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
# http://is.gd/NzZxYT | |
defmodule BinaryTree do | |
def invert([n, list]) when is_integer(n) and is_list(list) do | |
[n, invert(list)] | |
end | |
def invert([n, nc, m, mc]) | |
when is_integer(n) and is_integer(m) | |
and is_list(nc) and is_list(mc) do |
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
# elixir | |
defmodule Example do | |
def work(_msg) do | |
IO.puts "called 1st function" | |
end | |
def work(_msg, data=[_a, _b, _c]) do | |
IO.puts "called 2nd function #{inspect data}" | |
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
require 'httparty' | |
require 'redis' | |
require 'json' | |
require 'timeout' | |
$publisher = Redis.new | |
$subscriber = Redis.new | |
CHANNEL = 'omg' |
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
curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_CREDENTIALS_HERE", "doc":{"name":"kitabu.pdf", "document_type":"pdf", "test":"false", "document_url":"https://dl.dropboxusercontent.com/u/123456789/output/kitabu.pdf.html"}}' http://docraptor.com/docs > kitabu.pdf |
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
;; letrec practice | |
;; fold | |
;; map | |
;; filter | |
;; mapcat | |
(define (fold fold-f acc l) | |
(letrec | |
((FOLD (lambda (acc l) | |
(cond |
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 Ring do | |
def node(name, next_pid) do | |
receive do | |
1 -> | |
send next_pid, 1 | |
n when is_number(n) -> | |
send next_pid, n | |
node(name, next_pid) | |
end | |
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
% Andrea Leopardi's list parser | |
% http://andrealeopardi.com/posts/tokenizing-and-parsing-in-elixir-using-leex-and-yecc/ | |
Nonterminals list elems elem. | |
Terminals '[' ']' ',' int atom. | |
Rootsymbol list. | |
list -> | |
'[' ']' : []. | |
list -> |
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 MyList do | |
# version 1: continuation passing style | |
def flatten(l), do: flatten(l, fn (result) -> result end) | |
def flatten([], col), do: col.([]) | |
def flatten([h|t], col) when not is_list(h) do | |
flatten(t, fn (acc) -> col.([h | acc]) end) | |
end | |
def flatten([h|t], col) do | |
col.( |
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
def daemonize_app | |
if RUBY_VERSION < "1.9" | |
exit if fork # jettison the terminal | |
Process.setsid # establish a new group & session leader (can only be done as a child process) | |
exit if fork # jettison the group leader. now it can't be interrupted from another group or session going down. | |
Dir.chdir "/" # change dir to root to make sure that the dir won't go away during the process run | |
# as a demon we won't be needing these... | |
STDIN.reopen "/dev/null" | |
STDOUT.reopen "/dev/null", 'a' |
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
(define y2 | |
(lambda (c) | |
((lambda (h) | |
(h h)) | |
(lambda (f) | |
(c (lambda (x y) | |
((f f) x y))))))) | |
(define make-rember | |
(y2 (lambda (f) |