Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
View label-arrow.js
// Doesn't throw an error, but doesn't return an object
const getObj = () => { a: 1 };
console.log(getObj()); //=> val 'undefined' : void
// Reason: It looks like an arrow function returning an object, but it isn't.
// It's an arrow function with a function body (containing a labeled
// statement) that returns nothing.
const getObj = () =>
{ // <- Start function body
a: // <- A label to use when break/continue; e.g. break a;
@getify
getify / run.js
Last active Oct 1, 2015 — forked from spikesagal/run.js
ES6 destructure named args into properties of constructed object (this).
View run.js
'use strict';
class Person {
constructor({
firstName: this.firstName = '<FIRSTNAME_UNKNOWN>',
lastName: this.lastName = '<LASTNAME_UNKNOWN>'
} = {}) {}
printName() {
console.log(this.lastName, ',', this.firstName);
}
}
View 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){
View ASQ Map
//In asynquence-contrib
var emptyItems = [],
sq = ASQ();
sq.map(emptyItems, function(item, done){
// do some things to item
item.values = [];
done(item);
});
View jsConversation
//COMPILER: Scope, can you register an `Animal` and a `dog`?
//SCOPE: Sure.
var Animal, dog;
//ENGINE: Scope, do you have `Animal` available?
//SCOPE: Sure, here it is.
//ENGINE: I'm assigning a reference to the anonymous function to `Animal`
//COMPILER: I see a function expression with a parameter called `inLove`
//COMPILER: Scope, can you register `inLove` inside this function scope?
View 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);
});
@getify
getify / async.js
Last active Jan 3, 2016 — forked from JedWatson/async.js
Example usage of the new asynquence.map() contrib plugin to update an array against a redis cache
View async.js
var transform = function(contents, doneTransform) {
var authExpiry = 60 * 60 * 1000,
authId = uuid.v4(),
authKey = 'file:auth:' + authId;
redis.client.set(authKey, JSON.stringify({
userId: req.user.id
}));
redis.client.expire(authKey, authExpiry);
@getify
getify / async.js
Last active Jan 3, 2016 — forked from JedWatson/async.js
Example usage of asynquence.gate() to update an array against a redis cache
View async.js
// This function takes a contents object with a files array.
// The goal is to cache each file details in redis then replace
// the file's path with a secure, obscured url.
// Finally the contents object is returned with the updated array
// in place of the old one.
// async = require('async')
// uuid = require('node-uuid')
// redis.client = require('node-redis').createClient()
View test.js
console.log('test');
@getify
getify / 1.js
Last active Dec 14, 2015 — forked from padolsey/1.js
View 1.js
var x = '/x/';
/x/==x
You can’t perform that action at this time.