-
iPhone in-app purchasing now a…
Posted on October 15th, 2009 No commentsiPhone in-app purchasing now available for FREE apps. No more “Lite” versions! http://bit.ly/2eeRMQ
-
Thoughtful take on SEO. There’…
Posted on October 13th, 2009 No commentsThoughtful take on SEO. There’s basic solid advice and markup improvements but “experts” are just selling snake oil. http://bit.ly/3aAMya
-
Javascript: get remote data in one method call
Posted on October 8th, 2009 No commentsI came across this useful bit of javascript when I had some parameters and wanted to call the server and get some data from the db(preferably in a nice json object). All in one line, as if I was calling a local function without having to mess with callbacks. ajax and jQuery make this very simple.
Here’s what the code looks like:
var jsonLoader = function(url, params) { this.url = url; this.params = params; this.retrievedData = {}; this.getRawData(); }; jsonLoader.prototype.getRawData = function() { var json = $.ajax({ type: 'POST', contentType: "application/json; charset=utf-8", url: this.url, data: JSON.stringify(this.params), dataType: 'json', success: this.setRawData(this), async: false }); }; jsonLoader.prototype.setRawData = function(self) { return function(json) { self.retrievedData = json; }; };And you’d call it like this:
var params = new Object(); params.var1 = "something"; params.var2 = 22; var data = new jsonLoader("/WebService/MyMethod", params); data.retrievedData.d.{json object name returned by the server}The method blocks until data is retrieved(async: false), so you can start using data right away.
Make sure you have jQuery and JSON libraries loaded.
Credit to the original jsonLoader sniplet author for the idea, shown here tweaked to accept parameters.
-
All WebKits are not created eq…
Posted on October 8th, 2009 No commentsAll WebKits are not created equal: http://bit.ly/3Y5iNT (WebKit powers Safari, Chrome, iPhone, Pre, Android to name a few.)
-
Brilliant bit of marketing fro…
Posted on October 8th, 2009 No commentsBrilliant bit of marketing from the North Face. New products: sticks, rocks, and leaves! http://bit.ly/q66hq
-
Rails has_many Time.now gotcha
Posted on October 7th, 2009 No commentsIt’s one of those face palm moments for me, but don’t use has_many in your rails models if it’s time dependent data. In the production environment the Time.now will be the time the environment loads the class, which is only once per server start. Keep in mind your code will work in development and test mode. So basically the solution is to move those has_many statements into a function.
has_many :recent_stuff, :conditions => ["starts_at =?", Time.now]
becomes…
def recent_stuff
timenow = Time.now
self.find(:all, :conditions => ["starts_at = ?", timenow])
end


Recent Comments