Skip to content

Instantly share code, notes, and snippets.

View gist:ff8292ba1966c7bfd3c93f8d7fe5dede
enum OrderEvent {
OrderPlaced(OrderPlacedPayload)
}
struct OrderPlacedPayload {
name: String,
whatever: String
}
mod event_formats {
@obmarg
obmarg / GeoSuggest.elm
Last active May 25, 2017
Embedding react-geosuggest in Elm
View GeoSuggest.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 Sep 8, 2016
Circle.yml snippet for building libsysconfcpus to speed up elm builds
View circle.yml
## 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 Feb 8, 2016
Reading /proc/loadavg in elixir using with statements.
View system_metrics.ex
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 Aug 4, 2015
A naive dictionary based tokenizer in clojure
View tokenizer.clj
(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 Jul 13, 2015
Sqlitex Stored Statement vs Query
View write_many_bench.ex
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
View 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 Jan 4, 2017
Google app engine python issue #7746 workaround
View gae_workaround.py
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 Jan 2, 2016 — forked from honza/get.py
View 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):