Skip to content

Instantly share code, notes, and snippets.

View nerdinand's full-sized avatar
💭
wat

Ferdinand Niedermann nerdinand

💭
wat
View GitHub Profile
@nerdinand
nerdinand / gist:dcd0b3da194fe2ff2bcb
Last active August 29, 2015 14:01
Ruby one-liner for calculating the total activity of each of the tracks from an Auphonic production description file
require "json"; p JSON.parse(File.read("ZCH042.json", external_encoding: "iso-8859-1", internal_encoding: "utf-8"))["statistics"]["tracks"].map{|t| [t["identifier"], t["activity"].nil? ? nil : t["activity"].map{|kv| kv[1] - kv[0]}.inject(:+)/60 ]}
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@nerdinand
nerdinand / spreadsheet_range.rb
Created June 13, 2012 13:40
Class for dealing with ranges of cells (2-dimensional) in spreadsheet gem
class SpreadSheetRange
BORDER_EDGES=[:bottom, :top, :right, :left]
def initialize(worksheet, row_range, col_range)
@worksheet = worksheet
@row_range = row_range
@col_range = col_range
end
def draw_border(where = :all, color = nil)