Skip to content

Instantly share code, notes, and snippets.

View vladdu's full-sized avatar

Vlad Dumitrescu vladdu

  • Göteborg, Sweden
View GitHub Profile
@vladdu
vladdu / tsort.erl
Created September 21, 2010 20:13
Topological sorting of a list of dependencies as pairs of {label, [label]}
%% Topological sorting of a list of dependencies as pairs of
%% {label, [label]} where the list contains dependees.
%%
%% > tsort:tsort([{a,["b",c]}, {c, [1]}]).
%% ["b",1,c,a]
-module(tsort).
-export([tsort/1]).
@vladdu
vladdu / emacs-indent-erlang
Last active August 29, 2015 13:56
Scripts to indent Erlang files from the command line
;;; File: emacs-indent-erlang
;;; adapted from http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html
;; this has to be set to the real path on your system
(add-to-list 'load-path "~/.emacs.d/elpa/erlang-20131025.6")
(load-library "erlang")
;; comment out the call to untabify if you want the mixed tabs and spaces
(defun emacs-indent-function ()
@vladdu
vladdu / 0_reuse_code.js
Created July 28, 2014 12:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@vladdu
vladdu / pre-commit.hook
Last active August 29, 2015 14:06
git pre-commit hook template: we need to work only with the files that are going to be commited
#! /bin/sh
git stash -u --keep-index
# .... work ....
# get only affected files with
git status --porcelain
#
git reset --hard
#!/bin/sh
#
# A (client-side) git hook script which warns if there are too long lines in
# the commit message, not fitting with 50/72 formatting.
#
# To use this script, copy it as .git/hooks/commit-msg and give it an executable
# file permission.
#
FILE=$1
@vladdu
vladdu / gist:0142b568a72430fcccf0
Last active August 29, 2015 14:14
Dump binary as hex
dump_hex(Binary) ->
dump_hex(Binary, 32).
dump_hex(Binary, Size) ->
dump_hex(Binary, Size, []).
dump_hex(Bin, Size, R) ->
case Bin of
<<H:Size/binary, T/binary>> ->
@vladdu
vladdu / CooldownRestartPolicy.java
Last active February 16, 2016 01:46
Guava RestartableService
public class CooldownRestartPolicy extends ServiceRestartPolicy {
/**
* If restarting sooner than this, it's probably an unrecoverable error.
*/
public static final int RESTART_INTERVAL = 5000;
private long last;
private long interval = RESTART_INTERVAL;
public CooldownRestartPolicy() {
import org.eclipse.core.runtime.Path;
public interface IPreferenceNotifier {
void changed(Path path, String key, String newValue);
void added(Path path, String key);
void removed(Path path, String key);
get_application_doc(A) ->...
% from edoc in the sources
get_module_source_doc(M) ->...
% from external files
get_module_external_doc(M) ->...
get_function_spec(M, F, A) ->...
@vladdu
vladdu / cancellable_worker.erl
Last active November 24, 2016 14:05
Cancellable worker process
-module(cancellable_worker).
-behaviour(gen_server).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
%% ====================================================================
%% API functions
%% ====================================================================