Skip to content

Instantly share code, notes, and snippets.

View gschorkopf's full-sized avatar

Geoffrey Schorkopf gschorkopf

View GitHub Profile
@gschorkopf
gschorkopf / sum_of_multiples_solution
Last active December 16, 2015 20:59
SumOfMultiples warmup solution
class SumOfMultiples
def initialize(*ints)
@numbers = ints.to_a
end
def self.to(max)
new(3, 5).to(max)
end
def to(max)
function getNext() {
scan = badgeScans[index];
console.log("got scan " + scan);
if (scan) {
var scanAction = svgContainer.selectAll("g")
.data([scan], function(d){return d.scan_time});
scanAction.exit().remove();
@gschorkopf
gschorkopf / JSTaskerSolution.js
Last active December 18, 2015 23:29
An less functional solution to JS tasker, with namespacing and object constructors. Could use some bits of refactoring. Big thanks to one Franklin Webber for being awesome.
// jQuery "on page load"
$(function(){
// Focus on the main field
$('input#task_text').focus();
// Object constructor for task list
var TaskList = function(element) {
// Assigning 'this.element' property from input (a selector). 'this.element' could be called anything.
this.element = $(element);

July

07-07

Jay-Z: Magna Carta Holy Grail

07-09

AraabMUZIK: The Remixes, Vol. 1

Daughn Gibson: Me Moan

07-16

Updated Sept 10, 2019
LPs:
Alt+J (∆) - An Awesome Wave
Amadou & Mariam - Welcome to Mali
Anais Mitchell - Hadestown
Anderson Paak - Malibu
Andrew Bird - Armchair Apocrypha
Andrew Bird - The Mysterious Production of Eggs
@gschorkopf
gschorkopf / users.rb
Created December 6, 2013 21:13
Sample FactoryGirl admin/user creation
FactoryGirl.define do
factory :user do
first_name "Geoff"
last_name "S"
role 'standard'
factory :admin do
role 'admin'
end
end
@gschorkopf
gschorkopf / orders_controller_etc.rb
Created December 13, 2013 18:03
Orders controller -> Worker -> Mailer
# Version 1:
def perform(order_attributes, user_attributes, order_total)
UserMailer.order_confirmation(order_attributes, user_attributes, order_total).deliver
end
def order_confirmation(user_attributes, order_attributes, order_total)
@user = user_attributes
@order = order_attributes
@total = order_total
@gschorkopf
gschorkopf / sanitation.rb
Last active December 31, 2015 14:19
Nifty ways to have custom sanitation for columns in Rails
# Goal: To clean up surrounding whitespace from a user's first_name field:
# rspec test:
describe User do
describe "first_name" do
it "sanitizes surrounding whitespace from column" do
user = User.new(first_name: " Stafford ")
expect(user.first_name).to eq "Stafford"
end
@gschorkopf
gschorkopf / tracks_2013
Last active January 2, 2016 00:39
Top Tracks of 2013
http://open.spotify.com/user/gschorkopf/playlist/1uN5MMGqmKSpf0FVNEZl8A
100. Ducktails – Under Cover
99. Danny Brown - Kush Coma
98. DJ Rashad – Let It Go
97. Run The Jewels – Banana Clipper
96. Mutual Benefit – Strong Swimmer
95. Mount Kimbie – Made To Stray
94. AlunaGeorge – Attracting Flies
93. Washed Out – All I Know
# app/models/user.rb
class User < ActiveRecord::Base
validates :password, complexity: true # You may also pass this a method that returns true/false
# ...
end
# app/validators/complexity_validator.rb
class ComplexityValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, "must have a number") if value !~ /(?=.*\d)/