<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Michael Bensoussan</title>
 <link href="http://mickeyben.com/atom.xml" rel="self"/>
 <link href="http://mickeyben.com/"/>
 <updated>2010-07-25T20:36:22-04:00</updated>
 <id>http://mickeyben.com/</id>
 <author>
   <name>Michael Bensoussan</name>
   <email>pada51@gmail.com</email>
 </author>

 
 <entry>
   <title>Register to an image loaded event with jQuery</title>
   <link href="http://mickeyben.com/2010/07/26/register-to-an-image-loaded-event-with-jquery.html"/>
   <updated>2010-07-26T00:00:00-04:00</updated>
   <id>http://mickeyben.com/2010/07/26/register-to-an-image-loaded-event-with-jquery</id>
   <content type="html">&lt;h1&gt;Register to an image loaded event with jQuery&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;26 July 2010&lt;/p&gt;
&lt;p&gt;I recently was working on a lightbox where I needed to display a remote image and recenter the lighbox once the image is loaded.&lt;br /&gt;
This may seems pretty simple but it took me some time to discover that jQuery does the job via the &lt;i&gt;load&lt;/i&gt; method. &lt;br /&gt;
As soon as the image has been loaded, the handler is called.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;#image_id&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// stuff to do after the image is loaded&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Creating an activity feed with rails, AR and observers</title>
   <link href="http://mickeyben.com/2010/05/23/creating-an-activity-feed-with-rails%2C-ar-and-observers.html"/>
   <updated>2010-05-23T00:00:00-04:00</updated>
   <id>http://mickeyben.com/2010/05/23/creating-an-activity-feed-with-rails,-ar-and-observers</id>
   <content type="html">&lt;h1&gt;Creating an activity feed with rails, AR and observers&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;23 May 2010&lt;/p&gt;
&lt;p&gt;I recently had to build an activity feed at &lt;a href=&quot;http://letitcast.com&quot;&gt;letitcast.com&lt;/a&gt;.&lt;br /&gt;
It’s a common thing to do, but I thought I might mention how I did it, and see if anyone else has suggestions/improvements.&lt;/p&gt;
&lt;p&gt;We wanted to display to our actors new parts that correspond to their profile, new feedbacks and views of their auditions , recent comments &amp;#8230;&lt;/p&gt;
&lt;p&gt;So, I first created a model &amp;#8220;activity&amp;#8221;, here&amp;#8217;s the migration :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CreateActivities&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Migration&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;up&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;create_table&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activities&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activity_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;integer&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;  &lt;span class=&quot;ss&quot;&gt;:target_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:null&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timestamps&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

       &lt;span class=&quot;n&quot;&gt;add_index&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:target_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target_type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;add_index&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user_id&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;down&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;drop_table&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activities&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As you can see it&amp;#8217;s a polymorphic model, so the activity can be related to any active record model.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the model :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Activity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;belongs_to&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:polymorphic&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;
  
    &lt;span class=&quot;n&quot;&gt;default_scope&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:order&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;activities.created_at DESC&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:limit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;
  
    &lt;span class=&quot;no&quot;&gt;AUDITION_POSTED&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#target --&amp;gt; model audition&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;AUDITION_FEEDBACK_UPDATED&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#target --&amp;gt; model audition&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;AUDITION_VIEWED&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#target --&amp;gt; model video&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;NEW_PART&lt;/span&gt;                  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#target --&amp;gt; model part&lt;/span&gt;
  
    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;activity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Activity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:user&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:activity_type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:target&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;activity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;save!&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
  
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;At the beginning the activity types were mapped in an other database but it was a bit overkill and was reducing the performance a lot so I just added them into the model (AUDITION_POSTED, AUDITION_FEEDBACK_UPDATED, &amp;#8230;)&lt;/p&gt;
&lt;p&gt;I decided to create the activities via observers, example :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;AuditionObserver&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Observer&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# ACTIVITY OBSERVER : new audition posted&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;after_create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;audition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;actor&lt;/span&gt;
        &lt;span class=&quot;no&quot;&gt;Activity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;audition&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;actor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Activity&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;AUDITION_POSTED&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;audition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;So now, I can add any event via a simple variable in the activity model and an observer.&lt;/p&gt;
&lt;p&gt;It was working really well but there were some performance issues with some events that required a lot of inserts in the activity model. &lt;br /&gt;
I first decided to execute this observer in a delayed job but after some research I ended up with a fast way to insert a batch of activities, here&amp;#8217;s the method :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt; &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;batch_add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;blank?&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;inserts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inserts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;(&amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;activity_type&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;#39;, &amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;#39;, UTC_TIMESTAMP())&amp;quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;INSERT INTO activities (`user_id`, `activity_type`, `target_id`, `target_type`, `created_at`) VALUES &lt;/span&gt;&lt;span class=&quot;si&quot;&gt;#{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inserts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;, &amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;no&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;execute&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sql&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;To retrieve the activities :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;  &lt;span class=&quot;vi&quot;&gt;@user&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;activities&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;By default you&amp;#8217;ll get 10 activities order by most recents. &lt;br /&gt;
If you want to change this behavior, just change the &lt;i&gt;default_scope&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;We&amp;#8217;re also in the process of grouping the user activities to display them in a nice view, so there will maybe be a part II :-)&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Optional local in partial that doesn't break</title>
   <link href="http://mickeyben.com/2010/05/22/optional-local-in-partial-that-doesn%27t-break.html"/>
   <updated>2010-05-22T00:00:00-04:00</updated>
   <id>http://mickeyben.com/2010/05/22/optional-local-in-partial-that-doesn't-break</id>
   <content type="html">&lt;h1&gt;Optional local in partial that doesn&amp;#8217;t break&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;22 May 2010&lt;/p&gt;
&lt;p&gt;If you have a partial called with or without local parameters, example :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:partial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user/new&amp;#39;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:partial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;user/new&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:locals&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:show_ad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;And you don’t want the partial to break when the local isn’t assigned, you can access it through the &lt;i&gt;local_assigns&lt;/i&gt; variable :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;local_assigns&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:show_ad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:partial&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;ad&amp;quot;&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>"can't find headers file for ruby" while installing gems</title>
   <link href="http://mickeyben.com/2010/01/02/can%27t-find-headers-file-for-ruby-while-installing-gems.html"/>
   <updated>2010-01-02T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2010/01/02/can't-find-headers-file-for-ruby-while-installing-gems</id>
   <content type="html">&lt;h1&gt;&amp;#8220;can&amp;#8217;t find headers file for ruby&amp;#8221; while installing gems&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;02 January 2010&lt;/p&gt;
&lt;p&gt;I just reinstall my old MacBook and had a problem I got each time I install a Mac &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo gem install RedCloth
Password:
Building native extensions.  This could take a &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt;...
ERROR:  Error installing RedCloth:
	ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
can&lt;span class=&quot;err&quot;&gt;&amp;#39;&lt;/span&gt;t find header files &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;ruby.


Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/RedCloth-4.2.2 &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/RedCloth-4.2.2/ext/redcloth_scan/gem_make.out
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;And the solution is really simple but I always forget it :&lt;/p&gt;
&lt;p&gt;Install Xcode &lt;a href=&quot;http://developer.apple.com/technology/xcode.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Mac OSX tricks 1 : cannot empty your trash ? use lsof</title>
   <link href="http://mickeyben.com/2010/01/01/mac-osx-tricks-part-i-%3A-cannot-empty-your-trash-%3F-use-lsof.html"/>
   <updated>2010-01-01T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2010/01/01/mac-osx-tricks-part-i-:-cannot-empty-your-trash-?-use-lsof</id>
   <content type="html">&lt;h1&gt;Mac &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt; tricks 1 : cannot empty your trash ? use lsof&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;01 January 2010&lt;/p&gt;
&lt;p&gt;So you want to empty you Trash but you have this below message saying that the file is already in use.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/Trash.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You click &lt;i&gt;continue&lt;/i&gt; but the file isn&amp;#8217;t deleted.&lt;/p&gt;
&lt;p&gt;In this case, the problem is that the file is a dmg and is mounted.&lt;br /&gt;
You just have to unmount the image to be able to delete it permanently.&lt;/p&gt;
&lt;p&gt;But in some cases you don&amp;#8217;t really know what&amp;#8217;s the process currently using your file(s).&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s come &lt;strong&gt;lsof&lt;/strong&gt; !&lt;br /&gt;
If you open the lsof man, you&amp;#8217;ll read : &lt;i&gt;lsof &amp;#8211; list open files&lt;/i&gt;&lt;br /&gt;
So if you just type lsof without any arguments, it lists all open files by all processes.&lt;/p&gt;
&lt;p&gt;lsof also take one or several files in argument so it can list all the processes using this file(s).&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;lsof .Trash/Spotify.dmg
COMMAND    PID USER   FD   TYPE DEVICE SIZE/OFF   NODE NAME
diskimage 1842 mike    3r   REG   14,2  3286498 928605 .Trash/Spotify.dmg
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Here you can identify &lt;b&gt;diskimage&lt;/b&gt; as the process using our file.&lt;br /&gt;
Now that you know the file is mounted, you can unmount it using the finder or the command line :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;diskutil unmount /Volumes/Spotify
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Or simply kill the process (in this case it will unmount it) by using the &lt;span class=&quot;caps&quot;&gt;PID&lt;/span&gt; nicely given by lsof :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;kill&lt;/span&gt; -9 1842
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You can now empty your Trash.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using Nginx as a load balancer</title>
   <link href="http://mickeyben.com/2009/12/30/using-nginx-as-a-load-balancer.html"/>
   <updated>2009-12-30T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2009/12/30/using-nginx-as-a-load-balancer</id>
   <content type="html">&lt;h1&gt;Using Nginx as a load balancer&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;30 December 2009&lt;/p&gt;
&lt;p&gt;Here’s a look at how nginx does basic load balancing :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server_name&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;www.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kn&quot;&gt;proxy_pass&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;http://yoursite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This configuration will send 50% of the requests for www.yoursite.com to yoursite1.yoursite.com and the other 50% to yoursite2.yoursite.com.&lt;/p&gt;
&lt;h2&gt;ip_hash&lt;/h2&gt;
&lt;p&gt;You can specify the &lt;i&gt;ip_hash&lt;/i&gt; directive that guarantees the client request will always be transferred to the same server.&lt;br /&gt;
If this server is considered inoperative, then the request of this client will be transferred to another server.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;ip_hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;h2&gt;down&lt;/h2&gt;
&lt;p&gt;If one of the servers must be removed for some time, you must mark that server as &lt;strong&gt;down&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;ip_hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;down&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;h2&gt;weight&lt;/h2&gt;
&lt;p&gt;If you add a &lt;strong&gt;weight&lt;/strong&gt; tag onto the end of the &lt;strong&gt;server&lt;/strong&gt; definition you can modify the percentages of the requests send to the servers.&lt;br /&gt;
When there&amp;#8217;s no weight set, the weight is equal to one.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;weight=4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This configuration will send 80% of the requests to yoursite1.yoursite.com and the other 20% to yoursite2.yoursite.com.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;note:&lt;/strong&gt; It&amp;#8217;s not possible to combine ip_hash and weight directives.&lt;/p&gt;
&lt;h2&gt;max_fails and fail_timeout&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;max_fails&lt;/strong&gt; is a directive defining the number of unsuccessful attempts in the time period defined by &lt;strong&gt;fail_timeout&lt;/strong&gt; before the server is considered inoperative. If not set, the number of attempts is one. A value of 0 turns off this check.&lt;br /&gt;
If &lt;strong&gt;fail_timeout&lt;/strong&gt; is not set the time is 10 seconds.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;max_fails=3&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;fail_timeout=30s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;In this configuration nginx will consider yoursite2.yoursite.com as inoperative if a request fails 3 times with a 30s timeout.&lt;/p&gt;
&lt;h2&gt;backup&lt;/h2&gt;
&lt;p&gt;If the non-backup servers are all down or busy, the server(s) with the &lt;strong&gt;backup&lt;/strong&gt; directive will be used.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;upstream&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;yoursite&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite1.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;max_fails=3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite2.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;max_fails=3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;kn&quot;&gt;server&lt;/span&gt;   &lt;span class=&quot;s&quot;&gt;yoursite3.yoursite.com&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;backup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This configuration will send 50% of the requests for www.yoursite.com to yoursite1.yoursite.com and the other 50% to yoursite2.yoursite.com.&lt;br /&gt;
If yoursite1.yoursite.com and yoursite2.yoursite.com both fails 3 times the requests will be send to yoursite3.yoursite.com.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Installing Jekyll and Pygments on ArchLinux</title>
   <link href="http://mickeyben.com/2009/12/23/installing-jekyll-and-pygments-on-archlinux.html"/>
   <updated>2009-12-23T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2009/12/23/installing-jekyll-and-pygments-on-archlinux</id>
   <content type="html">&lt;h1&gt;Installing Jekyll and Pygments on ArchLinux&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;23 December 2009&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt; is a simple, blog aware, static site generator. I use it for this blog and the cool part about it is that is very simple and easy to use and there&amp;#8217;s already plenty of &lt;a href=&quot;http://wiki.github.com/mojombo/jekyll/sites&quot;&gt;websites&lt;/a&gt; using it. &lt;br /&gt;
I forked &lt;a href=&quot;http://github.com/jtoy/jtoyblog/&quot;&gt;jtoy.net&lt;/a&gt; and was ready to blog in about an hour.&lt;/p&gt;
&lt;p&gt;I didn&amp;#8217;t use ruby1.9 but 1.8.7 because of some &lt;a href=&quot;http://github.com/mojombo/jekyll/issues/#issue/108&quot;&gt;issues&lt;/a&gt; with pygments.&lt;/p&gt;
&lt;p&gt;First if you don&amp;#8217;t have ruby, let&amp;#8217;s install it. &lt;br /&gt;
Remove the &amp;#8220;ruby&amp;#8221; package, so that it doesn&amp;#8217;t mess up, and retrieve and build the packages with any way you&amp;#8217;re comfortable with,&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pacman -R ruby
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;yaourt -S ruby1.8
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;yaourt -S rubygems1.8

&lt;span class=&quot;c&quot;&gt;# ruby1.8 installs ruby-1.8 executable. link it to &amp;quot;ruby&amp;quot;:&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; /usr/bin
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ln ruby-1.8 ruby -s
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;If you need syntax highlighting, you need python and pygments :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pacman -S python
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;download the last version of easy_install (ruby gems equivalent for python) and install pygments :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo sh setuptools-0.6c11-py2.6.eg
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;easy_install Pygments
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Install Jekyll :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo gem install jekyll
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Next, if you want the &amp;#8220;Related posts&amp;#8221; feature, you&amp;#8217;ll need the the Ruby &lt;span class=&quot;caps&quot;&gt;GSL&lt;/span&gt; package.&lt;br /&gt;
I first tried to install it via yaourt but it didn&amp;#8217;t work (conflicts with rubygems), next I try do download the last version (1.10.3) but it didn&amp;#8217;t work as well &amp;#8230; So I took the last version from the &lt;span class=&quot;caps&quot;&gt;SVN&lt;/span&gt; :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;svn checkout svn://rubyforge.org/var/svn/rb-gsl
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;rb-gsl/trunk/rb-gsl
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby setup.rb config
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;ruby setup.rb setup
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo ruby setup.rb install
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Finally, this is how I run Jekyll:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;jekyll --pygments --lsi 
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;To preview the website you can specify the option &lt;i&gt;&amp;#8212;server&lt;/i&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Monitoring Apache with Bluepill</title>
   <link href="http://mickeyben.com/2009/12/22/monitoring-apache-with-bluepill.html"/>
   <updated>2009-12-22T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2009/12/22/monitoring-apache-with-bluepill</id>
   <content type="html">&lt;h1&gt;Monitoring Apache with Bluepill&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;22 December 2009&lt;/p&gt;
&lt;p&gt;I always used &lt;a href=&quot;http://god.rubyforge.org/&quot;&gt;god&lt;/a&gt; to monitor my processes. god is working fine, has a lot of features and is very easy to use, but has some serious &lt;a href=&quot;http://groups.google.com/group/god-rb/browse_thread/thread/1cca2b7c4a581c2/69f69f602add7636?lnk=gst&amp;amp;q=memory+leak#69f69f602add7636&quot;&gt;memory&lt;/a&gt; leaks. To handle this problem I usually set-up a cron to restart god every day.&lt;/p&gt;
&lt;p&gt;Recently I read an &lt;a href=&quot;http://asemanfar.com/Why-We-Wrote-Bluepill&quot;&gt;article&lt;/a&gt; about a new process monitoring tool called &lt;a href=&quot;http://github.com/arya/bluepill&quot;&gt;bluepill&lt;/a&gt; based on EventMachine. The &lt;span class=&quot;caps&quot;&gt;DSL&lt;/span&gt; looks simple and comes memory-leaks-less.&lt;/p&gt;
&lt;p&gt;In this article I&amp;#8217;ll cover how to install it and monitor apache.&lt;/p&gt;
&lt;p&gt;First let&amp;#8217;s grab it :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo gem install bluepill
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;Next, we need to configure the syslogger to log the local6 facility used by bluepill.&lt;/p&gt;
&lt;p&gt;If your syslogger is syslog, add a line to &lt;i&gt;/etc/syslog.conf&lt;/i&gt; :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;local6.*          /var/log/bluepill.log
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;If it&amp;#8217;s syslog-ng, add ths to &lt;i&gt;/etc/syslog-ng.conf&lt;/i&gt; :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;filter f_local6 &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; facility&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;local6&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;;
destination d_local6 &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; file&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/log/bluepill.log&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;;

log &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;src&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;; filter&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;f_local6&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;; destination&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;d_local6&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;; &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You&amp;#8217;ll also want to add &lt;i&gt;/var/log/bluepill.log&lt;/i&gt; to &lt;i&gt;/etc/logrotate.d/syslog&lt;/i&gt; so that it gets rotated.&lt;/p&gt;
&lt;p&gt;Next restart your syslogger, for syslog-ng :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo /etc/rc.d/syslog-ng restart
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;And finally create the &lt;i&gt;/var/bluepill&lt;/i&gt; directory for bluepill to store its pid and sock files.&lt;/p&gt;
&lt;p&gt;Finally let&amp;#8217;s create our bluepill script to monitor apache in &lt;i&gt;apache-monitor.pill&lt;/i&gt; :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;Bluepill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;httpd&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;httpd&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pid_file&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;/var/run/httpd/httpd.pid&amp;quot;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start_command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;apachectl start&amp;quot;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop_command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;apachectl stop&amp;quot;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;restart_command&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;apachectl restart&amp;quot;&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start_grace_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop_grace_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;restart_grace_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;This simple script just checks if apache is up and if not reboot it.&lt;br /&gt;
You can try it by :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo bluepill load apache-monitor.pill
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;You can try to kill your httpd processes and you&amp;#8217;ll see the magic happens, bluepill will restart them.&lt;/p&gt;
&lt;p&gt;Bluepill comes with some great features to monitor your memory and cpu, so you can add to your script :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:cpu_usage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:every&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:below&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:times&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;checks&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:mem_usage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:every&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:below&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;megabytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:times&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;p&gt;The first line checks every 10 seconds to make sure the cpu usage of this process is below 5 percent; 3 failed checks results in a restart. &lt;br /&gt;
The second line checks every 10 seconds to make sure memory usage is below 100MB; 3 out of 5 failed attempts results in a restart.&lt;/p&gt;
&lt;p&gt;If you want your bluepill daemon to run at boot, just add a line to &lt;i&gt;/etc/rc.local&lt;/i&gt; :&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;sudo bluepill load /full/path/to/your/script/apache-monitor.pill
&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Introduction</title>
   <link href="http://mickeyben.com/2009/12/22/introduction.html"/>
   <updated>2009-12-22T00:00:00-05:00</updated>
   <id>http://mickeyben.com/2009/12/22/introduction</id>
   <content type="html">&lt;h1&gt;Introduction&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;22 December 2009&lt;/p&gt;
&lt;p&gt;I always wanted to create a technical blog, but never took the time to do it. &lt;br /&gt;
Recently, I wanted to play with &lt;a href=&quot;http://wiki.github.com/mojombo/jekyll&quot;&gt;Jekyll&lt;/a&gt;, a simple static site generator and just bought a &lt;span class=&quot;caps&quot;&gt;VPS&lt;/span&gt; instance on &lt;a href=&quot;http://linode.com&quot;&gt;linode&lt;/a&gt;. So I made the jump and create this blog from a github &lt;a href=&quot;http://github.com/jtoy/jtoyblog&quot;&gt;fork&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m mainly doing some ruby stuff but buying this server was a way to hack a bit with archlinux and learn some basic sysadmin. I hope some of you will find something interesting here, otherwise you can just make fun of my English.&lt;/p&gt;</content>
 </entry>
 
 
</feed>
