Warning: Creating default object from empty value in /homepages/39/d161420129/htdocs/p373.net/wp/wp-content/themes/p373b/admin/functions.php on line 183
Global Technology, Activism, Philosophy, Photography.

Monthly Archives: January 2014

Stub a ruby method and conditionally raise an exception based upon state of object

(If you want to skip my fancy and hilarious writing, skip straight to the SO post) Here’s the use case: You’re building  a mass email system for your globo-mega-corp’s 90,000 employees.  Your corp’s smtp server can only handle batches of 450 recipients at a time.  Your boss tells you your corp’s SMTP server is finicky […]

Posted in Coding, Ruby/Rails, Technology | Tagged , , | Comments closed

Adventures in Grunt-Land Part II: How to dynamically update files with Grunt-Replace

In the previous post, I went over how to setup Grunt so that you can have environment based builds.  A build for your development environment would have a destination of builds/development, builds for staging would go to builds/staging, and builds for production go to builds/production.  You get the idea. In this post, let’s take our […]

Posted in Coding, Ruby/Rails, Technology | Tagged , , | Comments closed

How to create environment based builds with Grunt

Grunt is pretty neat when it comes to creating builds of javascript applications.  However, I found it quite difficult to create environment based builds, ie, builds for development, staging, and production. First off, let me say that I’m not a javascript developer.  In reality, what I”m trying to do is very simple: create a deployment […]

Posted in Coding, Ruby/Rails, Technology | Tagged , , | Comments closed

Recursively generate nested errors in json with Rails

See this gist: https://gist.github.com/synth/8511262 def nice_errors(object, errors) object.errors.each do |key| error_obj = object.send(key) if error_obj.kind_of?(Array) errors[key] = {} error_obj.each {|item| nice_errors(item, errors[key])} elsif error_obj.kind_of?(ActiveRecord::Base) errors[error_obj.id] = {} nice_errors(error_obj, errors[error_obj.id]) else errors[key] = object.errors[key] end end return errors end end # call it with nice_errors(resource, {}) # will generate something like: {"errors":{"user_recipients":{"email":["may not be the same as […]

Posted in Coding, Ruby/Rails, Technology | Comments closed