Skip to content

Instantly share code, notes, and snippets.

View parroty's full-sized avatar
🏠
Working from home

Kenta Nakase parroty

🏠
Working from home
View GitHub Profile
@parroty
parroty / .tool-versions
Created December 30, 2015 08:48
Elixir build example at CircleCI
erlang 18.0
elixir 1.1.1
defmodule XmlParser do
require Record
Record.defrecord :xmlElement, Record.extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl")
Record.defrecord :xmlText, Record.extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl")
@xml """
<result>
<event>
<title>My event</title>
@parroty
parroty / dummy
Last active October 11, 2015 06:52
dummy
@parroty
parroty / gist:98a68f2e8a735434bd60
Created February 24, 2015 23:23
Macro wrapper for fetching default value of map
defmodule Fetcher do
def db_value_for(key) do
IO.puts "processing..."
"db value for #{key}"
end
defmacro get(map, key, default \\ nil) do
quote do
case Map.get(unquote(map), unquote(key)) do
nil -> unquote(default)
@parroty
parroty / fib.hs
Created December 29, 2014 14:54
Fibonacci on Haskell
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
let n = read $ head args :: Int
putStrLn . show $ fib n
fib :: Int -> Integer
fib 0 = 0
Git clone https://github.com/parroty/exfirebase
cd exfirebase
mix deps.get
iex -S mix
@parroty
parroty / circle.yml
Last active February 12, 2016 17:54
CircleCI sample
dependencies:
pre:
- bash ./install-otp_src_17.0.sh
- bash ./install-elixir.sh
cache_directories:
- otp_src_17.0
- elixir
test:
pre:
- ln -s ~/circle_sample/otp_src_17.0/bin/erl ~/bin/erl
defmodule ExFuture.HelperTest do
use ExUnit.Case
use ExFuture
test "future block" do
f = future do
3 * 3
end
assert 9 == value(f)
end
@parroty
parroty / gist:7970215
Created December 15, 2013 08:00
Parallel map using future
defmodule SampleFuture do
require Future
def fib(0), do: 0
def fib(1), do: 1
def fib(n), do: fib(n - 1) + fib(n - 2)
defmacro benchmark([do: content]) do
quote do
s = :erlang.now
@parroty
parroty / quick.ex
Created October 27, 2013 13:23
Elixir QuickSort
defmodule QuickSort do
def sort([]), do: []
def sort([head|tail]) do
{lesser, greater} = Enum.partition(tail, &(&1 < head))
sort(lesser) ++ [head] ++ sort(greater)
end
end
IO.inspect QuickSort.sort([1,6,3,4,2,5])