Skip to content

Instantly share code, notes, and snippets.

app="myapp"
function gen-ups {
rebar generate-appups previous_release=$1
cat $app/lib/*/ebin/*.appup
}
# This uses a dirty bunch of hacks to "generate" downgrade instructions
# (upgrade instructions in the opposite direction) with the current rebar
# version.
@amtal
amtal / now_skew.erl
Created May 20, 2011 00:55
Playing with now()'s clock skew effect at high call rates.
-module(now_skew).
-compile(export_all).
go() ->
A = os:timestamp(),
NA = now(),
Master = self(),
spawn(fun()->loop(1000000), Master!done end),
%spawn(fun()->loop(500000), Master!done end),
receive done->ok end,
@amtal
amtal / life_sync_cell.lfe.clj
Created May 30, 2011 10:08
Conway's Life in Lisp Flavored Erlang...
;;; Global clock implementation of Life.
(defmodule life_sync_cell
(export (start_link 1) (set_neighbours 2) (tick 1)
(init 1) (handle_cast 2))
(using gen_server)
(behaviour gen_server))
(include-file "deps/lfe_utils/include/using.lfe")
;;; Exported:
@amtal
amtal / how2doit.cpp
Created May 30, 2011 13:54
This is how you do it.
/* TOMMY's CONNECT 4 PROGRAM */
#include <iostream>
using namespace std;
char cBlock[] = {178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178,178};
int choice;
char block = 178;
bool bGameover = false;
char iPlayerTurn = 'X';
bool bPlayerTurn = true;
@amtal
amtal / CheckRev.hs
Created June 10, 2011 08:12
Untested and unsanitary implementation of CheckRevision algorithm
module Main where
import Data.Word
import Data.Int
import Text.Parsec
import Control.Monad
import Control.Applicative hiding ((<|>),many)
import qualified Data.ByteString.Lazy as S
import Data.ByteString.Lazy (ByteString)
@amtal
amtal / key.hs
Created June 10, 2011 08:16
Loose inversion proof of D2 CD key decoding: note each function has a 1:1 inverse
module Key ( decode
) where
import Control.Monad
import Data.Char
import Data.List
import Data.Word
import Data.Bits
import Data.Array
decode key = fmap (pack . cipher . shuffle) (initialize . normalize $ key)
@amtal
amtal / talk.txt
Created June 12, 2011 22:58
Vancouver Erlang Meetup Talk Overview
Hot Code Reload in the Small: Hot Upgrades in the Large
Erlang's strongest strength is reliability, and thus uptime. Language design, VM features, and OTP design principles come together to produce code with useful properties. Two important ones are arbitrary error recovery, and hot upgrades. With them, systems with many nines of uptime can be built.
This talk will focus on hot upgrades. We will start in the small, with low level mechanisms. Then, using examples and demonstrations, we'll cover the conventions and libraries that bring hot upgrades to the large.
By the end, you'll see how a system can be kept running non-stop despite being patched, updated, extended, and partially rewritten!
@amtal
amtal / optimize_this.erl
Created June 22, 2011 00:51
Well dang, I guess -define macros DO have a place!
-module(tst).
-export([go/0]).
a()->1.
b()->two.
c()->"three".
go() -> [a(),b(),c()].
{module, tst}. %% version = 0
@amtal
amtal / lfe_ablock.lfe.clj
Created July 14, 2011 20:31
Erlang early-returns via syntax sugar rather than throw-catch.
;; ([{atom(),binary()}], pid()) -> {missing,atom()}
;; | {bad_value,atom()}
;; | {unescaped,|atom()}
;; | malicious
;; | ok.
(defn sanitize [args logger-pid]
(ablock user-err
; check for user screwing up the input, inform them
(check-missing args)
(if (/= '() it)
@amtal
amtal / iter.erl
Created July 21, 2011 19:54
Local recursion with access to lexical scope.
-module(iter).
-export([fac/1]).
-define( for(Arg,Seed,Body)
, begin F = fun(Iter,Arg)->Body end, F(F,Seed) end
).
-define( iter(Arg)
, Iter(Iter,Arg)
).