Skip to content

Instantly share code, notes, and snippets.

@jimkang
jimkang / exportIfNode.js
Created May 18, 2014 22:28
Check for module.exports before assigning to it. For modules intended work in both browser and Node.
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = createWhatever();
}
@jimkang
jimkang / howtousefind.sh
Created June 19, 2014 17:50
How to use `find`. I somehow always forget this.
find . -name [name of file]
@jimkang
jimkang / arraycombos.js
Created July 30, 2014 04:41
Getting all of the possible combinations of the elements in several arrays
// Combines every element in A with every element in B.
function crossArrays(arrayA, arrayB) {
var combo = [];
arrayA.forEach(function combineElementWithArrayB(aElement) {
arrayB.forEach(function combineBElementWithAElement(bElement) {
if (Array.isArray(aElement) || Array.isArray(bElement)) {
combo.push(aElement.concat(bElement));
}
else {
combo.push([aElement, bElement]);
@jimkang
jimkang / call-stack-introspection.js
Created November 1, 2014 18:11
Call stack introspection
➜ ~ node 0 ~
> function showGrandCaller() { console.log('grandcaller:', showGrandCaller.caller.caller); console.log('parent caller:', showGrandCaller.caller); }
undefined
> function innerCaller() { showGrandCaller(); }
undefined
> function outerCaller() { innerCaller(); }
undefined
> outerCaller();
grandcaller: function outerCaller() { innerCaller(); }
parent caller: function innerCaller() { showGrandCaller(); }
{
"created_at": "Sat Dec 20 20:31:52 +0000 2014",
"id": 546402627261833200,
"id_str": "546402627261833217",
"text": "RT @bxllshipper: in NY, an american larry shipper asked Harry if Larry was real. Harry winked at her and said \"you know\" http://t.co/6OFB4X…",
"source": "<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
@jimkang
jimkang / phoneme-follow-frequencies-in-syllables.json
Created February 17, 2015 16:51
Generated with `phonemize-analyze-ff.js` from `phonemenon`.
{
"START": {
"EH": 3794,
"L": 27491,
"M": 21337,
"SH": 7342,
"P": 13789,
"K": 25811,
"W": 7070,
"D": 18826,
+
#
#
#
|*
#
{" ":"black","#":"#bbb","-":"#555","|":"#555","+":"#a83",".":"#efd","@":"#af6",">":"#5ad"}
@jimkang
jimkang / trapconsolelog.js
Created February 28, 2015 02:23
A way to trap a stray console.log
var originalLog = console.log;
console.log = function trapLog(param) {
if (param === undefined) {
debugger;
}
originalLog(arguments);
};
@jimkang
jimkang / gist:427f02d30a50971e0b83
Created March 2, 2015 21:12
New service set up steps
We couldn’t find that file to show.