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 / gist:6401386
Last active December 22, 2015 02:08
Sample for Firebase access on Elixir
defmodule Sample do
def test do
# acquire your Firebase URL (https://xxx.firebaseio.com/)
# from the environment variable.
url = String.from_char_list!(:os.getenv("FIREBASE_URL"))
# setup url for ExFirebase module
ExFirebase.set_url(url)
# put data in /test path"
@parroty
parroty / gist:6405497
Last active December 22, 2015 02:48
Fibonacci number
defmodule Sequence do
def fib(0), do: 1
def fib(1), do: 1
def fib(n), do: fib(n - 1) + fib(n - 2)
end
IO.puts Sequence.fib(10) # -> 89
@parroty
parroty / application_router.ex
Last active December 23, 2015 14:49
Sample for Dynamo and REST API.
defmodule ApplicationRouter do
use Dynamo.Router
filter DynamoScaffold.Filters.MethodOverride
prepare do
conn = conn.fetch([:cookies, :params])
conn.assign :layout, "main"
end
@doc "index"
@parroty
parroty / application_router.ex
Last active December 23, 2015 17:59
Sample for Dynamo and exfireabse.
defmodule ApplicationRouter do
use Dynamo.Router
filter Dynamo.Filters.MethodOverride
prepare do
conn = conn.fetch([:cookies, :params])
conn.assign :layout, "main"
end
@doc "index"
@parroty
parroty / gist:6765617
Last active December 24, 2015 07:40
ExVCR example
defmodule ExVCR.MockTest do
use ExUnit.Case
import ExVCR.Mock
setup_all do
ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes",
"fixture/custom_cassettes")
:ok
end
@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])
@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
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 / 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
Git clone https://github.com/parroty/exfirebase
cd exfirebase
mix deps.get
iex -S mix