Skip to content

Instantly share code, notes, and snippets.

@dry
dry / dispatcher.erl
Created December 2, 2012 14:11
Simple URL dispatcher for Mochiweb
-module(dispatcher).
-export([dispatch/2]).
dispatch(_, []) -> none;
dispatch(Req, [{Regexp, Handler}|T]) ->
"/" ++ Path = Req:get(path),
Method = Req:get(method),
Match = re:run(Path, Regexp, [global, {capture, all_but_first, list}]),
case Match of
{match, [MatchList]} ->
@dry
dry / date_util.erl
Created December 20, 2012 21:15 — forked from zaphar/date_util.erl
-module(date_util).
-compile(export_all).
epoch() ->
now_to_seconds(now())
.
epoch_hires() ->
now_to_seconds_hires(now())
.
@dry
dry / sample output
Last active December 11, 2015 16:19 — forked from josevalim/sample output
defmodule Chat.Client do
# In all of the following functions 'server' stands for the server's pid
def join({server, name}) do
send server, {name, :join, ""}
end
def say({server, name, message}) do
send server, {name, :say, message}
end
@dry
dry / json.ex
Created February 4, 2013 22:04
A Jiffy (https://github.com/davisp/jiffy) wrapper for Elixir
defmodule JSON do
@moduledoc """
This module is a wrapper for the Jiffy JSON library.
## Examples
JSON.encode({[{foo: bar, count: 1}]})
JSON.encode({[{"foo": "bar", "count": 1}]})
JSON.decode("\\"foo\\": \\"bar\\", \\"count\\": 1}]})
# Set Vi Mode
setw -g mode-keys vi
# Reload Config
bind-key R source-file "$HOME/.tmux_conf"\; display-message "Configuration Reloaded"
# Option+Arrow
bind-key -n M-Left previous-window
bind-key -n M-Right next-window
@dry
dry / gist:6007806
Created July 16, 2013 11:09
Emacs dired quick access key map
(define-key evil-normal-state-map ",f" (lambda ()
(interactive)
(dired default-directory)
))
@dry
dry / gist:6144045
Created August 2, 2013 22:40
Erlang - extract beam function attributes.
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_code]).
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
@dry
dry / gist:6636840
Last active December 23, 2015 12:39
Remove show message redirect from Cookie Consent module
<?php
// ... rest of module stuff
/**
* Set the 'cookies_allowed' cookie
*
* @access public
* @return string
*
@dry
dry / update
Created October 9, 2013 22:32
Update all git repositories in a directory
#!/usr/bin/env escript
%%! -smp enable -sname update
main([Path]) ->
SPath = string:strip(Path, right, $/),
{ok, Dirs} = file:list_dir(SPath),
[files(SPath ++ "/" ++ Dir) || Dir <- Dirs];
main(_) ->
io:format("Usage: update [path/to/directory]~n").
@dry
dry / .bashenv
Last active September 7, 2016 16:00
Set/unset per directory environment variables for development projects
SHOPIFY_CLIENT_ID "123456789"