Sunday, 15 September 2013

How to generate a labelled dendogram using agnes?

How to generate a labelled dendogram using agnes?

Using the code from :
http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering
Here is how to generate a dendogram :
# import data
x <- read.table("data.txt")
# run AGNES
ag <- agnes (x, false, metric="euclidean", false, method ="single")
# print components of ag
print(ag)
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)
I'm receiving an error on
ag <- agnes (x, false, metric="euclidean", false, method ="single")
The error is :
Error in agnes(x, false, metric = "euclidean", false, method = "single") :
object 'false' not found
This implementation of agnes works but its generating numbered labels for
the dendogram :
ag <- agnes (data, metric="euclidean")
# plot clusters
plot(ag, ask = FALSE, which.plots = NULL)
The dendogram :

The dendogram generated from
http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Clustering/Hierarchical_Clustering
includes labels :
Here is the data file :
,ba,fi,mi,vo,rm,to
ba,0,662,877,255,412,996
fi,662,0,295,468,268,400
mi,877,295,0,754,564,138
vo,255,468,754,0,219,869
rm,412,268,564,219,0,669
to,996,400,138,869,669,0
How can generate a labelled hierarchical cluster based on above data which
is same as labelled dendogram above ?

Parse error: syntax error, unexpected T_VARIABLE in bindValue

Parse error: syntax error, unexpected T_VARIABLE in bindValue

if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'])) {
$title = $_POST['title'];
$content = $_POST['content'];
if (empty($title) or empty($content)) {
$error = 'All fields are required!';
} else {
$query = $pdo->prepare("INSERT INTO articles (atricle_title,
atricle_text, atricle_timestamp) VALUES (?, ?, ?)")
$query->bindValue(1, $title); //error is here
$query->bindValue(2, $content);
$query->bindValue(3, time());
$query->execute();
header(Location: index.php);
}
Someone knows what's the problem here?. The code itself is more then that,
but this is to only relevent part.
Thanks.

Struggling with simple node.js code

Struggling with simple node.js code

I really can't figure out what I've done wrong. I've spent about half an
hour looking at this code and re-reading code that essentially does the
same thing and works. The 'data' event and corresponding callback is never
triggered.
var http = require("http");
http.createServer(function(request, response){
response.writeHead(200);
console.log('Executing');
request.on('data', function(chunk){
console.log('data being read');
console.log(chunk.toString());
});
request.on('end', function(){
console.log('done');
response.end();
});
}).listen(8080);
Please help

Parents Selector in CSS?

Parents Selector in CSS?

For example HTML :
<div id="css">
<a href="/forum"></a>
</div>
How can I choose the parent selector of a href ? I have tried :
#css! > a[href*="/forum"]
But not successful . Thanks for your helping

PHP: Sessions never expire

PHP: Sessions never expire

Last night I logged in and the following morning I was still logged in,
even if I quit my browser. I want the session to expire after a few hours
and I thought that it would work with "session.gc_maxlifetime" set to
"1440" and "session.cache_expire" set to "180"
Here is what I could find from PHP.ini
Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx
session.auto_start Off
session.bug_compat_42 Off
session.bug_compat_warn Off
session.cache_expire 180
session.cache_limiter nocache
session.cookie_domain no value
session.cookie_httponly Off
session.cookie_lifetime 0
session.cookie_path /
session.cookie_secure Off
session.entropy_file no value
session.entropy_length 0
session.gc_divisor 1000
session.gc_maxlifetime 1440
session.gc_probability 0
session.hash_bits_per_character 5
session.hash_function 0
session.name PHPSESSID
session.referer_check no value
session.save_handler files
session.save_path /var/lib/php5
session.serialize_handler php
session.use_cookies On
session.use_only_cookies On
session.use_trans_sid 0
On our old server we used the same settings and the sessions worked. The
only difference from the old one is the "session.save_handler" that is set
to "memcache" on the old server. Also "session.save_path" is different.

Saturday, 14 September 2013

Disable direct access to certain files (include)

Disable direct access to certain files (include)

I'm triyng to blobk access to certain files. I have on my server many
files like this
filename_sql.php
Basically i need to disallow user to access directly to sql.php files:
http://url.com/filename_sql.php <<<
I have created an htaccess with this code, but i can access files direcly
calling url. What do I wrong?
<Files ~ "\.sql(.php)?$">
Order allow,deny
Deny from all
</Files>
Thanks all.

Django Template - iterating through nested dictionary - too many examples

Django Template - iterating through nested dictionary - too many examples

I have a call to an external data source that successfully returns a
dictionary in this format. There can be any number of entries:
{
'0090000': {'status': 'some status', 'modified_date':
'2013-08-09T14:23:32Z', 'modified_by': 'John Doe', 'severity': '3
(Normal)', 'created_by': 'Dan Smith', 'summary': "some status",
'created_date': '2013-07-18T21:10:36Z'},
'0060000': {'status': 'some status', 'modified_date':
'2013-06-24T03:19:01Z', 'modified_by': 'Jay Johnson', 'severity': '4
(Low)', 'created_by': 'Tony Thompson', 'summary': "some other status",
'created_date': '2012-05-03T17:45:19Z'}...
}
I'm pulling this data end using some information gathered in a form. I've
read a ton of docs and examples of how to iterate through this and present
the data in a template but I can't quite make it work.
My view is as follows:
def agenda_detail(request, agenda_id):
#get the meeting data
a_data = get_object_or_404(meetingEvent, pk=agenda_id)
#get the DEE data for the VAT fieldset
account_id = a_data.account_number.pk
#get the stored session user/pass
username = request.session['username']
password = request.session['password']
dee_data = onsiteEngineer.objects.filter(account=account_id)
#now we get the case data from the Portal API
portal_raw = CustomerInformation()
customer_data = portal_raw.getOpenCaseInfo(account_id,username,password)
return render_to_response('agendas/detail.html',{'a_data':a_data,
'dee_data': dee_data, 'customer_data': customer_data.iteritems()},
context_instance=RequestContext(request))
My template code dealing with this is (I don't care about the html
formatting right now, i just want to see the data on the screen:
{% for key, value in customer_data.items %}
<p>{{ key }}</p>
{% for info in value %}
{{ value }}
{% endfor %}
{% endfor %}
It's showing no data. I've tried multiple combinations (using .items,
using iteritems, etc.) but I can't quite get it to work.
All advice appreciated.