Skip to content

Instantly share code, notes, and snippets.

@mattsnyder
mattsnyder / heroku-helpers.md
Last active March 24, 2017 20:49
Heroku Census Helpers

Add Graphene with specific version

heroku addons:add graphenedb --version v218

Backup neo4j

tar -cjf graph.tar.bz2 /opt/neo4j-enterprise-2.1.5/data/graph.db

Add Remote for Heroku Staging

git remote add heroku-staging git@heroku.com:ut-census-staging.git

@mattsnyder
mattsnyder / 99bottles_spec.rb
Last active September 9, 2016 15:21
99bottles problem
describe "Bottles Song" do
it "the first verse" do
expected = "99 bottles of beer on the wall, " +
"99 bottles of beer.\n" +
"Take one down and pass it around, " +
"98 bottles of beer on the wall.\n"
expect(expected).to eq(Bottles.verse(99))
end
test "invalid when proper number of digits but letters mixed in" do
assert Phone.number("1a2a3a4a5a6a7a8a9a0a") == "0000000000"
end
defmodule Phone do
@doc """
Remove formatting from a phone number.
Returns "0000000000" if phone number is not valid
(10 digits or "1" followed by 10 digits)
## Examples
iex> Phone.number("123-456-7890")
Definitions.
INT = [0-9]
SPECIAL = [\(\)\.\-]
WHITESPACE = [\s\t\n\r]
Rules.
{INT} : { token, {int, TokenLine, TokenChars}}.
{SPECIAL} : skip_token.
@char_types [{~r/(?<number>\d)/, :digit}, {~r/(?<letter>\w)/, :letter}, {~r/(?<allowed>[\(\)\.\-])/, :allowed} ]
defp identify_char(char) do
{_, type} = Enum.find(@char_types, {nil, :unknown}, fn {reg, type} ->
String.match?(char, reg)
end)
{type, char}
end
@mattsnyder
mattsnyder / bash_profile.sh
Created December 26, 2013 14:56
Configure Bash prompt to perform Git command completion and show Git repo info
# Symlink the completion and prompt scripts from your Git install to your home directory
# Then add the following to your .bash_profile
source ~/git-completion.bash
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export PS1='\033[00;36m\]\W\[\033[01;37m\]$(__git_ps1)\[\033[01;36m\] \$\[\033[00m\] '
@mattsnyder
mattsnyder / null_object.rb
Created September 23, 2013 20:43
NullObject based on Avdi Grimm's Confident Code talk. http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/
class NullObject
def initialize
@origin = caller.first ### SETS ORIGIN FOR INSPECT INFO
end
def method_missing(*args, &block)
self
end
def nil?; true; end
@mattsnyder
mattsnyder / fuey.yml
Created August 23, 2013 11:57
Example fuey client configuration (v0.4.2)
---
title: "My app server"
logfile: /var/log/fuey.log
notifications:
-
- "run.trace"
- "Fuey::Log"
traces:
VPN_UP:
- Ping:
@mattsnyder
mattsnyder / sentry_example_controller.rb
Created June 26, 2013 14:56
Example of using sentry as guard clause/routing for Rails controllers
class PersonsController
extend ::Sentry
def show
# do stuff
end
sentry_for :show, :expect => [:person], :if_not => :handle_person_not_found
def subscribe
# do stuff