Skip to content

Instantly share code, notes, and snippets.

@lmarlow
lmarlow / macro_v_runtime_bench.exs
Last active May 3, 2017 20:09
Elixir Macro vs. Runtime check
defmodule MyMacro do
defmacro def_match(pattern) do
quote do
def macro_pattern_match(unquote(pattern)), do: unquote(Macro.var(:matched, nil))
def macro_pattern_match(_), do: :error
end
end
end
defmodule MacroVRuntimBench do
@lmarlow
lmarlow / chunky_flow.exs
Last active December 13, 2016 17:58
Chunky flow
alias Experimental.Flow
defmodule Chunky do
@moduledoc ~S"""
A chunky stream produces documents, each with a list of items in it.
The default settings will produce documents with a few thousand items
for a bit and then fall back to trickling in items every few seconds.
This simulates catching up to some external paged feed.
"""
@lmarlow
lmarlow / keybase.md
Created March 15, 2014 21:08
Keybase proof

Keybase proof

I hereby claim:

  • I am lmarlow on github.
  • I am lmarlow (https://keybase.io/lmarlow) on keybase.
  • I have a public key whose fingerprint is E5CC FFBD FAB3 82A6 3522 E7DA 8579 B5D8 C046 C07F

To claim this, I am signing this object:

@lmarlow
lmarlow / git-recent
Created November 6, 2013 20:30
Prints the branches with the most recent commits
#!/bin/bash
#############################################################################
usage () {
printf "%s" "\
usage: git recent [-r remote] [count]
Prints the branches with the most recent commits.
options:
@lmarlow
lmarlow / config.ru
Last active December 26, 2015 18:59 — forked from thinkerbot/config.ru
# [config.ru]
#
# puma
# curl http://localhost:9292/
#
# Note chrome buffers like 1024 or so... meaning the first lots will look missing.
use Rack::Chunked
run lambda { |env|
# simple timing without blocks
@@last_tick, @@last_line = Time.now.to_f, 0
def tick(new_line)
last_tick, last_line, new_tick = @@last_tick, @@last_line, Time.now.to_f
if last_line > 0
puts "Line#{new_line - last_line > 2 ? %Q(s #{last_line + 1}-#{new_line - 1}) : %Q( #{new_line - 1})} took #{'%0.3f' % (new_tick - last_tick)}s"
else
puts "Line #{new_line} executing #{'%0.3f' % (new_tick - last_tick)}s after tick defined"
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>bundleUUID</key>
<string>5A9D4FC6-6CBE-11D9-A21B-000D93589AF6</string>
<key>command</key>
<string>#!/usr/bin/env ruby -rcgi
@lmarlow
lmarlow / date_formats.rake
Created July 22, 2008 22:53
Show available format strings for Date, DateTime, and Time objects in Rails
desc "Show the date/time format strings defined and example output"
task :date_formats => :environment do
now = Time.now
[:to_date, :to_datetime, :to_time].each do |conv_meth|
obj = now.send(conv_meth)
puts obj.class.name
puts "=" * obj.class.name.length
name_and_fmts = obj.class::DATE_FORMATS.map { |k, v| [k, %Q('#{String === v ? v : '&proc'}')] }
max_name_size = name_and_fmts.map { |k, _| k.to_s.length }.max + 2
max_fmt_size = name_and_fmts.map { |_, v| v.length }.max + 1