Skip to content

Instantly share code, notes, and snippets.

View alco's full-sized avatar
🇺🇦

Oleksii Sholik alco

🇺🇦
View GitHub Profile
@alco
alco / dave.exs
Last active August 29, 2015 14:08
defmodule Returning do
defmacro returning(val, do_block) do
quote do
val = unquote(val)
case val, unquote(do_block)
val
end
end
end
λ brew reinstall postgres
==> Reinstalling postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.3.5/postgresql-9.3.5.tar.bz2
Already downloaded: /Library/Caches/Homebrew/postgresql-9.3.5.tar.bz2
==> Patching
patching file contrib/uuid-ossp/uuid-ossp.c
==> ./configure --prefix=/usr/local/Cellar/postgresql/9.3.5_1 --datadir=/usr/local/Cellar/postgresql/9.3.5_1/share/postgresql --docdir=/usr/local/Cellar/postgresql/9.3
checking for POSIX signal interface... yes
checking for working memcmp... yes
checking for tclsh... /usr/bin/tclsh
defmodule M do
def test do
cond do
length([1,2,3]) == 0 -> false
true
"oops, I forgot the arrow"
end
end
end
defmodule Compositions do
# "Call" composition
#
# f = Enum.map(& &1+1) ||| Enum.reverse
#
# f.([1,2,3]) #=> [4, 3, 2]
#
# g = f.() ||| List.to_tuple
#
# g.([1,2,3]) #=> {4, 3, 2}
def gen_module(file, rest_body) do
# load things from the file here and assign them to variables
Module.create(<name>, quote bind_quoted: [rest_body: rest_body, var1: var1, ...] do
# now unquote() can be called here freely, it will be deferred until module compilation
# therefore, you can copy-paste your previous in-line code without the file loading part
def unquote(...)(...) do
unquote(...)
end
...
data_path = Path.expand(Path.join(__DIR__, "../../priv/address.json"))
json = File.read!(data_path) |> JSEX.decode!
Enum.each json, fn(el) ->
{lang, data} = el
Enum.each data, fn
{"values", values} ->
Enum.each values, fn({fun, list}) ->
@get_fn String.to_atom("get_#{fun}")
@count_fn String.to_atom("#{fun}_count")
@lang String.to_atom(lang)
(pprof) top10
Total: 2525 samples
298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64
268 10.6% 22.4% 2124 84.1% main.FindLoops
251 9.9% 32.4% 451 17.9% scanblock
178 7.0% 39.4% 351 13.9% hash_insert
131 5.2% 44.6% 158 6.3% sweepspan
119 4.7% 49.3% 350 13.9% main.DFS
96 3.8% 53.1% 98 3.9% flushptrbuf
95 3.8% 56.9% 95 3.8% runtime.aeshash64
# Numbers
0b0101011
1234 ; 0x1A ; 0xbeef ; 0763 ; 0o123
3.14 ; 5.0e21 ; 0.5e-12
100_000_000
# Atoms
:this ; :that
:'complex atom'
:... ; :<<>> ; :%{} ; :% ; :{}
λ cat ~/.tmux.conf
# Don't use login shell in tmux
set -g default-command /bin/zsh
# Change default prefix to Ctrl-q
unbind C-b
set -g prefix C-q
# Pane switching with Alt-<arrow> keys
bind -n M-Left select-pane -L
iex(1)> Mix.SCM.Git.checkout git: "https://github.com/alco/mix-elixir-template.git", dest: "templatio"
** (exit) exited in: :gen_server.call(Mix.ProjectStack, {:get_and_update, #Function<5.113990582/1 in Mix.ProjectStack.printable_app_name/0>}, 30000)
** (EXIT) no process