Skip to content

Instantly share code, notes, and snippets.

View obmarg's full-sized avatar

Graeme Coupar obmarg

  • London
  • 18:32 (UTC)
View GitHub Profile
enum OrderEvent {
OrderPlaced(OrderPlacedPayload)
}
struct OrderPlacedPayload {
name: String,
whatever: String
}
mod event_formats {
@obmarg
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
obmarg / circle.yml
Created September 8, 2016 14:44
Circle.yml snippet for building libsysconfcpus to speed up elm builds
## Customize dependencies..
dependencies:
cache_directories:
- "libsysconfcpus"
post:
# Build sysconfcpus to workaround elm issue.
- if [ ! -d libsysconfcpus ]; then git clone https://github.com/obmarg/libsysconfcpus.git; fi
- cd libsysconfcpus && ./configure && make && sudo make install
@obmarg
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
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
[words]
"Builds a dict-tree from a list of words."
@obmarg
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} = Sqlitex.open(":memory:")
Sqlitex.query(db, "CREATE table x(a INTEGER PRIMARY KEY, b);")
Enum.map 1..1000, fn (i) ->
Sqlitex.query(db, "INSERT INTO x (b) VALUES (?1);", bind: [i])
end
end
@obmarg
obmarg / README.md
Last active August 29, 2015 14:18 — forked from joakimk/README.md

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.

@obmarg
obmarg / gae_workaround.py
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
obmarg / get.py
Last active January 2, 2016 20:59 — forked from honza/get.py
"""
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):
try:
return reduce(operator.getitem, keys, obj)
except (KeyError, IndexError):