Skip to content

Instantly share code, notes, and snippets.

Working from home

Weston Triemstra thermistor

Working from home
Block or report user

Report or block thermistor

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
adamcooper / example_controller.rb
Last active Aug 29, 2015
Sample Service Base Class and Result Class
View example_controller.rb
class UserController < ActionController::Base
def new
@user =
def create
result =[:user])
if result.successful?
redirect_to root_url, notice: "A welcome e-mail is on it's way!"
mhuggins / multiparameter_attribute_assignment.rb
Last active Jan 16, 2019
View multiparameter_attribute_assignment.rb
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
def assign_attributes(new_attributes)
kalv / gist:7147336
Last active Dec 26, 2015
A list of links, patches and articles to help with Mavericks os x for ruby development
matthewrobertson / base_serializer.rb
Last active Jun 14, 2016
A simple pattern for creating classes that encapsulate JSON serialization logic. Simply inherit from the `BaseSerializer` and override the hook methods as necessary.
View base_serializer.rb
# 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
passy /
Last active Jan 7, 2016
Using Yeoman with Compass Sprites

Yeoman + Compass Sprites


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"
kixorz / aws_iam_policy.json
Last active Sep 30, 2019
Update Route53 DNS records from your EC2 instance using this simple Ruby script. You can call it from rc.local after setting your hostname locally. First parameter is the desired <hostname>.<domain> Domain and other parameters are hardcoded. This script is useful for handling internal DNS changes in your systems after instance changes. Attached …
View aws_iam_policy.json
"Statement": [
"Action": [
"Effect": "Allow",
"Resource": [
thisisbrians / jquery-time-zone-select.js
Created Feb 3, 2013
Dynamically select a timezone in a Rails time_zone_select based on the browser's timezone using jQuery/JavaScript.
View jquery-time-zone-select.js
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
maxjustus / bulk_insert.rb
Last active Mar 14, 2018
Simple SQL bulk insert in Rails
View bulk_insert.rb
# 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 = do |d|
vals = {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
lokimeyburg / msp_number_generator.rb
Created Oct 26, 2012
Generate your own valid Canadian Medical Services Plan number.
View msp_number_generator.rb
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
a = total / 11
b = a * 11
c = total - b
result = 11 - c
rmurphey / gist:3086328
Created Jul 10, 2012
What's wrong with Netmag's "Optimize your JavaScript" post
View gist:3086328

What's wrong with Netmag's "Optimize your JavaScript" post

Update: The original post on Netmag has been updated since this was written.

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some people who actually know what they're talking about (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Things that are just plain wrong

You can’t perform that action at this time.