Skip to content

Instantly share code, notes, and snippets.

View kcurtin's full-sized avatar

Kevin Curtin kcurtin

View GitHub Profile
@kcurtin
kcurtin / psql update
Last active August 29, 2015 14:06
Upgrade postgres to 9.3 from 9.2.8
# Had some issues, so referenced these 3 solutions:
# https://gist.github.com/cjolly/2870054
# https://gist.github.com/cloud8421/6667898
# http://stackoverflow.com/questions/20754669/how-to-fix-postgres-after-updating-upgrading-brew
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
pg_dumpall > ninedottwo-dump
# Not sure if this is necessary, but has to be cleared out no matter what for when we run initdb
@kcurtin
kcurtin / .travis.yml
Created December 16, 2014 20:29
Travis
before_script:
- ./script/travis/setup_db.sh
script: bundle exec rspec spec/ --tag $TEST_TAG
env:
matrix:
- TEST_TAG=js DB_TEST=1
- TEST_TAG=~js DB_TEST=2
@kcurtin
kcurtin / fizzbuzz.ex
Last active December 26, 2015 15:53
Fizzbuzz in elixir using pattern matching
Enum.each 1..100, fn (n) ->
fizzbuzz = fn
(0, 0, _) -> "fizzbuzz"
(0, _, _) -> "fizz"
(_, 0, _) -> "buzz"
(_, _, n) -> n
end
IO.puts fizzbuzz.(rem(n, 3), rem(n, 5), n)
end
@kcurtin
kcurtin / weather_parser.ex
Created February 14, 2016 16:34
Interfacing with the erlang xmerl library to parse xml data. Using xml files from weather.gov for sample data (http://w1.weather.gov/xml/current_obs/)
defmodule WeatherParser do
require Record
Record.defrecord :xmlElement, Record.extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl")
Record.defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
def parse(xml, attrs) do
xml
|> :binary.bin_to_list
|> :xmerl_scan.string
|> extract_values(attrs, [])
@kcurtin
kcurtin / ex_unite_case_template.ex
Last active February 26, 2016 16:39
Using case templates to setup your database for integration tests with elixir and ecto.
defmodule DBTransactions do
use ExUnit.CaseTemplate
setup_all do
Ecto.Adapters.SQL.begin_test_transaction(Repo)
on_exit fn ->
Ecto.Adapters.SQL.rollback_test_transaction(Repo)
end
end