Skip to content

Instantly share code, notes, and snippets.

View gburd's full-sized avatar

Greg Burd gburd

View GitHub Profile
@gburd
gburd / abbreviate_number.js
Created July 10, 2012 20:25
Formatting numbers in JavaScript
function abbreviate_number(num)
{
var sizes = ['', 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion'];
if (num < 1000) return num;
var i = parseInt(Math.floor(Math.log(num) / Math.log(1000)));
return ((i == 0) ? (num / Math.pow(1000, i)) : (num / Math.pow(1000, i)).toFixed(1)) + ' ' + sizes[i]; // use .round() if you don't want the decimal
};
@gburd
gburd / user_defaults.erl
Created August 14, 2012 16:09
Helpful Erlang startup bits and pieces
-module(user_default).
-author('[email protected]').
%% Compile this file and use this line in your ~/.erlang file (with
%% correct path, of course!) to where the user_default.beam file is stored.
%%
%% code:load_abs("/home/fritchie/erlang/user_default").
-export([help/0,dbgtc/1, dbgon/1, dbgon/2,
dbgadd/1, dbgadd/2, dbgdel/1, dbgdel/2, dbgoff/0,
@gburd
gburd / README.md
Created August 20, 2012 16:37
CloudStack DevCloud bootstrap
  • CloudStack is all about allocating a pool of resources out to customers/clients but we don't have a pool of assets (racks of machines) when developing. Luckily there is a pre-configured VirtualBox VM all setup to pretend to be available to CloudStack for just such testing/development purposes.
  • I work out of ~/eng, so the cloudstack git repo is there, but it's scripted to live elsewhere, so...
    • mkdir -p /opt/cloudstack (might have to sudo, chmod etc.)
    • ln -s /Users/gburd/eng/cloudstack /opt/cloudstack/incubator-cloudstack
  • We'll need the cloudstack-python-client later, install that...
    • git clone git://github.com/jasonhancock/cloudstack-python-client.git
    • cd cloudstack-python-client
    • pip install .
  • A few ant commands will need additional jars in your Ant library path, so do that...
@gburd
gburd / Makefile.patch
Created September 26, 2012 16:26
Building the xv6 operating system using Clang on OS/X (10.8) for fun and non-profit.
diff --git a/Makefile b/Makefile
index 33bfb0a..af625c8 100644
--- a/Makefile
+++ b/Makefile
@@ -29,10 +29,10 @@ OBJS = \
vm.o\
# Cross-compiling (e.g., on Mac OS X)
-#TOOLPREFIX = i386-jos-elf-
+TOOLPREFIX = /opt/gnu/bin/i386-jos-elf-
@gburd
gburd / clang-blocks.c
Created November 19, 2012 20:26
ANSI-C lambda blocks
/*
sudo apt-get install libblocksruntime-dev
clang -fblocks clang-blocks.c -lBlocksRuntime -o clang-blocks
CAVEAT: only works with clang and BlocksRuntime
*/
#include <stdio.h>
int main(void)
{
@gburd
gburd / async_nif.h
Last active October 3, 2023 05:12
Technique for running Erlang NIFs functions asynchronously, not on scheduler threads.
/*
* async_nif: An async thread-pool layer for Erlang's NIF API
*
* Copyright (c) 2012 Basho Technologies, Inc. All Rights Reserved.
* Author: Gregory Burd <[email protected]> <[email protected]>
*
* 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:
*
@gburd
gburd / build_otp.sh
Last active October 18, 2021 06:11
Shell script to build a debug or valgrind enabled Erlang OTP release and other helpful notes.
#!/usr/bin/env bash
# Note: erlang depends on ncurses, openssl at a minimum
usage ()
{
echo "usage: $0 <release> <type>"
echo " release: R14B01|R14B02|R14B03|R14B04|R15B|R15B01|R15B02|R15B03|R16B|R16B01|R16B02"
echo " type: normal, opt, gcov, gprof, debug, valgrind, or lcnt"
@gburd
gburd / generate_node.sh
Created December 1, 2012 21:41
Generate a Riak node somewhere on your filesystem *not* where you installed Riak's distribution
#!/bin/sh
#
# ./generate-node.sh -p 8087 -P 192.168.1.201 -h 8098 -H 192.168.1.201 -d 8099 -D 192.168.1.201 -s riak_kv_eleveldb_backend /mnt/riak/bin/riak /data/solid/riak
while [ "${1:0:1}" = "-" -a "${#1}" -eq 2 ]; do
case ${1:1:1} in
p)
shift
pb_port="$1"
shift
@gburd
gburd / btree.c
Created December 11, 2012 01:08
high-concurrency-btree
// btree version 2n
// 26 APR 2010
// author: karl malbrain, [email protected]
/*
This work, including the source code, documentation
and related data, is placed into the public domain.
The orginal author is Karl Malbrain.
@gburd
gburd / bitpop.erl
Last active July 2, 2018 06:27
Hamming weight of 64bit integers in Erlang using the popcount_3() method found http://en.wikipedia.org/wiki/Hamming_weight counts the number of bits set to 1.
%% -*- coding: utf-8 -*-
%%
%% %CopyrightBegin%
%%
%% Copyright (C) 2013 Gregory Burd. All Rights Reserved.
%%
%% The contents of this file are subject to the Mozilla Public License,
%% Version 2, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Mozilla Public License along with this software. If not, it can be