Skip to content

Instantly share code, notes, and snippets.

View obmarg's full-sized avatar

Graeme Coupar obmarg

  • London
  • 15:43 (UTC +01:00)
View GitHub Profile
enum OrderEvent {
struct OrderPlacedPayload {
name: String,
whatever: String
mod event_formats {
obmarg / tokenizer.clj
Created August 4, 2015 13:36
A naive dictionary based tokenizer in clojure
(ns tokenizer.core)
(defn insert-word
[dict word]
"Inserts a single word into a dictionary tree"
(update-in dict (concat (interpose :children word) [:word]) (fn [orig] word)))
(defn build-dict-tree
"Builds a dict-tree from a list of words."
obmarg / GeoSuggest.elm
Last active May 25, 2017 13:37
Embedding react-geosuggest in Elm
module GeoSuggest exposing (geosuggest, onChange)
import Json.Decode
import Html exposing (Html, node)
import Html.Events exposing (on)
onChange : (String -> msg) -> Html.Attribute msg
onChange handler =
on "change" <|
obmarg /
Last active January 4, 2017 08:27
Google app engine python issue #7746 workaround
from toolz import concat
def page_iterator(query, page_size=999, **kwargs):
Returns an iterator over pages of a query.
Can be used to work-around the 1000 entity limit in remote_api_shell
:params query: The query we're using.
:params page_size: The page size to return.
:params qwargs: Additional options for fetch_page
obmarg / circle.yml
Created September 8, 2016 14:44
Circle.yml snippet for building libsysconfcpus to speed up elm builds
## Customize dependencies..
- "libsysconfcpus"
# Build sysconfcpus to workaround elm issue.
- if [ ! -d libsysconfcpus ]; then git clone; fi
- cd libsysconfcpus && ./configure && make && sudo make install
obmarg / system_metrics.ex
Created February 8, 2016 12:56
Reading /proc/loadavg in elixir using with statements.
defmodule SystemMetrics do
# Gets the load average.
def loadavg do
res =
with {:ok, data} <- read_file("/proc/loadavg"),
[one, five, fifteen | _] <- String.split(data, " "),
{one, ""} <- Float.parse(one),
{five, ""} <- Float.parse(five),
{fifteen, ""} <- Float.parse(fifteen),
do: ["1": one, "5": five, "15": fifteen]
obmarg /
Last active January 2, 2016 20:59 — forked from honza/
Clojure-inspired ``get_in`` function which gets value from nested dicts,
returning ``None`` if a key is not found.
import operator
def get_in(obj, *keys):
return reduce(operator.getitem, keys, obj)
except (KeyError, IndexError):
obmarg / write_many_bench.ex
Created July 13, 2015 23:12
Sqlitex Stored Statement vs Query
defmodule WriteManyBench do
use Benchfella
bench "write many with query" do
{:ok, db} =":memory:")
Sqlitex.query(db, "CREATE table x(a INTEGER PRIMARY KEY, b);") 1..1000, fn (i) ->
Sqlitex.query(db, "INSERT INTO x (b) VALUES (?1);", bind: [i])
obmarg /
Last active August 29, 2015 14:18 — forked from joakimk/

This runs a build for a small elixir (phoenix) project in about 40 seconds by caching as much of the compiled files as possible. It's not been run for very long so I don't know if it caches too much or of there is any other issues.

It should be generic enough to work on any elixir app using mix.