Skip to content

Instantly share code, notes, and snippets.

@alexmoore
alexmoore / iso8601.erl
Last active August 29, 2015 13:57
Iso 8601 Timestamp Long format in Erlang
%% Provides a timestamp like 2014-03-19T19:25:17.779905
DateTime = erlang:now().
{_,_,MicroSec} = DateTime.
{{Year,Month,Day},{Hour,Min,Sec}} = calendar:now_to_universal_time(DateTime).
DateString = io:format("~4..0B-~2..0B-~2..0BT~2..0B:~2..0B:~2..0B.~6..0B",
[Year, Month, Day, Hour, Min, Sec, MicroSec]).
DateString.

#Oh the Schemas you can Scheme!

You can scheme about scaling
Of which SQL can only dream!
You can scheme about NoSQL
Oh the schemas you can scheme

Oh, the schemes you can scheme up
if only you try!
If you try, you can scheme up

using System;
using System.Numerics;
using System.Globalization;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace StringPaddingTest
{
function doubleInteger(i) {
return i*2;
}
function isNumberEven(i) {
return i%2 === 0;
}
function getFileExtension(i) {
if(i.indexOf('.') >= 0) {
@alexmoore
alexmoore / .emacs
Created September 30, 2013 16:25
Add this to your .emacs file to autoload the tools for the current erlang with https://github.com/alexmoore/erls
;; setup erlang mode
(setq erlang-root-dir "/Users/alex/erlangs/current")
(setq erlang-lib-dir (concat erlang-root-dir "/lib/erlang/lib"))
(setq load-path
(cons (concat erlang-lib-dir
"/"
(car (directory-files erlang-lib-dir nil "^tools\-"))
"/emacs" )
load-path))
-module(fizzbuzz).
-export([print_fizz_buzz/0,fizzbuzz/1]).
print_fizz_buzz() ->
Each = fun(I) ->
print_fizz_buzz(fizzbuzz(I)) end,
lists:foreach(Each, lists:seq(1,100)).
print_fizz_buzz(I) when is_integer(I) -> io:fwrite("~p~n", [I]);
print_fizz_buzz(I) -> io:fwrite("~s~n", [I]).
function list_erlangs() {
read -ra AvailableErls <<< `ls -l $ERL_HOME | awk '/^d/' | cut -d ' ' -f12-`
Current=`ls -l $ERL_HOME | awk '/^l/' | sed 's/^l.*-> \(.*\)/\1/'`
for i in "${AvailableErls[@]}"; do
if [ $i = $Current ]; then echo "$Current *"; else echo $i; fi
done
}
function change_current_erlang() {
Target=$1
{
"Id": "Policy1371509616384",
"Statement": [
{
"Sid": "Stmt1371509665536",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::BUCKET_NAME/*",
@alexmoore
alexmoore / vnode_helper.rb
Last active December 16, 2015 21:59
Little helper class to figure out on which vnodes a particular hash resides.
class VNodeHelper
attr_reader :ring_size, :n_val
def initialize(ring_size, n_val)
@ring_size = ring_size
@n_val = n_val
@vnode_size = (2 ** 160 / @ring_size)
end
@alexmoore
alexmoore / push.rb
Created August 31, 2012 21:46
[hg]|[git] push -m 'it real good'
require 'Win32API'
Beep = Win32API.new('kernel32', 'Beep', ['I', 'I'], 'I')
def Rest(ms)
sleep(ms / 1000.0)
end
c = 1046
d = 1175
e = 1319