This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MigrationRunner do | |
use GenServer.Behaviour | |
@server_name :migration_runner | |
@full_name {:local, @server_name} | |
def start_link do | |
:gen_server.start_link(@full_name, __MODULE__, nil, []) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AttributeKeyWriter | |
extend ActiveSupport::Concern | |
module ClassMethods | |
protected | |
# Allow writing an attribute by key/code | |
# | |
# Example: | |
# belongs_to :currency | |
# attr_key_writer(:currency, key: "code") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
White Noise Generator | |
http://en.wikipedia.org/wiki/White_noise | |
Generates a .wav file with random noise. | |
Copy to phone, and run on loop. | |
`gem install wavefile` | |
=end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" put this .vimrc in your project's root folder | |
" type ,t to run all tests | |
map <Leader>t :!mix test<CR> | |
" type ,e to run current test | |
map <Leader>e :!mix test %<CR> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# | |
# iex> CreditCard.type(%{number: "4242424242424242"}) | |
# => :visa | |
defmodule CreditCard do | |
defstruct [:number, :expiration, :cvc] | |
# find the type of a credit card | |
# attempt map for first character, first 2 characters, etc (up to 4 characters) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# XML Builder - inspired by jimweirich's ruby builder | |
defmodule Builder do | |
def xml(elements) when is_list(elements), | |
do: Enum.map_join(elements, &xml/1) | |
def xml(element_name) when is_atom(element_name) or is_bitstring(element_name), | |
do: xml({element_name}) | |
def xml({element_name}), | |
do: "<#{element_name}/>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# defines a generic proxy | |
defmodule GenProxy do | |
defmacro __using__(_) do | |
quote location: :keep do | |
use GenServer | |
def handle_call(msg, from={_process, ref}, state) do | |
case proxy_call(msg, from, state) do | |
{:forward, server, new_state} -> | |
:erlang.send(server, {:"$gen_call", {self, ref}, msg}, [:noconnect]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Enum2 do | |
import Enum | |
def sample(collection), | |
do: hd(sample(collection, 1)) | |
# http://en.wikipedia.org/wiki/Reservoir_sampling | |
def sample(collection, count) do | |
results = take(collection, count) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example Angular.js form built with components (kind of like formtastic) | |
// `field`: supports text, number, email, checkbox, select, textarea, etc.. | |
// generates label and appropriate field type, withcheckmark/error icon when field is valid/invalid | |
.well | |
h1 Contact | |
super-form(name="contactForm" submit="send()") | |
field(model="message.email" type="email" required autofocus) | |
field(model="message.name" type="text" required) | |
field(model="message.topic" type="select" required options="topic as topic for topic in topics") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('Foo').controller 'ExampleCtrl', ($scope, Flash) -> | |
$scope.doSomething = -> | |
Flash.info "Hello There!" |