Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / run.js
Last active October 1, 2015 17:49 — forked from spikesagal/run.js
ES6 destructure named args into properties of constructed object (this).
'use strict';
class Person {
constructor({
firstName: this.firstName = '<FIRSTNAME_UNKNOWN>',
lastName: this.lastName = '<LASTNAME_UNKNOWN>'
} = {}) {}
printName() {
console.log(this.lastName, ',', this.firstName);
}
}
for (var i = 0, j = foo.length; i < j; i++) {
// do stuff
}
for (var i = foo.length; i;) {
// first usage in loop: blah[--i]
// do stuff slightly faster in reverse order
}
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
// ------------------------------------
<script src='LABjs/LAB.min.js'></script>
<script>
<!--
$LAB
.setOptions({BasePath:'/syntaxhighlight/js/'})
.script('shCore.js',
'shBrushCpp.js',
'shBrushCss.js',
'shBrushJScript.js',
'shBrushPython.js',
@getify
getify / nasty.js
Last active August 29, 2015 14:18 — forked from tomasdev/nasty.js
function segmentArray(arr,segmentSize) {
segmentSize = Math.max(1,Math.min(+segmentSize||0,arr.length));
return Array.apply(null,{length:Math.ceil(arr.length / segmentSize)}).map(function(_,i){
return arr.slice(i*segmentSize,(i+1)*segmentSize);
});
}
// lift `serviceCall(..)`
function promiseServiceCall(v) {
return new Promise(function(resolve,reject){
@getify
getify / ASQ Map
Last active August 29, 2015 14:14 — forked from broguinn/ASQ Map
//In asynquence-contrib
var emptyItems = [],
sq = ASQ();
sq.map(emptyItems, function(item, done){
// do some things to item
item.values = [];
done(item);
});
@getify
getify / promises.js
Last active August 29, 2015 14:11 — forked from smockle/promises.js
// if you convert to everything returning asynquence sequences
ASQ( get("/api/google/sheets/resources") )
.val( JSON.parse )
.seq( handlebar.bind(null,"#template", "#output") )
.seq( pourover )
.seq( linkify )
.or(function(err) {
console.error(err);
});