Skip to content

Instantly share code, notes, and snippets.

View heliostatic's full-sized avatar

Ben Lee-Cohen heliostatic

View GitHub Profile
@dmitriy-kiriyenko
dmitriy-kiriyenko / 0_quest.md
Last active August 29, 2015 13:56
Ruby tests, mission 3

Find or create an object by a unique key and update it without introducing any extra objects.

Let's assume that an external API is being polled for payments. The actual external API is irrelevant to this task, what really matters is that each payment has a line_item_id and belongs to a service.

A line_item_id is unique in the scope of a service.

Assume that you are already given an ActiveRecord object (and underlying table) for representing a payment. It was already designed by another team member, it has been deployed and is being actively used in production.

class Payment < ActiveRecord::Base
@spence
spence / phantomjs-repl.sh
Last active August 29, 2015 14:19
Bash PhantomJS REPL modeled after https://github.com/sotownsend/BooJS
#!/usr/bin/env bash
### Repl Usage:
#
# $ ./phantomjs-repl.sh
# > missing
# ReferenceError: Can't find variable: missing
# > window
# [object Window]
# > console.log('Hello')
@zspencer
zspencer / sinatra_base.rb
Created June 9, 2011 06:26
Code Review of sinatra/base.rb
# external dependencies
require 'rack'
require 'tilt'
# stdlib dependencies
require 'thread'
require 'time'
require 'uri'
# other files we need
@betamatt
betamatt / Procfile
Created January 26, 2012 23:29
Running delayed_job with foreman
queue: ./queue.sh
@mahemoff
mahemoff / 999_add_indexes.rb
Created February 9, 2012 00:52
Rails mass migration to add indexes
class AddIndexes < ActiveRecord::Migration
INDEXES = {
:blogs => %w/title author_id/,
:comments => %w/blog_id subject poster_id/,
:events => %w/name place when/
}
def up
INDEXES.each { |table, cols |
/*
On OS X, basic text manipulations (left, right, command+left, etc) make use of the system key bindings,
and don't need to be repeated here. Anything listed here will take precedence, however.
*/
[
{ "keys": ["super+shift+n"], "command": "new_window" },
{ "keys": ["super+shift+w"], "command": "close_window" },
{ "keys": ["super+o"], "command": "prompt_open" },
{ "keys": ["super+shift+t"], "command": "reopen_last_file" },
{ "keys": ["super+alt+up"], "command": "switch_file", "args": {"extensions": ["cpp", "cxx", "cc", "c", "hpp", "hxx", "h", "ipp", "inl", "m", "mm"]} },
@tsmango
tsmango / deploy.rb
Last active November 6, 2015 21:22
Rails Rumble 2013 - Official Linode StackScript - Capistrano Deployment Recipe
require 'bundler/capistrano'
# This capistrano deployment recipe is made to work with the optional
# StackScript provided to all Rails Rumble teams in their Linode dashboard.
#
# After setting up your Linode with the provided StackScript, configuring
# your Rails app to use your GitHub repository, and copying your deploy
# key from your server's ~/.ssh/github-deploy-key.pub to your GitHub
# repository's Admin / Deploy Keys section, you can configure your Rails
# app to use this deployment recipe by doing the following:
@scottweisman
scottweisman / fade_in.sass
Last active December 11, 2015 09:58
Fade in animation with bourbon and Sass
@-webkit-keyframes fadeIn
from
opacity: 0
to
opacity: 1
@-moz-keyframes fadeIn
from
opacity: 0
to
@chmullig
chmullig / lakeMerritt.R
Last active December 14, 2015 16:58
Lake Merritt trash removal graph cleanup
#inspired by: http://www.reddit.com/r/dataisbeautiful/comments/19tgz2/one_of_the_worst_graphs_ive_ever_seen_courtesy_of/
#data from: http://www.lakemerrittinstitute.org/abt_lake_watershed_trash.htm
library(plyr)
library(reshape2)
library(zoo)
library(ggplot2)
library(scales)
df <- read.csv(textConnection("Month,2012,2011,2010,2009,2008,2007,2006,2005,2004,2003,2002,2001,2000,1999,1998,1997
require "sinatra"
require "google/api_client"
require "data_mapper"
require "twilio-ruby"
require 'rack-ssl-enforcer'
DataMapper::setup(:default, ENV["DATABASE_URL"] || "sqlite3://#{Dir.pwd}/dev.db")
class TokenPair
include DataMapper::Resource