Wednesday, April 20, 2011

La costituzione italiana

“L’Italia è una Repubblica democratica fondata sul lavoro. La sovranità appartiene al popolo, che la esercita nelle forme e nei limiti della Costituzione”.

Silvio, la Costituzione è stata fatta così per difenderci da persone come te.

Tuesday, February 15, 2011

How to prevent Hudson to kill processes

Normally hudson will kill all the processes that have been created during the build tasks, this will ensure that after the build the system will be left in a consistent state.

However, sometimes, you may need to keep those tasks running, for example we use Hudson to automatically perform nightly installations on our test servers, in those cases you want that hudson will not kill the processes that have been started during the installation (i.e. jboss, tomcat).

A web search got me this page:

http://www.suryasuravarapu.com/2010/07/spawning-a-process-from-hudson.html

The page explain how to setup the project to prevent hudson from killing started process, basically it says:

set the environment variable BUILD_ID to something like 'dontKillMe' in the
process that should stay alive.

Hudson looks for that environment variable when cleaning up stray processes.

However, if you are new to hudson, it does not say how to achieve that, well, you can use the setenv plugin, to install it you have to simply go to the “manage hudson” page where you will find the “manage plugins” shortcut, in the plugins page (in the “available” column) you can find the SetEnv plugin, just mark it and then click on “install” at the end of the page.

At the end of the plugin installation you can restart hudson and the Environment Variables field will appear when configuring the project.

 

Happy CI.

Monday, February 14, 2011

Hudson

Installing hudson is pretty easy, you can download the war from http://java.net/projects/hudson/downloads/directory/war, for example you can download it directly from the server:

wget http://java.net/projects/hudson/downloads/download/war%252Fhudson-1.395.war

Then you can create a script like this that will start it:

#!/bin/bash



 



dir=/home/polopoly/hudson<



 



nohup java -jar $dir/hudson.war --httpPort=18080 --ajp13Port=18009 >$dir/hudson.log 2>&1 &; 




 


this will start hudson on port 18080, the only remaining thing you have to configure is the email server that should be used to send email alert (if you want to send them which is highly recommended).


Now you are free to create your tasks.

Wednesday, February 09, 2011

CKEditor

I’ve just replaced the old FCKEditor with CKEditor, in this page you can find some really helpful hints to achieve better performance: http://ckeditor.com/blog/CKEditor_Loading_performance_details

As always, measure your performance to understand if the changes you have done are really worth it.

Sunday, January 03, 2010

How to use Nginx to load balance a website

Have a look at http://mickeyben.com/2009/12/30/using-nginx-as-a-load-balancer.html to see how to use Nginx as a load balancer.

upstream  yoursite  {
server yoursite1.yoursite.com;
server yoursite2.yoursite.com;
}

server {
server_name www.yoursite.com;
location / {
proxy_pass http://yoursite;
}
}








The configuration is really simple, additionally you can use the ip_hash directive to forward all the request of the same client to the same server:









upstream  yoursite  {
ip_hash;
server yoursite1.yoursite.com;
server yoursite2.yoursite.com;
}



Wednesday, December 23, 2009

Using different JQuery versions in the same page

Suppose your web page in the CMS is already using one version of jquery and you want to add a new HTML element with a javascript library that needs a more recent version of jquery.

You may think to use the google api like:

<script>
google.load("jquery", "1.3.2");
</script>



and then use the noConflict option like:




<script>
function OnLoad(){
jq13 = jQuery.noConflict(true);
}

google.load("jquery", "1.3.2");
google.setOnLoadCallback(OnLoad);
</script>



Unfortunately this will not work correctly in IE…so you may want to use the technique to dynamically load a javascript (see http://themnd.blogspot.com/2009/12/dynamically-load-javascript-on-webpage.html)






<script>
function OnLoad(){
jq13 = jQuery.noConflict(true);
}

function loadJQuery() {
loadJS('http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js', function() {
OnLoad();
});
}

jQuery(document).ready(function() {
setTimeout(function() {
loadJQuery();
}, 2000);
});
</script>



at this point you can load the needed library in the OnLoad function before setting the noConflict option. Please note that we are still using the google cdn to fetch the jquery library. The OnLoad function would be something like:




function OnLoad(){
loadJS(plugin_url, function() {
jq13 = jQuery.noConflict(true);
// now you can call the plugin methods here:
jq13.XXXX()
});
}

Dynamically load javascript on a webpage

When you work with a CMS sometimes you may need to dynamically add a javascript library on the fly.

The easiest thing to do is:

var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = url;
headID.appendChild(newScript);



But what if you want to be notified when the javascript has been loaded? You can add the onload parameter:




newScript.onload = function(){
func();
};



but you will find out that this will not work in IE, so what you really need to use is:




function loadJS(url, func) {
var headID = document.getElementsByTagName("head")[0];
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
if (newScript.readyState) { //IE
newScript.onreadystatechange = function() {
if (newScript.readyState == "loaded" || newScript.readyState == "complete") {
newScript.onreadystatechange = null;
func();
}
};
} else { //Others
newScript.onload = function(){
func();
};
}
newScript.src = url;
headID.appendChild(newScript);
}



We will rely on the onreadystatechange event that IE will fire, unfortunately that event is, in reality, the progress of the loading and sometimes it reach the “complete” state, sometimes only the “loaded” state, so if we really want to be sure that our callback will be called we have to get the first one and then cancel the event.



You can learn more at: http://www.nczonline.net/blog/2009/06/23/loading-javascript-without-blocking/



In a similar way you can also dynamically load CSS:




function loadCss(url) {
var headID = document.getElementsByTagName("head")[0];
var cssNode = document.createElement('link');
cssNode.type = 'text/css';
cssNode.rel = 'stylesheet';
cssNode.href = url;
cssNode.media = 'screen';
headID.appendChild(cssNode);
}

Saturday, October 03, 2009