CSV to JSON Convert Ruby

Here. Easy way to convert your CSV (with headers) to a representative json hash. It just creates a file with .json tacked onto the end.

require 'json'
require 'csv'


File.open("#{file_name}.json", "w") { |f| f.write(CSV.open(file_name, headers: true, header_converters: :symbol, converters: :all).to_a.map(&:to_hash).to_json) }

AngularJS ngMin Json Properties

One thing I ran across using these tools while trying to lazy load routes/pages was the inability to properly compress the JSON Object properties. One of the workarounds, specifically for a templateUrl in this case works like so (you have to specify that you want the function value, and not the first value returned from the array.

templateUrl: ["$stateParams", function($stateParams){
var templateUrl = "views/folder/" + $stateParams.page + ".html";
return templateUrl;

simple_form with AngularJS

Maybe I’ll stop monkeying with code, but here’s a time saver.  Couldn’t find a great solution to add ng-model’s to my bootstrap forms to bind AngularJS and certainly this doesn’t take the cake, but it does add my model names for my ng-models with simple_form.  Comment if you find issues in your code.  (Note: You will want to change the wrapper name here to ~namespace it to your wrapper). I did this to avoid conflicts on non-angular forms.

 module SimpleForm
   module Inputs
     class Base
       def input_html_options
         if @builder.options[:wrapper] == :bootstrap_angular
@input_html_options.reverse_merge!({ "ng-model" => "#{@builder.lookup_model_names.join(".")}.#{self.attribute_name}" })

Technology & Web Flashiness

I really like flashy-ness and feel that I have run across a bunch of cool sites on the web.  One thing that never surprises me though is running into security holes and vulnerabilities… Especially when I get to see the code from someone’s site.  When it boils down to it, that a developer can have a widget update several counts at the same time to enhance functionality to a user OR the developer can make a call back to the server to see if a username or keyword is available, doesn’t mean that the developer is super l33t.

The ability to build a solution that works inside and out, completely answering the business’ needs is a more valuable trait of a senior developer than any of these things above.  Maybe when you’re interviewing or discussing with potential team mates; mentioning the flashy coolness of AJAX is worth a shot, for small talk.  But a more important conversation about answering the business needs with a subset of functionality that does what the business wants it to do in a robust way is more beneficial.

To boot, using the proper architecture and development strategies to enhance your product with the flashy-ness later in short iterative bursts will show your customer that you are analyzing usage and making all business functionality easier for them.  Spend minimal time to market, then use feedback and user test analysis to decide where your product needs to grow.  Always consider your audience, get them on it first so you not only understand what they’re doing but have a very good idea of HOW they are doing it.  Use your AJAX L33tness and JavaScript skillz to create that “brilliance” that we all know exists and deliver the best product for your customer.

© 2012 - Jeff Ancel
Wordpress Themes
Scroll to Top