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.

Author Archives: admin

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

An algorithm to generate fake but realistic stock price graph data that trends

Sometimes you want to generate data. Generating random data is pretty easy, but that doesn’t represent real user behavior. Real user behavior probably follows patterns. Here is an approach to generating some data that approximates stock price fluctuations. The below algorithm will generate a string of code that can be input into Google charts for […]

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

How to customize Http Digest Authentication error pages in Ruby on Rails

Say you are working on a site that has a splash/landing page that is public, but the site rest of the site needs to be locked down to a small group of people to alpha test. You could build this into your authentication model, or you could do it quickly and easily using HTTP Digest […]

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

Carrierwave custom validations

The use case here is when you need to conditionally validate the extensions you validate.  In our case, we only wanted to validate the extension white list when a local file was uploaded.  This is because our users can signup via Yammer during which we suck in their mugshot images.  Yammer’s mugshot urls do not […]

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

Forget pretty urls, how about vain gorgeous urls

In Rails, resource based urls are by default not pretty.  For example, say you have the following routing resources :projects do resources :users end This yields urls /projects /projects/1 /projects/1/users /projects/1/users/1 So to make pretty urls, its pretty trivial.  Just implement #to_param on the project model and user model #app/models/project.rb class Project < ActiveRecord::Base … […]

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

Beginner’s electronics soldering project: Led Origami Flower

Led Origami Flower

Ok, so its been some time since I’ve done any soldering, so I figured I start with a small attainable project before I move on to my project of building a cigar box speaker(http://blog.makezine.com/projects/make-34/monobox-powered-speaker-2/). Since I ordered some parts from Jameco, I went with their LED Origami Flower project as my starter project. So, the premise […]

Posted in Electronics, Projects, Technology | Comments closed

Rails deployments from 4 minutes to 40 seconds

Currently my deployment(which is pretty close to a default setup) takes about 4 minutes.  Currently we take the server offline into a “maintenance” mode for the entire deployment process.  That’s 4 minutes of downtime.  No bueno. Here’s what we’re going to do: 1. Move the maintenance mode (think of it like a mutex) to wrap […]

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

Capistrano Callback Sequence

Considering how well Capistrano is documented otherwise, I’m surprised there isn’t better documentation on the load order or sequence of the default capistrano tasks. There Capistrano Deploy Recipe doc, which if you read(and who likes to do that), you can kind of figure it out.  But where are the pictures!  Google didn’t seem to turn up […]

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

Patterns: Exception Factory(or is it a Proxy?)

Let’s say you are writing a library that wraps around an API, say Yammer.  Your library probably uses a lower level library to manage the http requests, say Faraday.  There are a multitude of problems that may arise while communicating with their api.  For example, the user could have revoked their token, or there could […]

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

Capybara custom matcher alternative

Sometimes when writing specs, you want to test a high level case multiple times across multiple spec tests.  This test may involve asserting multiple things on the page. There is probably a proper way to do this, like see this gist , or there is my way, which seems way simpler. So the objective is to […]

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

Ec2, Elastic LoadBalancers, Passenger, forcing ssl and how not to drive yourself crazy

Say you are using ec2, elastic load balancers and passenger to run your rails app, and then say you want to force ssl for all requests.  If you’re running a Rails 3.1+ app you just need to specify force_ssl, right?  nope. Do these things and save yourself some time, money, and hair follicles: Change the […]

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

ProTip: Don’t name your namespaced controllers “ApplicationController”

Don’t do this: class Admin::ApplicationController < ApplicationController layout "admin" end class Admin::IndexController < Admin::ApplicationController end This works for the most part except that the layout is not chosen properly.  Rails just chooses the default application.html.erb layout. Instead, rename to something like this: class Admin::BaseController < ApplicationController layout "admin" end class Admin::IndexController < Admin::BaseController end you’re […]

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

Rails Nested Resource Controllers – what not to do when testing

Testing nested resource controllers is pretty easy and awesome.  It is not easy and awesome, however, if the name of your nested controller differs from the route you want to use. Examine the following resources :posts do resources :comments, controller: "UserComments" end Did you catch whats wrong with the above?  You may not actually run […]

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

Capybara, ajax, requirejs and how to pull your hair out in 8 easy hours…

Editors Note:  I wrote this post after a full day of hair pulling and shotgun debugging, so it may be a bit incoherent…but I wanted to get the situation documented as soon as possible.  Read at your own risk Capybara is awesome for rails acceptance testing. However, I do have a love/hate relationship with it. […]

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

Get more reliable wifi in remote areas: carry an extender

So you’re not gonna believe this next tip. Carry around a wifi extender. Yup, I said it.  and I’ve been doing it. I bought it in Germany, and its been with me down through Eastern Europe and now India.  I’ve been meaning to ship it home…but I keep delaying and it keeps getting me wifi […]

Posted in Tips, Travel | Tagged , , , | Comments closed

How to download a large file with a shaky internet connection, the 1337 way.

When traveling, the availability of a solid connection isn’t always reliable.  Or sometimes the file is so large and you are in transit you need to chip away at the download each time you find bits of access. Some browser download managers might support resume, but as of writing, Google Chrome does NOT.  pitiful, Chrome, […]

Posted in Tips, Travel | Tagged , , , | Comments closed

Know where you are always: offline mapping on Android

So, you’re in the middle of india and you need to find your guesthouse.  No one speaks english.  You can’t call for directions.  All you have is an address.  Out of luck?  Not on android. The latest version of Google Maps on Ice Cream Sandwich has the ability to pre-cache all the maps tiles within […]

Posted in Tips, Travel | Tagged , , , | Comments closed

Ubuntu 10.04, Rvm, and Rails 3.1.3 from scratch

Assumptions:(swap these out  in the below notes as you see fit) database: mysql scm: bazaar testing: capybara(has a libqt dependency) do basic install ubuntu 10.04 do full software update apt-get install build-essential curl git-core ruby zlib1g-dev libxml2-dev libxslt1-dev emacs mysql-client mysql-server libmysqlclient-dev bzr libqt4-core libqt4-dev rvm pkg install zlib openssl curl readline rvm install 1.9.2-p180 […]

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

ActiveScaffold and Rails 3.1.x without Asset pipeline

We have recently upgraded an app to rails 3.1.3 and to keep things simple(or so we thought) we avoided jumping into the asset pipeline. As expected, with rails, whenever you go against the grain, expect problems. The app was working mostly, until we tested ActiveScaffold.  First off, I despise AS.  It has definitely caused me […]

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

Letters from Istanbul – Part II

Hey all, I’ve caught a head cold so I”m not really into making this story pretty right now….Istanbul is still awesome.  The kindred connection between Istanbul and NY continues as I meet more and more Turk’s and Istanbulers.  I think it also shares a similarity in that its probably a nice place to visit, but […]

Posted in Travel, World Trip 2011/2012 | Comments closed

Letters from Istanbul, and a (brief) story of Transylvanian misadventure

After again trying(unsuccessfully) to wrangle the Romanian banks to accept my bank card, I cashed in my emergency dollars, leaving one last Jacksonin my pocket to contemplate whether he’s worth more than the lint he sits next to.  Or perhaps hes an optimist and looks towards brighter times in lands where he’s respected.  In either case, […]

Posted in Travel, World Trip 2011/2012 | Comments closed

Letters from Transylvania

Hey all, Transylvania!!!  :::insert megalomaniacal laughter set to tochata and fugue::::  actually i’m in a town called Brasov in the region of Transylvania.  Its close to Vlad the Impaler’s castle…so I’m gonna try to make it there tomorrow.  So Vlad the Impaler was actually dracula.  Dracula just means son of the dragon and his dad was […]

Posted in Travel, World Trip 2011/2012 | Comments closed

Letters from Budapest

Hey All, Just arrived into my hostel in Budapest!  It was crazy this morning getting out of Prague so I didn’t have time to send a “leaving prague” email, but alas, i’m safe and sound in freezing but beautiful budapest.  Did you know budapest is really 2 cities: buda and pest.  Also, “pest” isn’t pronounced […]

Posted in Travel, World Trip 2011/2012 | Comments closed

How to *Not Really* delete a ruby class from memory

Alright, alright…(first blog post here, cut me some slack…) So, how can you delete a class from memory in Ruby?  First, you might be asking….why in the hell would you do that. Well, as it happens, in my case, I wrote some base classes that other developers will derive off of.  So in this base […]

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