Skip to content

Instantly share code, notes, and snippets.

View jemmyw's full-sized avatar

Jeremy Wells jemmyw

View GitHub Profile
@jemmyw
jemmyw / 7.exs
Created December 10, 2018 11:07
require IEx
defmodule Steps do
def parse(str) when is_bitstring(str) do
str |> String.split("\n") |> parse()
end
def parse([]), do: []
def parse([h | t]) do
defmodule Danger do
def parse(str) when is_bitstring(str) do
str
|> String.split("\n")
|> parse()
|> Enum.with_index()
|> Enum.map(fn {c, i} ->
{c, [?a + i] |> to_string}
end)
end
defmodule Polymer do
def scan(p, status \\ :ok)
def scan(p, _) when is_bitstring(p) do
p = "%#{p}"
p
|> String.to_charlist()
|> scan(:ok)
|> elem(0)
defmodule Sleeps do
def parse([]), do: []
def parse([nil, t]), do: parse(t)
def parse([h | t]), do: [parse(h) | parse(t)]
def parse(str) do
~r/^\[(\d+)-(\d+)-(\d+) (\d+):(\d+)\] (.+)/
|> Regex.run(str)
|> List.delete_at(0)
|> List.to_tuple()
defmodule Squares do
def parse([]), do: []
def parse([h | t]) do
[parse(h) | parse(t)]
end
def parse(str) do
~r/^#(\d+)\s+@\s+(\d+),(\d+):\s+(\d+)x(\d+)$/
|> Regex.run(str)
defmodule Checksum do
def countchars(''), do: 0
def countchars(chars) do
chars
|> Enum.uniq()
|> Enum.map(&countchar(&1, chars))
end
def countchar(_, []), do: 0
@jemmyw
jemmyw / 1.exs
Created December 1, 2018 09:58
aoc 1.exs
defmodule One do
def split(str) do
[String.slice(str, 0..0), String.to_integer(String.slice(str, 1..-1))]
end
def value("+", n), do: n
def value("-", n), do: -n
def split_value(str) do
apply(One, :value, split(str))
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.0.beta1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# Ensure backward compatibility with Minitest 4
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)
# This connection will do for database-independent bug reports.
bundle
Fetching gem metadata from https://****:****@gems.****.co.nz/.
Fetching full source index from https://****:****@gems.****.co.nz/
Unfortunately, a fatal error has occurred. Please see the Bundler
troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
/Users/jeremy/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/1.8/net/https.rb:138:in `verify_mode=': can't modify frozen object (TypeError)
from /Users/jeremy/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/1.8/net/https.rb:138:in `verify_mode='
from /Users/jeremy/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:337:in `configure_connection_for_https'
from /Users/jeremy/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:323:in `connection_for'
from /Users/jeremy/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems/remote_fetcher.rb:402:in `request'
@jemmyw
jemmyw / setup-statsd.sh
Created April 4, 2012 12:50 — forked from rw/setup-statsd.sh
Turn an Ubuntu 11.10 EC2 into a StatsD/Graphite server
set -e
# install git
sudo apt-get -y install g++ curl libssl-dev apache2-utils git-core nodejs
# install other graphite dependencies
sudo apt-get -y install python-cairo python-django memcached python-memcache install python-ldap python-twisted apache2 libapache2-mod-python libapache2-mod-wsgi python-django-tagging
# install the Node package manager for later use
curl http://npmjs.org/install.sh | sudo sh