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
def get_indefinite_article (noun_phrase) | |
chars = 'aedhilmnorsx'.split('') | |
regexp1 = /(?!FJO|[HLMNS]Y.|RY[EO]|SQU|(F[LR]?|[HL]|MN?|N|RH?|S[CHKLMNPTVW]?|X(YL)?)[AEIOU])[FHLMNRSX][A-Z]/ | |
regexp2 = [/^e[uw]/, /^onc?e\b/, /^uni([^nmd]|mo)/, /^u[bcfhjkqrst][aeiou]/] | |
regexp3 = /^U[NK][AIEO]/ | |
regexp4 = /^y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt)/ | |
m = /\w+/.match noun_phrase | |
return "an" unless m |
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 mkdirpSync (dirpath) { | |
var fs = require('fs'); | |
var parts = dirpath.split(path.sep); | |
for( var i = 1; i <= parts.length; i++ ) { | |
try { | |
fs.mkdirSync(path.join.apply(null, parts.slice(0, i))); | |
} catch(e) { | |
if ( e.code != 'EEXIST' ) throw e; | |
} | |
} |
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 urlInfo (url) { | |
var props = 'hash host hostname href origin password pathname port protocol username search'; | |
if (!window.urlInfoAnchorElement) | |
window.urlInfoAnchorElement = document.createElement('a'); | |
urlInfoAnchorElement.href = url; | |
return props.split(' ').reduce(function (m, v, i) { |
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
m = function (func) { | |
return func.toString() | |
.replace(/^[^{]+{\s*\/\*\s*/m, "") | |
.replace(/\s*\*\/\s*}$/m, ""); | |
}; | |
var str = m(function(){/* | |
everything in here | |
is a multiline string | |
it is a secret. |
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
/* Hybrid singletons. removes the need for 'new' */ | |
/* Really more an experiment than anything */ | |
function Person (name, age) { | |
var parentFn = this[arguments.callee.name]; | |
if (parentFn && !(this instanceof parentFn)) | |
return new (Function.prototype.bind.apply( | |
parentFn, [this].concat(Array.from(arguments)))); | |
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 throttle (fn, limit) { | |
var wait = false; | |
return function () { | |
if (wait) return; | |
fn.call(); wait = true; | |
setTimeout(function () { wait = false; }, limit); | |
} | |
}; |
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(){ | |
var speed = 80, times = 3; | |
$(document).on('mouseover', '[data-shuffle]', function (e) { | |
var $this = $(this); | |
if (!$this.data('text')) | |
$this.data('text', $this.text()); |
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
#!/usr/bin/env ruby | |
require 'json' | |
photos = JSON.parse(`instagram-screen-scrape -u #{ARGV[0]}`).each { |p| | |
system("curl -LO #{p['image']}") | |
} |
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(){ | |
var speed = 80, times = 3; | |
$(document).on('mouseover', '[data-shuffle]', function (e) { | |
var $this = $(this); | |
if (!$this.data('text')) | |
$this.data('text', $this.text()); |
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
/* Async-await, stage-3 proposal in babel, so coming very soon */ | |
// Explanation: inside an `async function funcName (){}`, `await` token | |
// waits in a non-io-blocking way for a promise to resolve before continuing | |
// the seemingly synchronous control flow | |
(async () => { | |
const delay = ms => new Promise(res => setTimeout(res, ms)); | |