Skip to content

Instantly share code, notes, and snippets.

View thermistor's full-sized avatar
🏠
Working from home

Weston Triemstra thermistor

🏠
Working from home
View GitHub Profile
@maxim
maxim / task.yml
Created June 12, 2014 11:09
Adding github to known_hosts with ansible
- name: ensure github.com is a known host
lineinfile:
dest: /root/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa github.com') }}"
regexp: "^github\\.com"
@franksmule
franksmule / gulpfile.js
Last active August 8, 2017 20:30
gulp.js that does SASS, JS Concatenation Watching - Tutorial -> http://omcfarlane.co.uk/install-gulp-js-windows/
//*********** 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');
@cpb
cpb / example.rb
Last active August 29, 2015 13:56
replace method with method object
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
@adamcooper
adamcooper / example_controller.rb
Last active August 29, 2015 13:56
Sample Service Base Class and Result Class
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!"
@mhuggins
mhuggins / multiparameter_attribute_assignment.rb
Last active September 5, 2020 19:41
MultiparameterAttributeAssignment
# app/models/concerns/multiparameter_attribute_assignment.rb
module MultiparameterAttributeAssignment
include ActiveModel::ForbiddenAttributesProtection
def initialize(params = {})
assign_attributes(params)
end
def assign_attributes(new_attributes)
@kalv
kalv / gist:7147336
Last active December 26, 2015 11:59
A list of links, patches and articles to help with Mavericks os x for ruby development
@matthewrobertson
matthewrobertson / base_serializer.rb
Last active June 14, 2016 07:16
A simple pattern for creating classes that encapsulate JSON serialization logic. Simply inherit from the `BaseSerializer` and override the hook methods as necessary.
# 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
@passy
passy / yeoman_compass.md
Last active January 7, 2016 19:24
Using Yeoman with Compass Sprites

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"
@kixorz
kixorz / aws_iam_policy.json
Last active April 11, 2022 10:32
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 …
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [
@thisisbrians
thisisbrians / jquery-time-zone-select.js
Created February 3, 2013 00:08
Dynamically select a timezone in a Rails time_zone_select based on the browser's timezone using jQuery/JavaScript.
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