OS X Mavericks, failing specs and libxml
3 Quick Tips for Coding with OS X 10.9 Mavericks Some good tips on homebrew and xcode to get compiling working
Install Ruby on Rails · Mac OS X Mavericks RVM / Homebrew / Git
class UserAdder < Struct.new(:user_params, :company_id, :role) | |
extend FriendlyMethodObject | |
def initialize(*) | |
super | |
# Provide defaults for optional members | |
self.role ||= :default_role | |
end | |
def call |
class UserController < ActionController::Base | |
def new | |
@user = User.new | |
end | |
def create | |
result = SignupUser.call(params[:user]) | |
if result.successful? | |
redirect_to root_url, notice: "A welcome e-mail is on it's way!" |
def valid_msp_number(msp_number) | |
weights = [0, 2, 4, 8, 5, 10, 9, 7, 3, 0] | |
total = 0 | |
weights.to_enum.with_index(1).each do |weight, i| | |
total = total + msp_number[i-1].to_i * weight.to_i | |
end | |
a = total / 11 | |
b = a * 11 | |
c = total - b | |
result = 11 - c |
OS X Mavericks, failing specs and libxml
3 Quick Tips for Coding with OS X 10.9 Mavericks Some good tips on homebrew and xcode to get compiling working
Install Ruby on Rails · Mac OS X Mavericks RVM / Homebrew / Git
generator-webapp
has support for compass out of the box. However, in order to use one of my favorite features of it — sprites and the image_url
helper — you have to make some adjustments to the Gruntfile
.
Let's assume you use a SASS stylesheet like this one:
@import "design/*.png"
jQuery.fn.selectTimeZone = function() { | |
var $el = $(this[0]); // our element | |
var offsetFromGMT = String(- new Date('1/1/2009').getTimezoneOffset() / 60); // using 1/1/2009 so we know DST isn't tripping us up | |
if (offsetFromGMT[0] != '-') { | |
offsetFromGMT = '+' + offsetFromGMT; // if it's not negative, prepend a + | |
} | |
if (offsetFromGMT.length < 3) { | |
offsetFromGMT = offsetFromGMT.substr(0, 1) + '0' + offsetFromGMT.substr(1); // add a leading zero if we need it | |
} | |
var regEx = new RegExp(offsetFromGMT); // create a RegExp object with our pattern |
# An abstract base class used to create simple serializers | |
# for ActiveRecord objects | |
class BaseSerializer | |
include Rails.application.routes.url_helpers | |
attr_reader :serialized_object | |
def initialize(serialized_object) | |
@serialized_object = serialized_object | |
end |
//*********** IMPORTS ***************** | |
var gulp = require('gulp'); | |
var sass = require('gulp-ruby-sass'); | |
var gutil = require('gulp-util'); | |
var rename = require("gulp-rename"); | |
var map = require("map-stream"); | |
var livereload = require("gulp-livereload"); | |
var concat = require("gulp-concat"); | |
var uglify = require('gulp-uglify'); | |
var watch = require('gulp-watch'); |
# Takes a table name, and an array of hashes where keys are column names and values are values. | |
# Expects hashes to all contain the same keys. | |
def bulk_insert(table, rows) | |
columns = rows.first.keys | |
to_insert = rows.map do |d| | |
vals = columns.map {|k| d[k] } | |
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals) | |
end |
class ActiveRecord::Base | |
mattr_accessor :shared_connection | |
@@shared_connection = nil | |
def self.connection | |
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection } | |
end | |
end | |
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection |