Skip to content

Instantly share code, notes, and snippets.

View collinschaafsma's full-sized avatar
👋

Collin Schaafsma collinschaafsma

👋
View GitHub Profile
// cache any function call, use the args as a key
const memoize = (fn) => {
let cache = {};
return (...args) => {
if (cache[args]) {
return cache[args];
} else {
let result = fn.apply(this, args);
cache[args] = result;
return result;
@collinschaafsma
collinschaafsma / gist:5216346
Last active December 15, 2015 06:29
SSL Install
openssl genrsa -des3 -out server.key 2048
openssl rsa -in server.key -out server.key.insecure
mv server.key server.key.secure
mv server.key.insecure server.key
openssl req -new -key server.key -out server.csr
cat chain.crt server.crt > server-chain.crt
class Hood
attr_accessor :houses
def initialize(houses)
@houses = houses
end
def house_count
@houses.count
end
@collinschaafsma
collinschaafsma / bike.rb
Created November 14, 2012 21:01
bdw OO
# OO for the win!
# Bike class
# Classes in Ruby are Capitalized and are defined like so...
class Bike
# Accessors are handy, this is the equivalant of
#
# def state
# @state
@collinschaafsma
collinschaafsma / gist:3786008
Created September 26, 2012 04:19
Bicycle example for bdw / intro to programming class week 3, basics of methods.
# Bicycle example for bdw / intro to programming class week 3, basics of methods.
# I'm a method without variables
def ride
"OK, we're rolling..."
end
# I'm a method with variables
def gear_ratio(gearing)
(gearing[:front_chainring_gear].to_f / gearing[:rear_chainring_gear].to_f).round(2)
@collinschaafsma
collinschaafsma / gist:2662997
Created May 11, 2012 23:09
handlebars.rb segfault
/Users/collin/dev/farmhand_dev/vendor/bundle/gems/therubyracer-0.10.1/lib/v8/context.rb:100: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
-- Control frame information -----------------------------------------------
c:0037 p:---- s:0146 b:0146 l:000145 d:000145 CFUNC :Enter
c:0036 p:0043 s:0143 b:0143 l:000142 d:000142 METHOD /Users/collin/dev/farmhand_dev/vendor/bundle/gems/therubyracer-0.10.1/lib/v8/context.rb:100
c:0035 p:0165 s:0140 b:0140 l:000130 d:000139 BLOCK /Users/collin/dev/farmhand_dev/vendor/bundle/gems/therubyracer-0.10.1/lib/v8/context.rb:21
c:0034 p:0028 s:0135 b:0135 l:000134 d:000134 METHOD /Users/collin/dev/farmhand_dev/vendor/bundle/gems/therubyracer-0.10.1/lib/v8/portal.rb:16
c:0033 p:0057 s:0131 b:0131 l:000130 d:000130 METHOD /Users/collin/dev/farmhand_dev/vendor/bundle/gems/therubyracer-0.10.1/lib/v8/context.rb:10
c:0032 p:---- s:0127 b:0127 l:000126 d:000126 FINISH
// Fast
var http = require('http');
http.Server(function(req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
// Faster
var cluster = require('cluster');
@collinschaafsma
collinschaafsma / gist:2637446
Created May 8, 2012 17:10
farmhand structure
├── Gemfile
├── Thorfile
├── client
│   ├── app
│   │   ├── config.js
│   │   ├── farmhand.js
│   │   ├── main.js
│   │   ├── modules
│   │   │   └── crop.js
│   │   └── templates
@collinschaafsma
collinschaafsma / rails-grunt.js
Created April 10, 2012 03:43
Grunt config for Rails
// This is the main application configuration file. It is a Grunt
// configuration file, which you can learn more about here:
// https://github.com/cowboy/grunt/blob/master/docs/configuring.md
//
module.exports = function(grunt) {
grunt.initConfig({
// The clean task ensures all files are removed from the dist/ directory so
// that no files linger from previous builds.
@collinschaafsma
collinschaafsma / gist:2324360
Created April 7, 2012 01:11
Adding middleware with Railtie
module Foo
class Railtie < Rails::Railtie
initializer "foo.insert_middleware" do |app|
app.config.middleware.use "Foo::Middleware"
end
end
end
require "foo/railtie" if defined? Rails