Skip to content

Instantly share code, notes, and snippets.

View andytill's full-sized avatar

Andy Till andytill

View GitHub Profile
@andytill
andytill / bench.erl
Last active August 29, 2015 13:56 — forked from 0xYUANTI/bench.erl
-module(bench).
-compile(export_all).
%% Luke Gorrie's favourite profiling macro.
-define(TIME(Tag, Expr),
(fun() ->
%% NOTE: timer:tc/4 does an annoying 'catch' so we
%% need to wrap the result in 'ok' to be able to
%% detect an unhandled exception.
{__TIME, __RESULT} =
@andytill
andytill / Engine.java
Created October 1, 2014 22:06
DirtyLittlePhysics Engine.java
public class Engine
{
final static int MAX_NUM_OF_PARTICLES = 200000;
Vect3D gravity;
double drag;
int NUM_OF_PARTICLES;
Particle particles[];
@andytill
andytill / Probability of Project Success.md
Last active August 29, 2015 14:09
Probability of Project Success

Quiz

There are ten tasks in a project and they all need to be completed within their estimate for the project to be delivered on time. Each task has a 10% chance that is mis-estimated and will take longer.

What is the probability that the project will be delivered on time?

If a task has a 10% chance of being late it has a 90% (0.9) probability of success. Probability of multiple events is calculated by multiplying all the probabilties: 0.9 * 0.9 * 0.9 etc. In the contrived example where all probabilites are the same we can do a simple power of:

Eshell V5.10.2 (abort with ^G)
@andytill
andytill / .tmux.config
Created June 15, 2015 10:33
.tmux.config
# set prefix key to Ctrl-a
unbind-key C-b
set-option -g prefix C-a
# set the window index to base 1
set -g base-index 1
setw -g pane-base-index 1
# Highlight active window
@andytill
andytill / Default (OSX).sublime-keymap
Last active August 29, 2015 14:23
Sublime Text Settings (OSX)
[
{ "keys": ["ctrl+forward_slash"], "command": "toggle_comment", "args": { "block": false } },
{ "keys": ["ctrl+alt+forward_slash"], "command": "toggle_comment", "args": { "block": true } },
{ "keys": ["f3"], "command": "goto_definition" },
{ "keys": ["super+alt+r"], "command": "reveal_in_side_bar" }
]
@andytill
andytill / riak_object_usage.erl
Last active August 29, 2015 14:24
xref riak_object usage
xref:start(lol).
[xref:add_directory(lol, Dir) || Dir <- code:get_path()].
Exports = riak_object:module_info(exports).
Analyze_fn = fun({F,A}) -> {ok, Use} = xref:analyze(lol, {use, {riak_object, F, A}}), Use end.
[{{riak_object,F,A}, Analyze_fn(FA)} || {F,A} = FA <- Exports, F =/= module_info].
@andytill
andytill / horsetheperfs output
Created July 19, 2015 15:22
horsetheperfs output
erlang_spawn_1:spawn_sleep_fun_on_one_proc in 1.057355s
erlang_spawn_1:spawn_fun_on_one_proc in 0.246039s
erlang_spawn_link_1:spawn_link_sleep_fun_on_one_proc in 1.132972s
erlang_spawn_link_1:spawn_link_fun_on_one_proc in 0.421424s
erlang_split_binary_2:split_binary_small_2 in 0.004270s
erlang_split_binary_2:split_binary_large_2 in 0.004266s
erlang_split_binary_2:split_binary_very_large_2 in 0.004171s
erlang_split_binary_2:syntax_split_binary_small_2 in 0.016963s
erlang_split_binary_2:syntax_split_binary_large_2 in 0.019240s
erlang_split_binary_2:syntax_split_binary_very_large_2 in 0.018668s
@andytill
andytill / proc pooling benchmarks.txt
Created July 22, 2015 13:58
proc pooling benchmarks
processing_in_pools options:
?ITERATIONS: 10000
?KV_SIZE: 500
?PRE_SIZED_HEAP: 4400
scheduler_bind_type: no_node_thread_spread
schedulers_online: 4
processing_in_pools:temporary_workers in 10.226417s
processing_in_pools:temporary_workers_with_pre_sized_heaps in 10.378222s
@andytill
andytill / in_process_macro.erl
Created September 9, 2015 09:57
Erlang macro to run some eunit test code inside its own process and wait for that process to complete before returning. This is useful when testing resources which get cleaned up when the current process completes like ets tables.
%%% MACRO
-define(in_process(TestCode),
Self = self(),
spawn_link(
fun() ->
TestCode,
Self ! test_ok
end),
receive
%% ---------------------------------------------------------------------
%%
%% Copyright (c) 2015 Kota UENISHI. All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0