Skip to content

Instantly share code, notes, and snippets.

View cromwellryan's full-sized avatar

Ryan Cromwell cromwellryan

View GitHub Profile
@cromwellryan
cromwellryan / Guardfile
Last active December 19, 2015 22:08
Triangle kata in elixir with some parallel map awesomeness
# gem install guard
# gem install guard-shell
# guard - watch the Magic™
guard 'shell', :elixirc_bin => "/usr/local/elixirc" do
watch(/(.+\.ex$)/) { |m| `elixirc #{m[0]}` }
end
guard 'shell', :elixir_bin => "/usr/local/elixir" do
watch(/(.+\.exs)/) { |m| `elixir #{m[0]}` }
end
defmodule Movies do
defp to_lines(file), do: String.split file, "\n"
defp to_movies(line) when is_bitstring(line), do: list_to_tuple String.split line, "\t"
defp to_movies([head|tail]), do: [ to_movies(head) | to_movies(tail) ]
defp to_movies([]), do: []
def from(path) do
# probably use IO module with File.open if we had a large set
614692 9.2 The Shawshank Redemption 1994
550111 8.9 The Dark Knight 2008
486716 9 Pulp Fiction 1994
471441 9.2 The Godfather 1972
454455 8.8 Fight Club 1999
448117 8.8 The Lord of the Rings: The Fellowship of the Ring 2001
444980 8.7 The Matrix 1999
425515 8.8 The Lord of the Rings: The Return of the King 2003
380364 8.7 The Lord of the Rings: The Two Towers 2002
378917 8.9 Inception 2010
@cromwellryan
cromwellryan / discover.ps1
Last active December 20, 2015 17:29
Looks for deployable project types in a C# filled directory
function Get-Projects($Path = ($pwd.path)) {
ls -path $path -filter *.csproj -recurse
}
function ConvertTo-Deployable {
begin {}
process {
$Path = $_
$project = New-Object psobject -Property @{
@cromwellryan
cromwellryan / error
Created August 9, 2013 03:10
lc doesn't work with range from to_list. elixir 0.10.1
** (ArithmeticError) bad argument in arithmetic expression
/Users/cromwellryan/projects/elixir/a.exs:7: :elixir_compiler_0."-__FILE__/2-lc$^1/1-1-"/1
/Users/cromwellryan/projects/elixir/a.exs:7: (file)
/private/tmp/elixir-QNLB/elixir-0.10.1/lib/elixir/lib/code.ex:291: Code.require_file/2
/private/tmp/elixir-QNLB/elixir-0.10.1/lib/elixir/lib/kernel/cli.ex:299: Kernel.CLI.process_command/2
/private/tmp/elixir-QNLB/elixir-0.10.1/lib/elixir/lib/enum.ex:594: Enum."-map/2-lc$^0/1-0-"/2
@cromwellryan
cromwellryan / parser.ex
Last active March 29, 2016 19:12
JSON Parser in Elixir
defmodule JSON do
import String
def parse( content ) do
case parse_content(content) do
{ value, "" } -> value
{ _, _ } -> raise "crap"
end
end
@cromwellryan
cromwellryan / ab.rb
Last active December 22, 2015 02:09
apache bench 2.4.6 brew formula
require 'formula'
class Ab < Formula
homepage 'http://httpd.apache.org/docs/trunk/programs/ab.html'
url 'http://www.apache.org/dist/httpd/httpd-2.4.6.tar.bz2'
sha1 '16d8ec72535ded65d035122b0d944b0e64eaa2a2'
def patches
{
# Disable requirement for PCRE, because "ab" does not use it
@cromwellryan
cromwellryan / index.js
Created October 11, 2013 12:31
composable promises from args (ie requirejs dependencies)
var Q = require('q');
console.log();
function hi() {
Q.promise( function() {
console.log("hi: " + Date());
});
}

Sparkboxers on Twitter

You'll need the t gem

./add-all.sh

Simple observer, event mechanism for isolating growing business actions.