Skip to content

Instantly share code, notes, and snippets.

@rylev
rylev / stark_params.rb
Created March 11, 2014 14:49
Strong Parameters Wrapper
def TasksController
def index
Task.where(index_params)
end
def create
Task.create!(create_params)
end
private
@rylev
rylev / calc.hs
Created February 24, 2014 11:53
Simple and Incredibly Naive Calculator
module Main where
import System.Environment
import Text.ParserCombinators.Parsec
import Control.Monad
import Data.Char
main :: IO ()
main = do putStrLn "What would you like to calculate:"
input <- getLine
putStrLn $ readExpr input
@rylev
rylev / gist:7725524
Created November 30, 2013 22:40
Binary Addition with logic gates
class Array
def second
self[1]
end
end
class Integer
def one?
raise "Not Binary" unless self == 1 || self == 0
self == 1
end
@rylev
rylev / plan.md
Last active December 25, 2015 17:39
Plan proposal for the next Elixir Users Group.

Intro to FP and Elixir

##Targeted Audience

The targeted audience are both beginners to functional programming who have experience in programming with at least one imperative style language. The content may also be appealing to those who have programmed in other functional programming languages (e.g. Haskell, Clojure, F#, etc.) or even Erlang programmers, but the content will not be specifically geared towards them.

@rylev
rylev / sort.ex
Created October 9, 2013 19:07
Sort Algorithms in Elixir
## Sort Algorithms in Elixir
# Selection Sort
defmodule Selection do
def sort(list) when is_list(list) do
do_selection(list, [])
end
def do_selection([head|[]], acc) do
@rylev
rylev / gist:6685033
Created September 24, 2013 13:49
Enforcing arity like a boss
def foo(args)
raise ArgumentError unless args.count == 2 && args.keys.include? :bar
# your code goes here
end
@rylev
rylev / dot_strings_parser.rb
Created November 12, 2012 18:09
A simple ruby class that parses .strings files (used in OSX and iOS for translations) and coverts it to a Ruby hash.
class DotStringsParser
REGEX_QUOTED = /\"((\\\"|[^\"])+)\"/
REGEX_KEY_VALUE = /#{REGEX_QUOTED}\s*=\s*#{REGEX_QUOTED}/
def initialize
@hash = {}
end
def convert_to_array(line)