February 2012
1 post
Should we use the contentStretch property or a...
This journey began when I started reading up on the View Controller Programming Guide for iOS on Apple’s developer portal. This is what the guide recommended for creating stretchable views. Fun exercise.
October 2011
1 post
Building Dart on Snow Leopard
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’t break anything.
Unsupported compiler 'GCC 4.2' selected for architecture 'x86_64'
Basically we have to clear out all references to GCC 4.2 from
GCC_VERSION = 4.2;
to
GCC_VERSION = ""
...
July 2011
2 posts
5 tags
Responding with non-empty JSON when updating a...
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.
The quick-fix is easy - we override the default behavior of respond_with using a block that returns forces the response to be the complete JSON...
2 tags
Linker errors with iOS 5 and libz
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 libz. We were referencing libz.1.2.3 which is apparently not included in iOS 5 SDK. I think it only contains version 1.2.5 now. The worst part was that libtool was failing, and it gave...
June 2011
1 post
How do you dynamically set AJAX request data with...
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.
So what was the problem? How do we dynamically modify the AJAX request data with rails using a link_to. If I...
July 2010
1 post
4 tags
Ruby version of Facebook's get_facebook_cookie in...
Facebook provides an example of Single Sign-on that includes a method of verifying the authenticity of facebook’s cookie that is set by their JavaScript SDK. The method is defined as:
<?php
define('FACEBOOK_APP_ID', 'your application id');
define('FACEBOOK_SECRET', 'your application secret');
function get_facebook_cookie($app_id, $application_secret)
{
$args = array();
...
June 2010
1 post
Enumerating Arrays and Objects in JavaScript
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.
When we are dealing with objects, the order of enumeration is not guaranteed. With arrays it is. That’s all there...
April 2010
2 posts
2 tags
authlogic_facebook_connect with a custom callback...
If you’re using authlogic_facebook_connect to have facebook integration in your site and don’t want to use the standard callback url of http:///user_session, then pass a controller option to the authlogic_facebook_login_button function and pass the controller name. Actually you don’t need a controller name, just the path from the root url would do.
Here’s the code I am...
4 tags
The unnoticed Course Evaluation SCAM
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...
March 2010
2 posts
evil is as eval does
– Anurag Mishra
2 tags
Implementing an EventBus in MooTools
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.
A big part of this manageability comes with using custom events that are closer to our domain...
February 2010
1 post
2 tags
Controlling a MooDialog of an existing element...
MooDialog 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’s content, ajax responses, and existing DOM elements among others.
Once created, these dialog boxes can be programmatically opened, closed,...
January 2010
4 posts
Chrome includes site search from the address bar
Google Chrome has a nice little feature that allows using a website’s own search through Chrome’s address bar directly.
For example, a query like “railscasts.com openid” will automatically goto railscasts.com and perform a search on that site itself.
The search is being performed in the site itself, and the local search box is populated with the query that was typed in...
GWT project is resurrected after upgrade to 2.0
After upgrading to GWT 2.0, my project suddenly stopped compiling. Almost 4 hours into the problem, but its finally solved!
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’t have the encodeToString(byte[]) method in it that I was using. Had to reorder the jars to get it...
4 tags
MooTools class keyword breaks in Safari
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...
Adding custom scrollbar-less scrolling with...
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.
To use, pass in an Element and an options object. The options object only takes one parameter...
December 2009
6 posts
4 tags
Insert and Delete for Javascript Arrays
Javascript is an awesome language but lacks some useful API’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’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...
3 tags
Project Euler Problem 24
Used the algorithm on Wikipedia at http://en.wikipedia.org/wiki/Permutation#Lexicographical_order_generation. It’s a generic method that takes any arbitrary list and the desired permutation number k.
Problem Statement
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...
3 tags
Project Euler Problem 23
This problem required generating all “abundant” 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.
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,...
4 tags
One liner for Project Euler problem 20
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’t an issue at all though.
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.
The problem statement is
Find the sum of...
3 tags
Project Euler Problem 17
This is a good way to learn Ruby by solving some problems from Project Euler. Here’s my solution to problem 17. Link to the problem - http://projecteuler.net/index.php?section=problems&id=17 and the problem text and solution are below:
If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
If all the...
November 2009
3 posts
myfacebookspacekutsquarewalla.com
Ultimate social networking domain name.. combining the best of all worlds -myfacebookspacekutsquarewalla.com
facebook
myspace
orkut
foursquare
gowalla
3 tags
Draw rectangles with canvas tag in html5
So far I am loving what html5 has to offer for web and mobile applications. There’s some amazing stuff that can be done with mouse events and the 2d drawing API. This is a simple demo for creating filled black rectangles on a canvas. I am hoping to use this as a building construct in a much bigger project.
canvas.js
var rect;
var canvas;
var context;
var dragging;
function Point(x, y)...
You may look around and see two groups here; white collar, blue collar. But I...
– Michael Scott