Skip to content

Instantly share code, notes, and snippets.

@maruks
maruks / enc-mp3.sh
Created December 7, 2013 22:24
WAV->MP3 encoding/tagging script
!/usr/bin/env ruby
if ARGV.length < 4
puts "Usage: enc-mp3 artist year album picture"
exit
end
artist = ARGV[0]
date = ARGV[1]
album = ARGV[2]
@maruks
maruks / heap.sml
Created January 30, 2015 12:14
leftist heap
signature Ordered =
sig
type T
val eq : T * T -> bool
val lt : T * T -> bool
val leq : T * T -> bool
end
(* HEAP *)
@maruks
maruks / heap.clj
Created January 30, 2015 12:15
leftist heap
(declare insert)
(declare find-min)
(declare delete-min)
(declare empty-heap)
(declare is-empty?)
(declare heap-seq)
(deftype LeftistHeap [^Integer rank ^Integer elem left right]
clojure.lang.IPersistentStack
(peek [this]
(ns sandbox.words
(:require [clojure.string :refer [blank? trim join]]))
(def split-at-chars #{\newline \space \tab})
(defn cut-single-line [text column-length]
(if (> (count text) column-length)
(let [line (drop-while (complement split-at-chars) (reverse text))
length (count line)]
(cond
@maruks
maruks / dojo2.erl
Created June 16, 2015 08:42
7 languages in 7 weeks: Erlang day 2
-module(dojo2).
-import(lists,[nth/2]).
-include_lib ("eunit/include/eunit.hrl").
-compile(export_all).
lookup(K,[{K,V}|_Tl]) ->
V;
lookup(K,[{_D,_V}|Tl]) ->
lookup(K, Tl);
lookup(_K,[]) ->
@maruks
maruks / aws_lambda.py
Created July 21, 2015 11:23
AWS gateway / lambda function invocation
# AWS Version 4 signing example
# This version makes a POST request and passes request parameters
# in the body (payload) of the request. Auth information is passed in
# an Authorization header.
import sys, os, base64, datetime, hashlib, hmac
import requests # pip install requests
method = 'POST'
service = 'execute-api'
@maruks
maruks / dojo4.erl
Created July 21, 2015 22:17
July Hack Night
-module(dojo4).
-import(lists,[nth/2]).
-include_lib ("eunit/include/eunit.hrl").
-compile(export_all).
rand_list(Size) ->
lists:map(fun(X)-> random:uniform(100) end, lists:seq(1,Size)).
grid(Size) ->
lists:map(fun(X)-> rand_list(Size) end, lists:seq(1,Size)).
(ns dojo.core)
(def prices {:A 2.5
:B 3.0})
(def zones-map {"Asterix" :A
"Aldgate" :A
"Barbican" :B
"Balham" :B})
-module('shake').
-import(lists,[reverse/1]).
-define(FILENAME,"/Users/maris/Documents/pg1000.txt").
%% API exports
-compile(export_all).
insert(Children, [X | Xs]) ->
I = maps:get(X, Children, #{}),
maps:put(X, insert(I, Xs), Children);
@maruks
maruks / dojo.erl
Created December 1, 2015 15:41
London Code Dojo 34
-module(dojo).
-import(lists,[nth/2,split/2,delete/2]).
-compile([export_all]).
deck() ->
[ {Rank, Suit} || Suit <- [hearts, spades, clubs, diamonds] , Rank <- [ace, king, queen, jack, 10, 9 ,8 ,7 , 6, 5 ,4 ,3 ,2] ].
shuffle([]) ->
[];
shuffle(Xs) ->