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
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 = 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!"
@cpb
cpb / example.rb
Last active Aug 29, 2015
replace method with method object
View example.rb
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
@lokimeyburg
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
end
a = total / 11
b = a * 11
c = total - b
result = 11 - c
@kalv
kalv / gist:7147336
Last active Dec 26, 2015
A list of links, patches and articles to help with Mavericks os x for ruby development
@passy
passy / yeoman_compass.md
Last active Jan 7, 2016
Using Yeoman with Compass Sprites
View yeoman_compass.md

Yeoman + Compass Sprites

Setup

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"
@thisisbrians
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
@matthewrobertson
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
end
@franksmule
franksmule / gulpfile.js
Last active Aug 8, 2017
gulp.js that does SASS, JS Concatenation Watching - Tutorial -> http://omcfarlane.co.uk/install-gulp-js-windows/
View gulpfile.js
//*********** 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');
@maxjustus
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 = rows.map do |d|
vals = columns.map {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
end
@mhuggins
mhuggins / multiparameter_attribute_assignment.rb
Last active Jan 16, 2019
MultiparameterAttributeAssignment
View multiparameter_attribute_assignment.rb
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
assign_attributes(params)
end
def assign_attributes(new_attributes)
You can’t perform that action at this time.