Skip to content

Instantly share code, notes, and snippets.

@khia
khia / Caddyfile
Last active Aug 6, 2019
Tiddlywiki with Bob on android
View Caddyfile
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
@khia
khia / .bash_profile
Created May 18, 2018
How to run TW5 on andriod
View .bash_profile
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||:
View gist:9441b0be8f8ccd8328517230c81347b3
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:
View gist:1106f6bed847cee96340
defmodule Instrument do
@zero :decimal_conv.number("0")
@struct symbol: nil, name: "", value: @zero
defstruct @struct
@keys Enum.sort(@struct |> Map.keys |> List.delete(:__struct__))
for k <- @keys do
def __atomize__({unquote(Atom.to_string(k)), v}, acc) do
Dict.put(acc, unquote(k), v)
end
def __atomize__({unquote(k), v}, acc) do
View gist:656532d41ce1332f471b
def benchmark(f, args \\ [], min_duration \\ @default_duration)
def benchmark(f, args, min_duration) when is_list(f) and is_list(args) do
Enum.map(f, fn(fp) -> benchmark(fp, args, min_duration) end)
end
def benchmark(f, args, min_duration) when is_function(f) do
IO.inspect fp
results = do_benchmark(fp, args, min_duration)
IO.puts results
results
end
View gist:606c51e2c4123f2d87ef
defmodule Test do
defstruct foo: nil, bar: nil
for x <- @keys do # <-------------------------- HOW ????
def parse(unquote(x)), do: something(x)
def parse(unquote(Atom.to_string(x))), do: something(x)
end
end
View apps_bexng_mix.exs
cat apps/bexng/mix.exs
defmodule Bexng.Mixfile do
use Bexng.Project
def project do
[ app: :bexng,
version: "0.0.1",
elixir: ">= 0.14.3-dev",
deps: deps ]
end
@khia
khia / README.txt
Created Nov 20, 2013
mix compile macro from different app
View README.txt
$ 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
View gist:5398228
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 Dec 12, 2015
Demo of simple DSL
View dsl.exs
#!/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
You can’t perform that action at this time.