Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Gauthier ngauthier

View GitHub Profile
@ngauthier
ngauthier / docker-cleanup.sh
Created Jan 29, 2015
Clean up docker containers and images
View docker-cleanup.sh
# 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
View poro-json.rb
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 Dec 16, 2014
go dep inj via interface and constructor
View athea.go
package athena
import (
accountant "codeship-accountant",
janus "codeship-janus",
ares "ares-api"
)
func main() {
// codeship accountant implements accountant interface
View 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 Jul 24, 2014
Nick's Trello Tips
View tips.md
  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
View myscript.coffee
tea $("#person"),
name: "Nick",
bio: "Coderguy"
@ngauthier
ngauthier / merge.rb
Created Jun 25, 2014
ActiveRecord Scope Merging
View merge.rb
# 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 Jun 12, 2014
Squeaky: Ultralight Exception Notification and General Notifier
View application_controller.rb
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 Mar 1, 2017
Scraping the Web with Ruby Code
View scraping.rb
#!/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 Mar 31, 2014
Bink CLI Example
View bink.rb
#!/usr/bin/env ruby
require_relative '../config/environment'
Bundler.require :bot
name = ARGV[1]
csv = "#{name}.csv"
bot = Bink.new csv
command = ARGV[0]