Skip to content

Instantly share code, notes, and snippets.

🔊


Duncan Beevers duncanbeevers

🔊

Block or report user

Report or block duncanbeevers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View proxyPromise.js
function proxyPromise(promise) {
const acc = [];
function createFnProxy(prop) {
return function(...args) {
acc.push([prop, args]);
return proxy;
};
}
@duncanbeevers
duncanbeevers / AliasVose.js
Last active May 22, 2020
JavaScript implementation of Michael Vose's constant-time weighted random outcome generator.
View AliasVose.js
// Based on Darts, Dice, and Coins: Sampling from a Discrete Distribution
// http://www.keithschwarz.com/darts-dice-coins/
export default class AliasVose {
constructor(list) {
// Determine relative probabilities.
const scalar = list.length /
list.reduce((acc, item) => { return acc + item.weight; }, 0);
// Partition outcomes into tiny and big work queues.
View keybase.md

Keybase proof

I hereby claim:

  • I am duncanbeevers on github.
  • I am duncanbeevers (https://keybase.io/duncanbeevers) on keybase.
  • I have a public key whose fingerprint is 3DC2 C013 05E7 E510 3F75 A78C BE1A 0744 BEC4 A007

To claim this, I am signing this object:

View edit-project.jade
.col-md-12
hr
div
ab-checkbox(shadow-model="project.sendErrorEmail") Send email when an error occurred
ab-checkbox(shadow-model="project.sendCommentEmail") Send email when someone commented
ab-checkbox(shadow-model="project.sendOnlyProductionEmail")
| Send Notify for
.label.production
i.burk.burk-environment
| Production
View keybase.md

Keybase proof

I hereby claim:

  • I am duncanbeevers on github.
  • I am duncanbeevers (https://keybase.io/duncanbeevers) on keybase.
  • I have a public key whose fingerprint is F03C 58AC 2B3E 019E 3F3D CCA5 2543 E9A0 A5D8 984D

To claim this, I am signing this object:

@duncanbeevers
duncanbeevers / Compiler.coffee
Created Jan 26, 2014
Jade to React.DOM compiler
View Compiler.coffee
isConstant = require('constantinople')
toConstant = require('constantinople').toConstant
Compiler = (node, options) ->
compile: ->
visitTag = (tag) ->
buffer('React.DOM.' + tag.name + '(')
visitAttributes(tag.attrs, tag.attributeBlocks)
visitArgs(tag)
buffer(')')
@duncanbeevers
duncanbeevers / to_query_string.js
Created Jul 16, 2013
Query string from JS object
View to_query_string.js
function toQueryString(obj) {
var ret = [];
function add(dest, key, val) {
var type = Object.prototype.toString.call(val), i, len;
if ("[object Array]" === type) {
// Array
for (i = 0, len = val.length; i < len; i++) { add(dest, key + "[]", val[i]); }
} else if ("[object Object]" === type) {
View users_app.js.coffee
App.setupWithOptions
orange: "very"
fragrant: "barely"
@duncanbeevers
duncanbeevers / flac2mp3.rb
Created Feb 19, 2013
Convert .flac files to VBR mp3
View flac2mp3.rb
#!/Users/duncanbeevers/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
filenames = ARGV
abort "Usage: flac2mp3 FLACFILE, ( FLACFILE, ... )" if filenames.length < 1
require 'open3'
FIELD_NAMES = %w(TITLE ARTIST ALBUM TRACKNUMBER GENRE)
FIELDS = FIELD_NAMES.map { |f| "(?:#{Regexp.quote(f)})" }.join("|")
MATCHER = /^(#{FIELDS})=([^\n]+)\n$/
@duncanbeevers
duncanbeevers / .bash_profile
Created Jan 18, 2013
PS1 hostname consistent hashing
View .bash_profile
# Colors
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow
txtblu='\[\e[0;34m\]' # Blue
txtpur='\[\e[0;35m\]' # Purple
txtcyn='\[\e[0;36m\]' # Cyan
bldred='\[\e[1;31m\]' # Red
bldgrn='\[\e[1;32m\]' # Green
bldylw='\[\e[1;33m\]' # Yellow
You can’t perform that action at this time.