This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ReversedSymbol = Symbol('reversed'); | |
type ScoreScalar = string | number | boolean; | |
type Score = ScoreScalar | [ScoreScalar, typeof ReversedSymbol]; | |
export type ScoreFunction<T> = (item: T) => Score; | |
function getResult<T>( | |
scoreFns: readonly ScoreFunction<T>[], | |
itemResults: Map<T, [Score, boolean][]>, | |
item: T, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function proxyPromise(promise) { | |
const acc = []; | |
function createFnProxy(prop) { | |
return function(...args) { | |
acc.push([prop, args]); | |
return proxy; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window){var i,$sound,$buttonGroup;var $sounds=$(".sound");var clientId=require("config").get("client_id");var oauthToken=require("lib/connect").getAuthToken();var conversionHelper=require("lib/helpers/conversion-helper");var $downloadButton,size;var params,downloadUrl,onSuccess;for(i=$sounds.length-1;i>=0;i--){$sound=$($sounds[i]);var soundcloudUrl="https://soundcloud.com"+($sound.find(".soundTitle__title").attr("href")||window.location.pathname);params={url:soundcloudUrl,client_id:clientId};onSuccess=function($sound){return function(data){var params={client_id:clientId};downloadUrl=require("lib/url").stringify({query:params},data.stream_url+".mp3");$buttonGroup=$($sound.find(".sound__soundActions .sc-button-group")[0]);size=$buttonGroup.find(".sc-button:first")[0].className.match(/sc-button-((?:small)|(?:medium))/)[1];$downloadButton=$('<a class="sc-button sc-button-download sc-button-icon sc-button-responsive">Download</a>').attr({title:"Download this sound ("+conversionHelper.bytesToMB(data.origi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(')') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.setupWithOptions | |
orange: "very" | |
fragrant: "barely" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fisherYates = (array) -> | |
cap = array.length | |
for e, i in array | |
j = Math.floor(Math.random() * (cap - i)) + i | |
[ array[i], array[j] ] = [ array[j], e ] unless i == j | |
array |
NewerOlder