Skip to content

Instantly share code, notes, and snippets.

@ngauthier
ngauthier / docker-cleanup.sh
Created January 29, 2015 14:49
Clean up docker containers and images
# Docker
function docker-cleanup {
# Find all containers that have exited
containers=`docker ps -a -q -f status=exited | xargs`
if [[ $containers ]]; then
# Remove exited containers
docker rm $containers
else
echo "No containers to remove"
fi
@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 / 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 / restart-last-build
Created November 19, 2014 15:44
Restart last build
#!/usr/bin/env bash
# Usage: restart-last-build <project-id>
# You must set the environment variable API_KEY to your codeship API key, for example:
# $ CODESHIP_API_KEY=abc123 restart-last-build 1234
PROJECT_ID=$1
set -e
echo Restarting last build for project $PROJECT_ID
@ngauthier
ngauthier / tips.md
Created July 24, 2014 14:32
Nick's Trello Tips
  1. Only keep the members who need to do something (blocking) the card on the card. Not everyone involved. After you do your part, take yourself off the card, and possibly add someone else to the card if it's their turn. It's important that all the cards with your face on it need you to do something. No false-positives.
  2. If you need someone's opinion on a card but they don't have to do something, just mention in a comment
  3. The description is the current state of the task, not a history of the evolution of the task. Comments are a history of the discussion that yields the description
  4. Use labels to indicate the kind of card, not state (e.g. "bug" but not "in qa"). Alternatively, have a code system in the card title. For example, we process data in batches. Batches have one to two letters to indicate client and numbers that increment. So IS42 is Internal Sales batch #42. This is nice when the label needs to be a little different each time. Instead of a label, put it at the beginning of the title.
  5. Use
@ngauthier
ngauthier / myscript.coffee
Created July 9, 2014 15:44
have some tea
tea $("#person"),
name: "Nick",
bio: "Coderguy"
@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 / 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 / scraping.rb
Last active March 1, 2017 13:29
Scraping the Web with Ruby Code
#!/usr/bin/env ruby
# From: http://ngauthier.com/2014/06/scraping-the-web-with-ruby.html
require 'capybara'
require 'capybara/poltergeist'
require 'csv'
require 'gdbm'
class NickBot
include Capybara::DSL
@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]