<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-3601561-4");
pageTracker._trackPageview();
} catch(err) {}
      hljs.initHighlightingOnLoad();
      hljs.addLineNumbers();
</description><title>My Web Log Book</title><generator>Tumblr (3.0; @vombat)</generator><link>http://vombat.tumblr.com/</link><item><title>Should we use the contentStretch property or a stretchable UIImage?</title><description>&lt;p&gt;This journey began when I started reading up on the View Controller Programming Guide for iOS on Apple&amp;#8217;s developer portal. This is what the guide recommended for creating stretchable views. Fun exercise.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_m04likufno1qa10vq.png"/&gt;&lt;img src="http://media.tumblr.com/tumblr_m04liodhvg1qa10vq.png"/&gt;&lt;img src="http://media.tumblr.com/tumblr_m04lirLLbG1qa10vq.png"/&gt;&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/18459567791</link><guid>http://vombat.tumblr.com/post/18459567791</guid><pubDate>Tue, 28 Feb 2012 15:10:53 -0800</pubDate></item><item><title>Building Dart on Snow Leopard</title><description>&lt;p&gt;I was stuck at the unsupported GCC error in building Dart on my Snow Leopard. The fix was simple - to remove the explicit version requirement, and let it use the system default. Hope it doesn&amp;#8217;t break anything.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Unsupported compiler 'GCC 4.2' selected for architecture 'x86_64'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Basically we have to clear out all references to GCC 4.2 from&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br/&gt;
GCC_VERSION = 4.2;&lt;br/&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br/&gt;
GCC_VERSION = ""&lt;br/&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since this version has been references in a thousand places, a global search and replace was needed. I am inside the dart/ directory.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ find . -name "*.pbxproj" -print -exec sed -i 's/GCC_VERSION = 4.2/GCC_VERSION = ""/g' {} \;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And ** BUILD SUCCEEDED **&lt;/p&gt;

&lt;p&gt;Cool!&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/11310752247</link><guid>http://vombat.tumblr.com/post/11310752247</guid><pubDate>Tue, 11 Oct 2011 00:52:00 -0700</pubDate></item><item><title>Responding with non-empty JSON when updating a resource via PUT in Rails 3</title><description>&lt;p&gt;Rails 3 responds with an empty object when making PUT requests to update a resource. This could be undesirable for some cases, and certainly is in our case where expect the JSON representation of the modified object as the response.&lt;/p&gt;

&lt;p&gt;The quick-fix is easy - we override the default behavior of &lt;code&gt;respond_with&lt;/code&gt; using a block that returns forces the response to be the complete JSON object.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;respond_with(@program) do |format|
  format.json {
    if @program.valid?
      render json: @program
    else
      render json: @program.errors, status: :unprocessable_entity
    end
  }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A neater fix, at least for me, would be in Rails itself inside the &lt;a href="https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/responder.rb#L205"&gt;Responder&lt;/a&gt; class. GET and POST requests already work as expected. For other requests Rails returns an empty response. This is how things look right now

&lt;/p&gt;&lt;pre&gt;&lt;code class="ruby"&gt;# This is the common behavior for formats associated with APIs, such as :xml and :json.
def api_behavior(error)
  raise error unless resourceful?

  if get?
    display resource
  elsif post?
    display resource, :status =&amp;gt; :created, :location =&amp;gt; api_location
  elsif has_empty_resource_definition?
    display empty_resource, :status =&amp;gt; :ok
  else
    head :ok
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Instead of responding with an empty resource for non GET/POST requests, we could have returned the resource itself for PUT requests as well. Here&amp;#8217;s how my ideal solution would look like (notice the &lt;code&gt;elsif put?&lt;/code&gt; line):&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;# This is the common behavior for formats associated with APIs, such as :xml and :json.
def api_behavior(error)
  raise error unless resourceful?

  if get?
    display resource
  elsif post?
    display resource, :status =&amp;gt; :created, :location =&amp;gt; api_location
  elsif put?
    display resource, :status =&amp;gt; :ok
  elsif has_empty_resource_definition?
    display empty_resource, :status =&amp;gt; :ok
  else
    head :ok
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now what can I do to get this merged in Rails?&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/8191942021</link><guid>http://vombat.tumblr.com/post/8191942021</guid><pubDate>Thu, 28 Jul 2011 17:01:00 -0700</pubDate><category>rails</category><category>responders</category><category>json</category><category>PUT</category><category>update</category></item><item><title>Linker errors with iOS 5 and libz</title><description>&lt;p&gt;So this has happened a few times across different projects where my iOS app failed to compile. The first one was particularly sad because when building a static framework that I include in my work app, because of &lt;code&gt;libz&lt;/code&gt;. We were referencing &lt;code&gt;libz.1.2.3&lt;/code&gt; which is apparently not included in iOS 5 SDK. I think it only contains version &lt;code&gt;1.2.5&lt;/code&gt; now. The worst part was that &lt;code&gt;libtool&lt;/code&gt; was failing, and it gave absolutely no clue as to why. The error simply said,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;libtool failed with error code 1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Bravo. After head-banging for a couple hours and trying random stuff, I removed libz and suddenly the project compiled.&lt;/p&gt;

&lt;p&gt;In another project, XCode for more helpful and guided me to the error rightaway by uttering some useful errors,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ld: library not found for -lz.1.2.3&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lesson learnt. Now I&amp;#8217;m just referencing &lt;code&gt;libz.dylib&lt;/code&gt; in the project as it is a symbolic link to the actual library and hopefully will always be there when needed.&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/8159906611</link><guid>http://vombat.tumblr.com/post/8159906611</guid><pubDate>Wed, 27 Jul 2011 21:46:51 -0700</pubDate><category>ios5</category><category>xcode</category></item><item><title>How do you dynamically set AJAX request data with Rails 3.1, jQuery, CoffeeScript, and all that jazz?</title><description>&lt;p&gt;Rails 3.1 is awesome. CoffeeScript is great. The jQuery addition is brilliant. But recently I came across a simple problem that took quite a while to figure out and with all these additions being fairly new, there was not much online help available, so I had to turn to the source code.&lt;/p&gt;

&lt;p&gt;So what was the problem? How do we dynamically modify the AJAX request data with rails using a &lt;code&gt;link_to&lt;/code&gt;. If I was using pure jQuery the solution would be as simple as,&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;$.ajax('/some/path', {
    type: 'POST',
    data: { foo: 'bar' },
    success: function() { .. },
    error: function() { .. }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But since I was trying to keep it Railsy and use &lt;code&gt;link_to&lt;/code&gt; to create a POST request, there were a few hurdles. Initially, I was trying to use the &lt;code&gt;ajax:beforeSend&lt;/code&gt; event callback which was useless for this task, as all form data gets set before this callback is made by Rails. The only use of this callback would be to abort the ajax request altogether if you suddenly discovered something. So I had to use the &lt;code&gt;ajax:before&lt;/code&gt; event. But inside the &lt;code&gt;ajax:before&lt;/code&gt; callback, we are only passed an event object totally unrelated to ajax, so to set custom ajax data, I had to checkout how &lt;em&gt;any&lt;/em&gt; data gets passed to &lt;code&gt;jQuery.ajax&lt;/code&gt; by Rails in the first place. Here&amp;#8217;s the relevant snippet from Rails UJS. Stripped out the form handling part as we&amp;#8217;re dealing with a link here.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;if (rails.fire(element, 'ajax:before')) {
    if (element.is('form')) {
        ...
    } else {
        method = element.data('method');
        url = element.attr('href');
        data = element.data('params') || null;
    }
    ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So Rails looks for custom data inside the &lt;code&gt;params&lt;/code&gt; data object of the element triggering the ajax request which is where I had to implant it. The CoffeeScript code for intercepting the ajax request and injecting the data dynamically looked like,&lt;/p&gt;

&lt;pre&gt;&lt;code class="coffeescript"&gt;$ -&amp;gt;
    $('#my_link').bind('ajax:before', -&amp;gt;
        $(this).data('params', { foo: 'bar' })
    )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Or if you don&amp;#8217;t like CoffeeScript for some reason, here&amp;#8217;s the equivalent in JavaScript.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;$(function() {
    $('#my_link').bind('ajax:before', function() {
        $(this).data('params', { foo: 'bar' });
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The corresponding link in rails erb was,&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;&amp;lt;%= link_to 'Foo', foo_path, method: :post, remote: true, id: 'my_link' %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This new syntax of creating hashes in Ruby 1.9 is cool and almost similar to JavaScript&amp;#8217;s object literals.&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/6874151754</link><guid>http://vombat.tumblr.com/post/6874151754</guid><pubDate>Fri, 24 Jun 2011 12:17:00 -0700</pubDate></item><item><title>Ruby version of Facebook's get_facebook_cookie in PHP</title><description>&lt;p&gt;Facebook provides an example of &lt;a href="http://developers.facebook.com/docs/guides/web#login"&gt;Single Sign-on&lt;/a&gt; that includes a method of verifying the authenticity of facebook&amp;#8217;s cookie that is set by their JavaScript SDK. The method is defined as:&lt;/p&gt;

&lt;pre&gt;&lt;code class="php"&gt;&amp;lt;?php
  define('FACEBOOK_APP_ID', 'your application id');
  define('FACEBOOK_SECRET', 'your application secret');
  
  function get_facebook_cookie($app_id, $application_secret)
  {
      $args = array();
      parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
      ksort($args);
      $payload = '';
      foreach ($args as $key =&amp;gt; $value) {
          if ($key != 'sig') {
              $payload .= $key . '=' . $value;
          }
      }
      if (md5($payload . $application_secret) != $args['sig']) {
          return null;
      }
      return $args;
  }
  
  $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Here&amp;#8217;s one for Ruby.&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;require 'cgi'
require 'digest/md5'

def get_facebook_params(app_id, app_secret, cookie)
  # unquote cookie value
  cookie.gsub!(/^"|"$/, '')
  
  # construct key, value pairs
  params = CGI.parse(cookie)
  
  # params contains keys and values of the form
  # {"session_key" =&amp;gt; ["..abcdef.."], "uid" =&amp;gt; ["123456789"]}
  # we need to unwrap each value out of the array into something like this
  # {"session_key" =&amp;gt; "..abcdef..", "uid" =&amp;gt; "123456789"}
  params = Hash[*params.sort.flatten]

  # take sig out
  sig = params.delete("sig")
  
  payload = ''
  params.sort.each do |pair|
    key, value = pair
    payload = payload + "#{key}=#{value}"
  end
  
  return nil if sig != Digest::MD5.hexdigest(payload + app_secret)
  
  return params
end
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/835536630</link><guid>http://vombat.tumblr.com/post/835536630</guid><pubDate>Tue, 20 Jul 2010 00:58:39 -0700</pubDate><category>facebook</category><category>javascript sdk</category><category>get_facebook_cookie</category><category>ruby</category></item><item><title>Enumerating Arrays and Objects in JavaScript</title><description>&lt;p&gt;
JavaScript arrays are an ordered collection of values, and objects are an unordered collection of key, value pairs. The members of both types can be enumerated and a variety of looping mechanisms can be used for doing that, however, these mechanisms are not interchangeable. 
&lt;/p&gt;

&lt;p&gt;When we are dealing with objects, the order of enumeration is not guaranteed. With arrays it is. That&amp;#8217;s all there is to know about enumerating collections. Four of the ways to do so are listed below.&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;for in&lt;/li&gt;
  &lt;li&gt;for each in&lt;/li&gt;
  &lt;li&gt;for&lt;/li&gt;
  &lt;li&gt;forEach&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;&lt;code&gt;for in&lt;/code&gt; and &lt;code&gt;for each in&lt;/code&gt; are perfect for enumerating properties, and values of an object respectively when order does not matter. To give an example, consider this object:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var phone = {
    screen: "320x480",
    wifi: true,
    price: 99
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
&lt;code&gt;for in&lt;/code&gt; can be used to enumerate all the properties and once we know the property name, the corresponding value can be accessed as phone[property].
&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;for(var prop in phone) {
    console.log(prop); // "screen", "wifi", and "price"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
The corresponding values can be accessed by using the bracket notation and passing the property name to the object.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;for(var prop in phone) {
    console.log(phone[prop]); // "320x480", true, 99
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With the addition of &lt;code&gt;for each in&lt;/code&gt; to JavaScript, which is only supported by Firefox at the moment, the above loop can be rewritten as:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;for each(var value in phone) {
    console.log(value); // "320x480", true, 99
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;for each in&lt;/code&gt; statement works beautifully when used with E4X, but that is for a later post. You wouldn&amp;#8217;t use either of the above statements for arrays because firstly order is not guaranteed, and secondly these are used to list all enumerable properties of an object which may not be desirable for Arrays as several frameworks add properties to the Array prototype which will also get enumerated. Consider this example:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var arr = ["a", "b"];

Array.prototype.justHangingOut = true;

for(var prop in arr) {
    console.log(prop); // "0", "1", "justHangingOut"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now &lt;code&gt;justHangingOut&lt;/code&gt; may just be hanging out with the Array prototype coming from some framework or library, and not necessarily be a part of your code, but it will show up when you try to enumerate an array in the above manner. Just to prove that I am not hallunicating about frameworks extending the Array prototype, here is the list of all methods added to Array.prototype when I run a small piece of code in Chrome&amp;#8217;s console for tumblr.com. The following few properties are listed:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;0
1
justHangingOut
each
eachSlice
all
every
any
some
collect
map
detect
findAll
select
filter
grep
include
member
inGroupsOf
inject
invoke
max
min
partition
pluck
reject
sortBy
toArray
entries
zip
size
inspect
find
_reverse
_each
clear
first
last
compact
flatten
without
reverse
uniq
intersect
clone
toJSON
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Hopefully the above example is sufficient to convince you that it&amp;#8217;s a bad idea to try to enumerate an array using a &lt;code&gt;for in&lt;/code&gt; or &lt;code&gt;for each in&lt;/code&gt; statement. There is a way using the &lt;code&gt;hasOwnProperty&lt;/code&gt; method that is available for all objects to find out if a given property belongs to that object or is coming from its prototype chain, but let&amp;#8217;s not get into that for now.&lt;/p&gt;

&lt;p&gt;So, moving on to enumerating arrays, a native and a somewhat faster way is to use a plain ol&amp;#8217; for loop. Here&amp;#8217;s an example:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var foo = [2, 3, 5, 7, 11];

for(var i = 0; i &amp;lt; foo.length; i++) {
    console.log(foo[i]); // 2, 3, 5, 7, 11
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This may be a little more performant than function-based looping, but I really dislike the use of so many indexes. All that is needed is going over each value and logging it, and all those i&amp;#8217;s are just noise. So, I prefer the &lt;code&gt;forEach&lt;/code&gt; method of an array that&amp;#8217;s part of ECMAScript 5th ed. It helps keep the noise levels low.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;var foo = [2, 3, 5, 7, 11];

foo.forEach(function(v) {
    console.log(v); // 2, 3, 5, 7, 11
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If your browser does not have native support for &lt;code&gt;forEach&lt;/code&gt;, it&amp;#8217;s easy to plug it in yourself. The following code from &lt;a href="https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/Array/ForEach"&gt;MDC&lt;/a&gt; defines the forEach method for enumerating array values if it&amp;#8217;s not already present.
&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;if (!Array.prototype.forEach)
{
    Array.prototype.forEach = function(fun /*, thisp*/)
    {
        var len = this.length &amp;gt;&amp;gt;&amp;gt; 0;
        if (typeof fun != "function")
            throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i &amp;lt; len; i++)
        {
            if (i in this)
                fun.call(thisp, this[i], i, this);
        }
    };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;On an unrelated note, although the above example of extending a native object (Array) with user defined functions may be seen as polluting the native object and even outrageous by some, I see nothing wrong with it. In fact, I am all in favor of it when such methods are put in the right place. The &lt;code&gt;forEach&lt;/code&gt; method that&amp;#8217;s now part of ECMAScript 5 was adapted from the Prototype framework, and it&amp;#8217;s very much possible that if Prototype hadn&amp;#8217;t &amp;#8220;polluted the native Array object&amp;#8221;, then the spec would have been a little different today.&lt;/p&gt;

&lt;p&gt;
I think if we extend the native types judiciously, it makes code a lot more readable and fun. A great example that comes to mind is the extension to Numeric types in Rails with some neat methods that allow code like:
&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;5.days + 2.days&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
No, I&amp;#8217;m not making this up. That is valid code in Rails thanks to &lt;a href="http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Numeric/Time.html"&gt;ActiveSupport&lt;/a&gt; extensions. Of course, we can always write methods that do exactly the same, but then we face the problem of either making too many things global:
&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;days(2) + days(5)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or namespacing them and making code uglier than it should&amp;#8217;ve been.&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;Time.Range.days(2) + Time.Range.days(5)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
Note that the first form &lt;code&gt;3.days&lt;/code&gt; uses a loose form of namespacing as it&amp;#8217;s only added for Numeric types and not available globally as in the second example &lt;code&gt;days(3)&lt;/code&gt;. The third example &lt;code&gt;Time.Range.days(3)&lt;/code&gt;, on the other hand, uses a seemingly well-defined namespace. I would prefer using the first form because it reads like prose, and at the same time doesn&amp;#8217;t throw everything into the global namespace.
&lt;/p&gt;

&lt;p&gt;
That said, its largely a matter of developer preference, and factors like type of project, scale of project, number of developers, etc. should also weigh in when deciding whether extension of native-types aka monkey-patching is acceptable for the project. It can be a huge asset of liability in building up your codebase depending on how it&amp;#8217;s done.
&lt;/p&gt;

Think I&amp;#8217;ve segway&amp;#8217;d enough for one post. Time to sleep.</description><link>http://vombat.tumblr.com/post/686555405</link><guid>http://vombat.tumblr.com/post/686555405</guid><pubDate>Fri, 11 Jun 2010 02:39:00 -0700</pubDate></item><item><title>authlogic_facebook_connect with a custom callback URL</title><description>&lt;p&gt;If you&amp;#8217;re using authlogic_facebook_connect to have facebook integration in your site and don&amp;#8217;t want to use the standard callback url of http://&lt;domain&gt;/user_session, then pass a controller option to the authlogic_facebook_login_button function and pass the controller name. Actually you don&amp;#8217;t need a controller name, just the path from the root url would do.&lt;/domain&gt;&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s the code I am using, that&amp;#8217;s facebook redirects to /authenticate using HTTP Post.&lt;/p&gt;

&lt;p&gt;&lt;code class="ruby"&gt;&amp;lt;%= authlogic_facebook_login_button :length =&amp;gt; "long", :controller =&amp;gt; 'authenticate' %&amp;gt;&lt;/code&gt;&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/517712254</link><guid>http://vombat.tumblr.com/post/517712254</guid><pubDate>Mon, 12 Apr 2010 23:57:00 -0700</pubDate><category>authlogic</category><category>authlogic_facebook_connect</category></item><item><title>The unnoticed Course Evaluation SCAM</title><description>&lt;p&gt;There are many accredited credential evaluation services that claim to translate your scores  from an international standard to a GPA system. They use a simple conversion scheme and somehow make your non-standard grades standard. I came across two such services that are a pain to use, provide an absolutely terrible service, and charge loads of dollars to do something that can be done with a pen and paper, or mentally within seconds. &lt;/p&gt;

&lt;p&gt;My first such experience was with &lt;a href="http://www.wes.org/"&gt;WES&lt;/a&gt; (World Education Services) that took over a month to deliver the converted grades that was supposed to be done overnight using an expedited service for which they charge an additional $195. It turned out that my documents were incomplete and instead of requesting all incomplete items at once, I had to mail them each missing item one by one, and on receiving that, they would request &lt;b&gt;one&lt;/b&gt; more document. After a month of these painful document exchanges, I called them up and asked them to just cancel the whole thing and refund my money, and voila!, the same day my evaluation was complete and mailed out to all the universities despite a missing document.&lt;/p&gt;

&lt;p&gt;The conversion system that most universities use for converting grades from India is basically that anything above 60% is equivalent to an A, 50-60% gets translated to a B, and below that is an F. I am not opposed to these services charging hundreds of dollars for doing such a simple conversion, but when they provide a crappy service on top of that, it becomes an almost useless exercise.&lt;/p&gt;

&lt;p&gt;My second experience is ongoing with &lt;a href="http://www.ece.org/"&gt;ECE&lt;/a&gt; (Education Credential Evaluators) which is no different. The default method of payment on their website is to basically print out the application and write in the payment information on a piece of paper and mail it out to them. Besides being extremely unsecure and time-consuming, I don&amp;#8217;t really see the point of them having a website at all. Why not just tie your VISA or Mastercard details to a pigeon&amp;#8217;s leg, and send it out to these people. And since you don&amp;#8217;t know when the pigeon landed, naturally you would call them up to find out, wait in a queue for half-an-hour, and then hang up out of disgust. For some reason, they never have any customer service agents that are free. This indicates that the process is broken and something should be done to fix it. They don&amp;#8217;t provide a charity service - it&amp;#8217;s a proper business and should be run as such.&lt;/p&gt;

&lt;p&gt;So if you&amp;#8217;re reading this and thinking of choosing a credential evaluation service, I would urge you to just drop the whole idea altogether. If a university is insistent on having your grades converted through one of these services, because they don&amp;#8217;t have the basic mathematical skills to carry out simple calculations, then that university is probably not worth your time. Look at other greener pastures.&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/501352206</link><guid>http://vombat.tumblr.com/post/501352206</guid><pubDate>Tue, 06 Apr 2010 13:07:00 -0700</pubDate><category>course evaluation services</category><category>WES</category><category>ECE</category><category>scam</category></item><item><title>"evil is as eval does"</title><description>“evil is as eval does”&lt;br/&gt;&lt;br/&gt; - &lt;em&gt;Anurag Mishra&lt;/em&gt;</description><link>http://vombat.tumblr.com/post/452750262</link><guid>http://vombat.tumblr.com/post/452750262</guid><pubDate>Tue, 16 Mar 2010 12:47:00 -0700</pubDate></item><item><title>Implementing an EventBus in MooTools</title><description>&lt;p&gt;An event bus can be useful in making your web applications more maintainable and manageable. It does so by decoupling the source of the application events from their destination. In complex web applications, a change in one part of the screen might require other parts of the screen to update as a result.&lt;/p&gt;
&lt;p&gt;A big part of this manageability comes with using custom events that are closer to our domain model than &amp;#8216;clicks&amp;#8217;, or &amp;#8216;mouseovers&amp;#8217;. If you have any doubts about the usefulness of custom events, you might want to read this &lt;a href="http://www.dustindiaz.com/custom-events/"&gt;article&lt;/a&gt; first.&lt;/p&gt;
&lt;p&gt;A very common example of such a custom event is user registration. Once a user registers on a site, and assuming they are automatically logged-in right after, then various parts on the screen will need to be updated as a result. A registration successful message pops-up somewhere. The navigation panel is updated with a Logout link. Other things that only registered users can do will get activated.&lt;/p&gt;
&lt;p&gt;If your application is highly modularized into widgets, views, etc., then you might not want to create an unnecessary binding between those components just because they need to listen to a particular event that some other component happens to fire. All that a widget needs to know is that an event of interest has fired, regardless of the source (for most cases), and that it must respond to it. Ray Ran gives a nice example with a full walkthrough in his &lt;a href="http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html"&gt;talk at Google I/O&lt;/a&gt; and explains how an EventBus solves the problem. I highly recommend watching the talk since the problem and solution that he demonstrates is very much applicable to any complex web application and not just apps written in &lt;a href="http://code.google.com/webtoolkit/"&gt;Google Web Toolkit&lt;/a&gt;. An event bus acts as a central broker for communicating events to various parts of the application that need not know about each other&amp;#8217;s presence. It basically &lt;a href="http://en.wikipedia.org/wiki/Publish/subscribe"&gt;publish-subscribe&lt;/a&gt; and somewhat similar to the &lt;a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/Reference/Reference.html"&gt;NSNotificationCenter&lt;/a&gt; in Cocoa if you&amp;#8217;re familiar with that.
&lt;/p&gt;&lt;p&gt;Once you are thoroughly convinced that you absolutely need this, you would really like the solution too if you&amp;#8217;re using MooTools. Why? checkout for yourself -
&lt;/p&gt;&lt;p&gt;&lt;code&gt; var EventBus = new Class({Implements: Events});&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;1 line. That&amp;#8217;s all that you need to start using an EventBus. MooTools classes can already handle events by implementing Events in Class.Extras. All that is need is creating an object of a class that does this and passing it around to whoever needs is using dependency injection and each object can register and post their events to this event bus.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a small example that makes use of this event bus with a couple of different types of classes:&lt;/p&gt;

&lt;iframe style="width: 100%; height: 550px" src="http://mootools.net/shell/F6DNH/3/embedded/"&gt;&lt;/iframe&gt;

Here&amp;#8217;s a tiny &lt;a href="http://github.com/AnuragMishra/MooTools-EventBus"&gt;wrapper&lt;/a&gt; around the EventBus class above. All it does is change the names addEvent, removeEvent, and fireEvent to be a little more semantic with &lt;a href="http://en.wikipedia.org/wiki/Observer_pattern"&gt;observers&lt;/a&gt;. Nothing fancy.</description><link>http://vombat.tumblr.com/post/425704473</link><guid>http://vombat.tumblr.com/post/425704473</guid><pubDate>Wed, 03 Mar 2010 21:47:00 -0800</pubDate><category>MooTools</category><category>EventBus</category></item><item><title>Controlling a MooDialog of an existing element programatically</title><description>&lt;p&gt;&lt;a title="MooDialog" href="http://mootools.net/forge/p/moodialog"&gt;MooDialog&lt;/a&gt; is a very nice Javascript plugin for creating your own dialog boxes that are much better looking than the native confirms, alerts, and prompts. The plugin offers much more in functionality and can be used to create dialog boxes with an iframe&amp;#8217;s content, ajax responses, and existing DOM elements among others.&lt;/p&gt;
&lt;p&gt;Once created, these dialog boxes can be programmatically opened, closed, or disposed off. The online documentation is very well written, but it doesn&amp;#8217;t mention how would you open or close a dialog that was created using an existing DOM element.&lt;/p&gt;
&lt;p&gt;To create a dialog from an existing element, we would just call .MooDialog() on the element.&lt;/p&gt;
&lt;pre&gt;&lt;code class="html"&gt;&amp;lt;div id="myElement"&amp;gt;
  ...
&amp;lt;/div&amp;gt;

$('myElement').MooDialog(); // that's all
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, since this method call simply returns myElement (for chaining purposes, I believe) and not the MooDialog object, we cannot call open() and close() on it. The plugin has a brilliant solution to take care of the problem - the Element store.&lt;/p&gt;
&lt;p&gt;The dialog object is stored with the key &amp;#8220;MooDialog&amp;#8221; into the element store. So to get access to the dialog object for &amp;#8220;myElement&amp;#8221;, simply call retrieve(&amp;#8216;MooDialog&amp;#8217;) on it.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var dialog = $('myElement').retrieve('MooDialog');
dialog.open();
dialog.close();
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/367948736</link><guid>http://vombat.tumblr.com/post/367948736</guid><pubDate>Tue, 02 Feb 2010 18:26:00 -0800</pubDate><category>MooDialog</category><category>MooTools</category></item><item><title>Chrome includes site search from the address bar</title><description>&lt;p&gt;Google Chrome has a nice little feature that allows using a website&amp;#8217;s own search through Chrome&amp;#8217;s address bar directly.&lt;/p&gt;
&lt;p&gt;For example, a query like &amp;#8220;railscasts.com openid&amp;#8221; will automatically goto railscasts.com and perform a search on that site itself.&lt;/p&gt;
&lt;p&gt;&lt;img height="85" width="531" src="http://i49.tinypic.com/zik22p.jpg"/&gt;&lt;/p&gt;
&lt;p&gt;The search is being performed in the site itself, and the local search box is populated with the query that was typed in Chrome&amp;#8217;s address bar.&lt;/p&gt;
&lt;p&gt;&lt;img height="256" width="807" src="http://i48.tinypic.com/11vl9vo.jpg"/&gt;&lt;/p&gt;
&lt;p&gt;Google is parsing the search forms from various sites and providing direct access to those through the address bar. I&amp;#8217;ve seen this work for all sites that do contain a identifiable search box, but not on sites that do not have any search capabilities.&lt;/p&gt;
&lt;p&gt;Long live Chrome!&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/362478403</link><guid>http://vombat.tumblr.com/post/362478403</guid><pubDate>Sat, 30 Jan 2010 19:43:00 -0800</pubDate></item><item><title>GWT project is resurrected after upgrade to 2.0</title><description>&lt;p&gt;After upgrading to GWT 2.0, my project suddenly stopped compiling. Almost 4 hours into the problem, but its finally solved!&lt;/p&gt;
&lt;p&gt;I was using the Base64 class in Apache Commons Codec library for some base64 encoding. GWT includes the commons codec package but an older version of Base64 which didn&amp;#8217;t have the encodeToString(byte[]) method in it that I was using. Had to reorder the jars to get it working again.&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/342273124</link><guid>http://vombat.tumblr.com/post/342273124</guid><pubDate>Mon, 18 Jan 2010 22:41:08 -0800</pubDate></item><item><title>MooTools class keyword breaks in Safari</title><description>&lt;p&gt;Having test the app in Chrome and Firefox, I happily strolled to Safari in a delightful mood only to find a blank page and JavaScript errors, yikes. After some digging on Google, I found the problem. Safari is not only backward compliant but forward compliant too. The class keyword that is very often used while creating an Element in MooTools is a future reserved keyword in ECMAScript language specification ECMA-262. Don&amp;#8217;t believe me? Check it out for yourself at &lt;a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"&gt;&lt;a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm"&gt;http://www.ecma-international.org/publications/standards/Ecma-262.htm&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Not a huge problem and we have to quote the class keyword. So something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var container = new Element("div", {class: "link"});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;now becomes this. Note the quotes around class&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var container = new Element("div", {"class": "link"});&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And we&amp;#8217;re good to go!&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/333650345</link><guid>http://vombat.tumblr.com/post/333650345</guid><pubDate>Wed, 13 Jan 2010 21:45:00 -0800</pubDate><category>javascript</category><category>safari</category><category>mootools</category><category>ecmascript</category></item><item><title>Adding custom scrollbar-less scrolling with MooTools</title><description>&lt;p&gt;This is a tiny class that adds scrolling capabilities with just a mouse wheel to any element in MooTools. Could not use the Slider class as I wanted it to be really lightweight, rather flyweight. Just remember, there are no bars - only content that can be scrolled with a mousewheel.&lt;/p&gt;
&lt;p&gt;To use, pass in an Element and an options object. The options object only takes one parameter &amp;#8220;direction&amp;#8221; which may be &amp;#8220;horizontal&amp;#8221; or &amp;#8220;vertical&amp;#8221;. The default value is vertical.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;var scrollable = new Scrollable($("#content"));&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the actual class.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;/*
 * Makes any Element scrollable. The element needs to have the overflow property as "auto".
 * This is a lightweight class, and does not require any libraries other than Core.
 *
 * To use, create a new Object of Scrollable, and pass in an Element.
 * var scrollable = new Scrollable($('div'));
 *
 * @Author Anurag Mishra
 * @Date Jan 13, 2010
 *
 */
var Scrollable = new Class({
	Implements: Options,
	options: {
		direction: "vertical"
	},
	/*
	 * @param content Element the element that is to be made scrollable.
	 * @param options Options optional hash to indicate direction of scroll. Possible
	 * values are "horizontal" or "vertical". The default value is "vertical".
	 */
	initialize: function(content, options) {
		this.setOptions(options);
		this.content = content;
		this.content.addEvent("mousewheel", this.onScroll.bind(this));
	},
	pickValue: function(horizontal, vertical) {
		return this.isVerticalScroll() ? vertical : horizontal;
	},
	onScroll: function(event) {
		var stepSize = this.getScroll() - event.wheel;
		if(this.isVerticalScroll()) {
			this.content.scrollTo(0, stepSize);
		}
		else {
			this.content.scrollTo(stepSize, 0);
		}
	},
	getContent: function() {
		return this.content;
	},
	getScroll: function() {
		return this.pickValue(this.content.getScroll().x, this.content.getScroll().y);
	},
	isVerticalScroll: function() {
		return this.options.direction == "vertical";
	},
	isHorizontalScroll: function() {
		return !this.isVertical();
	}
});
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/332217012</link><guid>http://vombat.tumblr.com/post/332217012</guid><pubDate>Wed, 13 Jan 2010 03:08:00 -0800</pubDate></item><item><title>Insert and Delete for Javascript Arrays</title><description>&lt;p&gt;Javascript is an awesome language but lacks some useful API&amp;#8217;s such as for Arrays. Insert and delete at a particular position are two very basic array operations that can be done by using the splice method. I didn&amp;#8217;t even know what splice meant till I bumped across Javascript Arrays. Now Array can be easily extended to do that using prototype, but a better home for such methods and wrappers is in the core language itself.&lt;/p&gt;
&lt;p&gt;For the time being, it&amp;#8217;s easy to create wrappers that use splice under the hood.&lt;/p&gt;
&lt;pre&gt;&lt;code class="javascript"&gt;// Insert element at the given index in array
Array.prototype.insert = function(element, index) {
	this.splice(index, 0, element);
}
// Remove the element at the given index
Array.prototype.remove = function(index) {
	this.splice(index, 1);
}
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/304905664</link><guid>http://vombat.tumblr.com/post/304905664</guid><pubDate>Mon, 28 Dec 2009 12:56:00 -0800</pubDate><category>array</category><category>delete</category><category>insert</category><category>javascript</category></item><item><title>Project Euler Problem 24</title><description>&lt;p&gt;Used the algorithm on Wikipedia at &lt;a href="http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation"&gt;&lt;a href="http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation."&gt;http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation.&lt;/a&gt;&lt;/a&gt; It&amp;#8217;s a generic method that takes any arbitrary list and the desired permutation number k.&lt;/p&gt;
&lt;p&gt;Problem Statement&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:&lt;/p&gt;
&lt;p&gt;012   021   102   120   201   210&lt;/p&gt;
&lt;p&gt;What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;require "fixnum.rb" # Fixnum.factorial
def permutation(k, list)
  size = list.size
  factorial = (size-1).factorial
  result = []

  while result.size != size
    x = k / factorial
    x -= 1 if (k % factorial).zero?
    result &amp;lt;&amp;lt; list.delete_at(x)
    k = k % factorial
    factorial = (list.size - 1).factorial
  end
  result
end

puts permutation(1000000, [0,1,2,3,4,5,6,7,8,9]).join
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/297683091</link><guid>http://vombat.tumblr.com/post/297683091</guid><pubDate>Wed, 23 Dec 2009 18:02:00 -0800</pubDate><category>project euler</category><category>problem 24</category><category>ruby</category></item><item><title>Project Euler Problem 23</title><description>&lt;p&gt;This problem required generating all &amp;#8220;abundant&amp;#8221; numbers below the specified limit, and then canceling out those that could not be reached by adding up any two abundant numbers from the generated list.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.&lt;/p&gt;
&lt;p&gt;A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n.&lt;/p&gt;
&lt;p&gt;As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.&lt;/p&gt;
&lt;p&gt;Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Solution in Ruby:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;require "mathn"
require "set"
require "fixnum.rb" # for Fixnum.factor?
require "array.rb" # for Array.sum

abundant = []
all = (1..max).to_set
sum_of_abundant_numbers = Set.new
max = 28123

# find all abundant numbers
(1..max).each do |n|
  factors = Set.new
  (1..Math.sqrt(n)).each do |f|
    if n.factor?(f)
      factors &amp;lt;&amp;lt; f
      factors &amp;lt;&amp;lt; (n/f) unless f == 1
    end
  end
  abundant &amp;lt;&amp;lt; n if factors.to_a.sum &amp;gt; n
end

# find sum of all abundant number pairs
abundant.each do |a|
  abundant.each do |b|
    break if a + b &amp;gt; max
    sum_of_abundant_numbers &amp;lt;&amp;lt; a + b
  end
end

all = all - sum_of_abundant_numbers
puts all.to_a.sum
&lt;/code&gt;&lt;/pre&gt;</description><link>http://vombat.tumblr.com/post/297500299</link><guid>http://vombat.tumblr.com/post/297500299</guid><pubDate>Wed, 23 Dec 2009 15:41:00 -0800</pubDate><category>project euler</category><category>problem 23</category><category>ruby</category></item><item><title>One liner for Project Euler problem 20</title><description>&lt;p&gt;I was needlessly worrying about about the capabilities of Bignum in being able to handle this factorial which has 158 digits in its result. Wasn&amp;#8217;t an issue at all though.&lt;/p&gt;
&lt;p&gt;Ruby certainly brings conciseness to the code. It maybe possible in a lot lesser characters in J or other functional languages, but this is good enough for me for the time being.&lt;/p&gt;
&lt;p&gt;The problem statement is&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Find the sum of the digits in the number 100!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Solution in Ruby&lt;/p&gt;
&lt;p&gt;&lt;code&gt; puts (1..100).to_a.inject{|prod, n| prod * n}.to_s.split(//).map{|d| d.to_i}.inject{|sum, n| sum + n}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Edit: even shorter with the reduce method in Ruby 1.9&lt;/p&gt;
&lt;p&gt;&lt;code class="ruby"&gt;(1..100).reduce(:*).to_s.split(//).map{|d| d.to_i}.reduce(:+)&lt;/code&gt;&lt;/p&gt;</description><link>http://vombat.tumblr.com/post/296639573</link><guid>http://vombat.tumblr.com/post/296639573</guid><pubDate>Wed, 23 Dec 2009 02:44:00 -0800</pubDate><category>project euler</category><category>problem 20</category><category>ruby</category><category>one-liner</category></item></channel></rss>
