Skip to content

Instantly share code, notes, and snippets.

@ngauthier
ngauthier / bink.rb
Created March 31, 2014 14:08
Bink CLI Example
#!/usr/bin/env ruby
require_relative '../config/environment'
Bundler.require :bot
name = ARGV[1]
csv = "#{name}.csv"
bot = Bink.new csv
command = ARGV[0]
@ngauthier
ngauthier / application_controller.rb
Created June 12, 2014 14:49
Squeaky: Ultralight Exception Notification and General Notifier
class ApplicationController < ActionController::Base
rescue_from StandardError, with: :handle_exception
def squeak(*args)
SqueakyMailer.notification(*args).deliver
end
def handle_exception(e)
squeak(
message: "Error: #{e.message}",
@ngauthier
ngauthier / merge.rb
Created June 25, 2014 14:39
ActiveRecord Scope Merging
# Merging Scopes
# ==============
# The goal is to join two tables to get all the records where a scope on both
# side of the join is used. I used to do this with a `where()` in which I
# added some sql on the joined table. But, I wanted to use the existing scopes
# from the joining table. Turns out there's a `merge` method on a scope where
# you can merge with another scope without having to chain!
class Car < ActiveRecord::Base
has_and_belongs_to_many :people
@ngauthier
ngauthier / myscript.coffee
Created July 9, 2014 15:44
have some tea
tea $("#person"),
name: "Nick",
bio: "Coderguy"
@ngauthier
ngauthier / athea.go
Created December 16, 2014 13:11
go dep inj via interface and constructor
package athena
import (
accountant "codeship-accountant",
janus "codeship-janus",
ares "ares-api"
)
func main() {
// codeship accountant implements accountant interface
@ngauthier
ngauthier / poro-json.rb
Created January 13, 2015 13:28
poro json
require 'active_support'
require 'active_support/core_ext/object/json'
class Person
def initialize(name, age, car)
@name = name
@age = age
@car = car
@birthyear = compute_birth_year
end
@ngauthier
ngauthier / build-container
Created February 2, 2015 15:28
Static Golang Container via Tar
#!/usr/bin/env bash
# Makes a docker container for a static golang application.
# For a small app, this container is usually about 7mb.
#
# Usage:
# build-container myapp myuser/myapp cmd/myapp/main.go
set -e
# Version is the git sha for HEAD
version=$(git log -1 --format=format:%H)
@ngauthier
ngauthier / Makefile
Created April 6, 2015 15:20
Minimum Viable Go Dependency Manager
build:
# get all the deps
go get -d -v -t ./...
# check out the library to the right ref
checkit github.com/myaccount/mylib abc123
# build stuff!
go build ./...
# Add to the bottom of the rake file:
require 'hydra'
require 'hydra/tasks'
Hydra::TestTask.new('hydra:spec') do |t|
t.add_files 'spec/**/*_spec.rb'
end
Hydra::TestTask.new('hydra:features') do |t|
t.add_files 'features/**/*.feature'
end
module Search
VECTORS = [
{:klass => Company, :columns => ['ticker', 'name']},
{:klass => Executive, :columns => ['name']}
]
class << self
def find(query)
query = query.split(' ').join(' & ')
return Search::VECTORS.collect{|tuple|
Array(tuple[:columns]).collect{|column|