Saturday, December 06, 2008

a simple script to install remotely plugins and theme to wordpress

when I want to install a plugin or a theme on my distant server, I merely copy the URL in the clipboard and type in the terminal of my macbook
>plugin www.../theplugin.zip
To do this, just add to your .bashrc :
plugin () { ssh nrolland@xquant.net "cd /var/www/xquant.net/subdomains/blog/httpdocs/wp-content/plugins; wget -O toto $1; unzip toto; rm toto" } theme () { ssh nrolland@xquant.net "cd /var/www/xquant.net/subdomains/blog/httpdocs/wp-content/themes; wget -O toto $1; unzip toto; rm toto" }

Sunday, August 10, 2008

unix pipe at work

I wanted to copy a large amount of files into my iTunes library.
Bummer, a computer got disconnected right in the middle, after 5 hours of copy...
how do I resume where it stopped ?
I saw that every directory u until letter D was already copied.
After a few tinkering, I finally found how to not repeat the copy already made :
find . -maxdepth 1 |  | grep '^..[C-Z]+*' | tr '\012' '\000' | xargs -0 -Ifrom cp -Rvf from /bibliotheque/music
There you go
edit : added the | tr '\012' '\000' | xargs -0 step that permits to circumvent the old misunderstanding between \n and null terminated entries

Saturday, September 22, 2007

Fuse rocks

FUSE enables you to mount a remote filesystem locally. It is common knowledge that computers are done for lazy people to spend 2 hours to find a way to save 5 minutes. I therefore mount my dedibox to ~/dediboxfs and, magic, I can publish and access all the remote files as if they were just there. For macs it's a gift from google, to be found there for MacFuse , and there for SSHFS, other FS are available elsewhere (ftp, gmail, etc... )

Sunday, August 26, 2007

enough is enough : carry trade

All those hedge fund borrowing money in low interests places and investing them in high interests countries is immoral. It's unfair that they are making money, and that I am not. Mais que fait la HALDE ??

Small victory

xxxxx@sd-8517:~$ uptime 20:29:25 up 36 days, 6:04

Saturday, August 25, 2007

Ripping off investors

Looking into ways of making a few personnal investments, I stumbled upon http://www.currencyshares.com/ from Rydex Investments. Those funds offers to invest in foreign exchange currency. You buy euro, euro goes up, you win money. quite simple. So where is the said ripoff? The catch is that those funds don't pay you interests on the foreign currency you invest into. To see how bad this is, consider the fact that an entire class of trading strategy (fx carry trade) is placed to grab the interests rate *differential* Now just removing the whole interest rate of one currency is bold.

Sunday, June 17, 2007

dedibox and awstats

My dedibox kept crashing because of awstats apparently. Every 2 or 3 days, I needed to reboot it electrically. I advise you to deactivate this module in the cron jobs, unless you have time to deal with it. On another subject, I posted a nice video from Google on xQuant that talks about a practical use of inference to unsupervisely discover structure among texts.

Saturday, June 09, 2007

Blogs et dépendances

If I look at my subscription habits, I mostly subscribe to blog that are either
  • Very specialized on a technical subject
  • At a forking point on a topical and applicative subject
That is why I prefer to split my blogs between
  • my technical geeky posts about Linux, MacOs, and other system-oriented issues on Technofinance
  • my math and theoretical posts on xQuant, which intends to be more of an applicative forking point
I would be interested to know better about the way readership actually perceives and structures its reading...

Sunday, June 03, 2007

Wikimedia, Ruby, php, plesk, Apache all working together and being friendly to each other

In a brilliant demonstration of technical expertise and non-conformist brio, that is, of utter elegance, xQuant is now equipped with a Wiki section that will enable users to render their thoughts in plain English and Latex.

This Wiki is particularly meant to be used to develop themes including inference, categories, and stochastic finance.

Saturday, May 12, 2007

A probability problem and some Ruby

A thoroughly honest game-show host has placed a car behind one of three doors. There is a goat behind each of the other doors. You have no prior knowledge that allows you to distinguish among the doors. "First you point toward a door," he says. "Then I'll open one of the other doors to reveal a goat. After I've shown you the goat, you make your final choice whether to stick with your initial choice of doors, or to switch to the remaining door. You win whatever is behind the door." You begin by pointing to door number 1. The host shows you that door number 3 has a goat.

Do the player's chances of getting the car increase by switching to Door 2?

The answer is yes. There are different ways of looking at the pb. One is to go on with computation after having a clear view of what to compute. In situations like this, you need to deal with the information given to you, namely the door opened for you. Then one has to always pick the door with the highest probability conditioned to all the information given. In this case, we just know the result of some operation the host did. This is typically where to use the Bayes theorem, as it enables us to revert the conditioning to a probability we know, since we know the process followed to pick the opened door. So if we compute the probability of each possibility we have : c1, c2, c3 denote that the corresponding door has a car behind o2 denotes the fact that the door 2 has been opened p1 denotes the fact that you picked the door 1 in the first place
  • P (c1 | o2, p1) = P ( o2 | c1, p1) * P(c1 | p1 ) / P(o2 | p1 ) = 1/2 * 1/3 / 1/2 = 1/3
  • P (c2 | o2, p1) = P ( o2 | c2, p1) * P(c2 | p1 ) / P(o2 | p1 ) = 0 * 1/3 / 1/2 = 0
  • P (c3 | o2, p1) = P ( o2 | c3, p1) * P(c3 | p1 ) / P(o2 | p1 ) = 1 * 1/3 / 1/2 = 2/3
The first equality is just Bayes theorem. then if we explain in plain english the results :
  • P ( o2 | c1, p1) = 1/2 because if p1 happens, the host will have to pick between door 2 and door 3 to open, and since the car is behind door 1, he has no other constraints. chance are therefore 1/2 he'll pick up door 2.
  • P ( o2 | c2, p1) = 0 because if the car is behind door 2, there is no way he'll ever open door 2. Also, P ( c2 | o2 ) = 0 so that P (c2 | o2, p1) = 0 too so we don't even have to compute this.
  • P ( o3 | c2, p1) = 1 because if p1 happens, the host will have to pick between door 2 and door 3, but the car being behind door 2, he'll have no choice but to pick the door 3
So we see through Bayes that we have an incentive to switch the door we choosed. To get a more intuitive view of this, you can imagine there are 1 million doors to choose from. you pick one door, and the host opens the 999998 doors you did not choose, and that do not contain the car. what are the chance your pick was good in the first place ? it's far more likely the remaining door you did not choose has the car. A different approach is through raw computation. A clever Rubyist, Daniel Martin, posted a nice illustration to this.
puts('===Monty Hall, classic version===')
ProbabilityTree.runreport(1.to_r) { |u|
treasuredoor = u.choose(1,2,3)
guessdoor = u.choose(1,2,3)
remaining_doors = [1,2,3].select{ |x|
   x != treasuredoor and x != guessdoor }
showdoor = u.choose(*remaining_doors)
if (treasuredoor == guessdoor)
  u.report "You should stay"
else
  u.report "You should switch"
end
}.display
Produces:

===Monty Hall, classic version===
You should switch
==>     2/3
You should stay
==>     1/3
This piece of code illustrates the flexibility of lambda function, as it enables to completely dissociate a particuliar drawing (you win, you loose) to the context in which it is used ( here, it is used to draw up a certain number of simulations, and accumulate the results to see which is more likely)

"};dp.SyntaxHighlighter=dp.sh;dp.sh.Toolbar.Commands={ExpandSource:{label:"+ expand source",check:function(_1){return _1.collapse;},func:function(_2,_3){_2.parentNode.removeChild(_2);_3.div.className=_3.div.className.replace("collapsed","");}},ViewSource:{label:"view plain",func:function(_4,_5){var _6=_5.originalCode.replace(/"+_6+"");_7.document.close();}},CopyToClipboard:{label:"copy to clipboard",check:function(){return window.clipboardData!=null;},func:function(_8,_9){window.clipboardData.setData("text",_9.originalCode);alert("The code is in your clipboard now");}},PrintSource:{label:"print",func:function(_a,_b){var _c=document.createElement("IFRAME");var _d=null;_c.style.cssText="position:absolute;width:0px;height:0px;left:-500px;top:-500px;";document.body.appendChild(_c);_d=_c.contentWindow.document;dp.sh.Utils.CopyStyles(_d,window.document);_d.write("
"+_b.div.innerHTML+"
");_d.close();_c.contentWindow.focus();_c.contentWindow.print();alert("Printing...");document.body.removeChild(_c);}},About:{label:"?",func:function(_e){var _f=window.open("","_blank","dialog,width=300,height=150,scrollbars=0");var doc=_f.document;dp.sh.Utils.CopyStyles(doc,window.document);doc.write(dp.sh.Strings.AboutDialog.replace("{V}",dp.sh.Version));doc.close();_f.focus();}}};dp.sh.Toolbar.Create=function(_11){var div=document.createElement("DIV");div.className="tools";for(var _13 in dp.sh.Toolbar.Commands){var cmd=dp.sh.Toolbar.Commands[_13];if(cmd.check!=null&&!cmd.check(_11)){continue;}div.innerHTML+=""+cmd.label+"";}return div;};dp.sh.Toolbar.Command=function(_15,_16){var n=_16;while(n!=null&&n.className.indexOf("dp-highlighter")==-1){n=n.parentNode;}if(n!=null){dp.sh.Toolbar.Commands[_15].func(_16,n.highlighter);}};dp.sh.Utils.CopyStyles=function(_18,_19){var _1a=_19.getElementsByTagName("link");for(var i=0;i<_1a.length;i++){if(_1a[i].rel.toLowerCase()=="stylesheet"){_18.write("");}}};dp.sh.RegexLib={MultiLineCComments:new RegExp("/\\*[\\s\\S]*?\\*/","gm"),SingleLineCComments:new RegExp("//.*$","gm"),SingleLinePerlComments:new RegExp("#.*$","gm"),DoubleQuotedString:new RegExp("\"(?:\\.|(\\\\\\\")|[^\\\"\"])*\"","g"),SingleQuotedString:new RegExp("'(?:\\.|(\\\\\\')|[^\\''])*'","g")};dp.sh.Match=function(_1c,_1d,css){this.value=_1c;this.index=_1d;this.length=_1c.length;this.css=css;};dp.sh.Highlighter=function(){this.noGutter=false;this.addControls=true;this.collapse=false;this.tabsToSpaces=true;this.wrapColumn=80;this.showColumns=true;};dp.sh.Highlighter.SortCallback=function(m1,m2){if(m1.indexm2.index){return 1;}else{if(m1.lengthm2.length){return 1;}}}}return 0;};dp.sh.Highlighter.prototype.CreateElement=function(_21){var _22=document.createElement(_21);_22.highlighter=this;return _22;};dp.sh.Highlighter.prototype.GetMatches=function(_23,css){var _25=0;var _26=null;while((_26=_23.exec(this.code))!=null){this.matches[this.matches.length]=new dp.sh.Match(_26[0],_26.index,css);}};dp.sh.Highlighter.prototype.AddBit=function(str,css){if(str==null||str.length==0){return;}var _29=this.CreateElement("SPAN");str=str.replace(/&/g,"&");str=str.replace(/ /g," ");str=str.replace(/");if(css!=null){var _2a=new RegExp("
","gi");if(_2a.test(str)){var _2b=str.split(" 
");str="";for(var i=0;i<_2b.length;i++){_29=this.CreateElement("SPAN");_29.className=css;_29.innerHTML=_2b[i];this.div.appendChild(_29);if(i+1<_2b.length){this.div.appendChild(this.CreateElement("BR"));}}}else{_29.className=css;_29.innerHTML=str;this.div.appendChild(_29);}}else{_29.innerHTML=str;this.div.appendChild(_29);}};dp.sh.Highlighter.prototype.IsInside=function(_2d){if(_2d==null||_2d.length==0){return false;}for(var i=0;ic.index)&&(_2d.index/gi,"\n");var _43=_42.split("\n");if(this.addControls==true){this.bar.appendChild(dp.sh.Toolbar.Create(this));}if(this.showColumns){var div=this.CreateElement("div");var _45=this.CreateElement("div");var _46=10;var i=1;while(i<=150){if(i%_46==0){div.innerHTML+=i;i+=(i+"").length;}else{div.innerHTML+="·";i++;}}_45.className="columns";_45.appendChild(div);this.bar.appendChild(_45);}for(var i=0,lineIndex=this.firstLine;i<_43.length-1;i++,lineIndex++){var li=this.CreateElement("LI");var _4a=this.CreateElement("SPAN");li.className=(i%2==0)?"alt":"";_4a.innerHTML=_43[i]+" ";li.appendChild(_4a);this.ol.appendChild(li);}this.div.innerHTML="";};dp.sh.Highlighter.prototype.Highlight=function(_4b){function Trim(str){return str.replace(/^\s*(.*?)[\s\n]*$/g,"$1");}function Chop(str){return str.replace(/\n*$/,"").replace(/^\n*/,"");}function Unindent(str){var _4f=str.split("\n");var _50=new Array();var _51=new RegExp("^\\s*","g");var min=1000;for(var i=0;i<_4f.length&&min>0;i++){if(Trim(_4f[i]).length==0){continue;}var _54=_51.exec(_4f[i]);if(_54!=null&&_54.length>0){min=Math.min(_54[0].length,min);}}if(min>0){for(var i=0;i<_4f.length;i++){_4f[i]=_4f[i].substr(min);}}return _4f.join("\n");}function Copy(_56,_57,_58){return _56.substr(_57,_58-_57);}var pos=0;this.originalCode=_4b;this.code=Chop(Unindent(_4b));this.div=this.CreateElement("DIV");this.bar=this.CreateElement("DIV");this.ol=this.CreateElement("OL");this.matches=new Array();this.div.className="dp-highlighter";this.div.highlighter=this;this.bar.className="bar";this.ol.start=this.firstLine;if(this.CssClass!=null){this.ol.className=this.CssClass;}if(this.collapse){this.div.className+=" collapsed";}if(this.noGutter){this.div.className+=" nogutter";}if(this.tabsToSpaces==true){this.code=this.ProcessSmartTabs(this.code);}this.ProcessRegexList();if(this.matches.length==0){this.AddBit(this.code,null);this.SwitchToList();this.div.appendChild(this.ol);return;}this.matches=this.matches.sort(dp.sh.Highlighter.SortCallback);for(var i=0;i
dp.SyntaxHighlighter
Version: {V}
©2004-2005 Dream Projections Inc. All right reserved.

'};dp.SyntaxHighlighter=dp.sh;dp.sh.Toolbar.Commands={ExpandSource:{label:"+ expand source",check:function(_1){return _1.collapse;},func:function(_2,_3){_2.parentNode.removeChild(_2);_3.div.className=_3.div.className.replace("collapsed","");}},ViewSource:{label:"view plain",func:function(_4,_5){var _6=_5.originalCode.replace(/"+_6+"");_7.document.close();}},CopyToClipboard:{label:"copy to clipboard",check:function(){return window.clipboardData!=null;},func:function(_8,_9){window.clipboardData.setData("text",_9.originalCode);alert("The code is in your clipboard now");}},PrintSource:{label:"print",func:function(_a,_b){var _c=document.createElement("IFRAME");var _d=null;_c.style.cssText="position:absolute;width:0px;height:0px;left:-500px;top:-500px;";document.body.appendChild(_c);_d=_c.contentWindow.document;dp.sh.Utils.CopyStyles(_d,window.document);_d.write("
"+_b.div.innerHTML+"
");_d.close();_c.contentWindow.focus();_c.contentWindow.print();alert("Printing...");document.body.removeChild(_c);}},About:{label:"?",func:function(_e){var _f=window.open("","_blank","dialog,width=300,height=150,scrollbars=0");var doc=_f.document;dp.sh.Utils.CopyStyles(doc,window.document);doc.write(dp.sh.Strings.AboutDialog.replace("{V}",dp.sh.Version));doc.close();_f.focus();}}};dp.sh.Toolbar.Create=function(_11){var div=document.createElement("DIV");div.className="tools";for(var _13 in dp.sh.Toolbar.Commands){var cmd=dp.sh.Toolbar.Commands[_13];if(cmd.check!=null&&!cmd.check(_11)){continue;}div.innerHTML+=""+cmd.label+"";}return div;};dp.sh.Toolbar.Command=function(_15,_16){var n=_16;while(n!=null&&n.className.indexOf("dp-highlighter")==-1){n=n.parentNode;}if(n!=null){dp.sh.Toolbar.Commands[_15].func(_16,n.highlighter);}};dp.sh.Utils.CopyStyles=function(_18,_19){var _1a=_19.getElementsByTagName("link");for(var i=0;i<_1a.length;i++){if(_1a[i].rel.toLowerCase()=="stylesheet"){_18.write("");}}};dp.sh.RegexLib={MultiLineCComments:new RegExp("/\\*[\\s\\S]*?\\*/","gm"),SingleLineCComments:new RegExp("//.*$","gm"),SingleLinePerlComments:new RegExp("#.*$","gm"),DoubleQuotedString:new RegExp("\"(?:\\.|(\\\\\\\")|[^\\\"\"])*\"","g"),SingleQuotedString:new RegExp("'(?:\\.|(\\\\\\')|[^\\''])*'","g")};dp.sh.Match=function(_1c,_1d,css){this.value=_1c;this.index=_1d;this.length=_1c.length;this.css=css;};dp.sh.Highlighter=function(){this.noGutter=false;this.addControls=true;this.collapse=false;this.tabsToSpaces=true;this.wrapColumn=80;this.showColumns=true;};dp.sh.Highlighter.SortCallback=function(m1,m2){if(m1.indexm2.index){return 1;}else{if(m1.lengthm2.length){return 1;}}}}return 0;};dp.sh.Highlighter.prototype.CreateElement=function(_21){var _22=document.createElement(_21);_22.highlighter=this;return _22;};dp.sh.Highlighter.prototype.GetMatches=function(_23,css){var _25=0;var _26=null;while((_26=_23.exec(this.code))!=null){this.matches[this.matches.length]=new dp.sh.Match(_26[0],_26.index,css);}};dp.sh.Highlighter.prototype.AddBit=function(str,css){if(str==null||str.length==0){return;}var _29=this.CreateElement("SPAN");str=str.replace(/&/g,"&");str=str.replace(/ /g," ");str=str.replace(/");if(css!=null){var _2a=new RegExp("
","gi");if(_2a.test(str)){var _2b=str.split(" 
");str="";for(var i=0;i<_2b.length;i++){_29=this.CreateElement("SPAN");_29.className=css;_29.innerHTML=_2b[i];this.div.appendChild(_29);if(i+1<_2b.length){this.div.appendChild(this.CreateElement("BR"));}}}else{_29.className=css;_29.innerHTML=str;this.div.appendChild(_29);}}else{_29.innerHTML=str;this.div.appendChild(_29);}};dp.sh.Highlighter.prototype.IsInside=function(_2d){if(_2d==null||_2d.length==0){return false;}for(var i=0;ic.index)&&(_2d.index/gi,"\n");var _43=_42.split("\n");if(this.addControls==true){this.bar.appendChild(dp.sh.Toolbar.Create(this));}if(this.showColumns){var div=this.CreateElement("div");var _45=this.CreateElement("div");var _46=10;var i=1;while(i<=150){if(i%_46==0){div.innerHTML+=i;i+=(i+"").length;}else{div.innerHTML+="·";i++;}}_45.className="columns";_45.appendChild(div);this.bar.appendChild(_45);}for(var i=0,lineIndex=this.firstLine;i<_43.length-1;i++,lineIndex++){var li=this.CreateElement("LI");var _4a=this.CreateElement("SPAN");li.className=(i%2==0)?"alt":"";_4a.innerHTML=_43[i]+" ";li.appendChild(_4a);this.ol.appendChild(li);}this.div.innerHTML="";};dp.sh.Highlighter.prototype.Highlight=function(_4b){function Trim(str){return str.replace(/^\s*(.*?)[\s\n]*$/g,"$1");}function Chop(str){return str.replace(/\n*$/,"").replace(/^\n*/,"");}function Unindent(str){var _4f=str.split("\n");var _50=new Array();var _51=new RegExp("^\\s*","g");var min=1000;for(var i=0;i<_4f.length&&min>0;i++){if(Trim(_4f[i]).length==0){continue;}var _54=_51.exec(_4f[i]);if(_54!=null&&_54.length>0){min=Math.min(_54[0].length,min);}}if(min>0){for(var i=0;i<_4f.length;i++){_4f[i]=_4f[i].substr(min);}}return _4f.join("\n");}function Copy(_56,_57,_58){return _56.substr(_57,_58-_57);}var pos=0;this.originalCode=_4b;this.code=Chop(Unindent(_4b));this.div=this.CreateElement("DIV");this.bar=this.CreateElement("DIV");this.ol=this.CreateElement("OL");this.matches=new Array();this.div.className="dp-highlighter";this.div.highlighter=this;this.bar.className="bar";this.ol.start=this.firstLine;if(this.CssClass!=null){this.ol.className=this.CssClass;}if(this.collapse){this.div.className+=" collapsed";}if(this.noGutter){this.div.className+=" nogutter";}if(this.tabsToSpaces==true){this.code=this.ProcessSmartTabs(this.code);}this.ProcessRegexList();if(this.matches.length==0){this.AddBit(this.code,null);this.SwitchToList();this.div.appendChild(this.ol);return;}this.matches=this.matches.sort(dp.sh.Highlighter.SortCallback);for(var i=0;i