Skip to content

Instantly share code, notes, and snippets.

@khia
khia / .bash_profile
Created May 18, 2018 10:58
How to run TW5 on andriod
cat data/data/com.termux/files/home/.bash_profile
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
export SVDIR="$HOME/etc/sv"
mkdir -p $PREFIX/var/run
mkdir -p ~/.log
daemonize -c $PREFIX -l $PREFIX/var/run/runsvdir.lock -p $PREFIX/var/run/runsvdir.pid $PREFIX/bin/applets/runsvdir $SVDIR 2>/dev/null||:
@khia
khia / Caddyfile
Last active August 6, 2019 11:55
Tiddlywiki with Bob on android
cat etc/Caddyfile
# entrypoint for accessing from PC
phone.local:8080 {
tls /data/data/com.termux/files/home/etc/phone.crt /data/data/com.termux/files/home/etc/phone.key
basicauth /wiki "username" password
proxy /wiki 127.0.0.1:8090 {
websocket
}
}
# entrypoint for accessing locally from phone
cat priv/spec/db.yml
swagger: '2.0'
info:
title: CouchDB API
description: CouchDB API to define bindings
version: "2.0"
# the domain of the service
host: couchdb.org
# array of all schemes that your API supports
schemes:
@khia
khia / README.txt
Created November 20, 2013 00:17
mix compile macro from different app
$ mix
==> common
Compiled lib/classes.ex
Generated common.app
==> macro
Compiled lib/method.ex
Generated macro.app
$ touch apps/common/lib/classes.ex
$ mix
==> common
def project do
your_options = []
[
...
elixirc_options: your_options ++ options(Mix.env)
]
end
defp options(env) when env in [:dev, :test] do
[exlager_level: 7]
@khia
khia / dsl.exs
Last active December 12, 2015 07:59
Demo of simple DSL
#!/usr/bin/env elixir
defmodule DSL do
defmacro action(match, [do: body]) do
quote do
def handle_info(unquote(match) = arg, state) do
unquote(body)
{:ok, state}
end
end
end
'/Users/some_user/dev/myproject/apps/myapp/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/gen_leader/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/edown/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/gproc/ebin',
'/Users/some_user/dev/myproject/apps/myapp/deps/genx/ebin',
'.',
'/usr/local/dev/erlang/R15B02/lib/erlang/lib/kernel-2.15.2/ebin',
'/usr/local/dev/erlang/R15B02/lib/erlang/lib/stdlib-1.18.2/ebin',
'/Users/some_user/dev/myproject/deps/elixir/bin/../lib/mix/ebin',
'/Users/some_user/dev/myproject/deps/elixir/bin/../lib/iex/ebin',
delegate [
capabilities(_self),
delete(_self),
url(_self), url(url, _self),
forward(_self), back(_self),
],
to: :htse_session, with: _pid
defmacrop _pid(args) do
[_self|rest] = Enum.reverse(args)
session_pid = quote do: unquote(_self).session_pid
element = quote do: unquote(_self).element
[session_pid,element|Enum.reverse(rest)]
end
delegate [element(strategy, value, _self)],
to: :htse_session, as: :element_element, with: _pid
```
Performance:
| asymptotic | length |
| | 10 | 100 | 1000 | 10000 |
| |min med max avg|min med max avg|min med max avg|min med max avg|
cons | | 0, 0, 537, 0 | 0, 0, 572, 0 | 0, 0, 223, 0 | 0, 0, 431, 0 |
drop | | 0, 0, 204, 0 | 0, 1, 356, 1 | 1, 1, 204, 1 | 1, 1, 450, 2 |
drop_tail | | 2, 3, 393, 3 | 1, 2, 588, 2 |294,302,501,306|2627,2768,9390,2812|
drop_tail_r| | 1, 2, 588, 2 | 16,17,404,17 |156,165,385,167|1364,1486,3650,1498|
from_list_r| | 0, 1, 405, 1 | 9,10,519,10 |112,114,879,116| 996,1037,3104,1060|