Skip to content

Instantly share code, notes, and snippets.

View KoryNunn's full-sized avatar

Kory Nunn KoryNunn

View GitHub Profile
@KoryNunn
KoryNunn / speed-tweeter.js
Created February 9, 2018 10:35
Auto tweet speedtest.net results.
var speedTest = require('speedtest-net');
var TweetIt = require('tweetit');
var creds = require('./creds');
var tweetit = new TweetIt(creds.consumerKey, creds.consumerSecret, creds.accessToken, creds.accessTokenSecret);
speedTest({maxTime: 5000}, (error, data) => {
if(error){
return;
}
@KoryNunn
KoryNunn / gcDelayExample.js
Last active January 22, 2018 01:35
Background Task Defer Request
function onDrag(event){
if(!dragging){
return
}
// Tell the browser you are doing important stuff
// It will decide whether or not to delay background tasks for a small period of time
// For example, not doing garbage collection if it isn't really critical.
// It might also decided not to, if it NEEDS to GC, or paint, or anything.
window.requestBackgroundTaskDefer();
@KoryNunn
KoryNunn / example.js
Created January 19, 2018 00:38
https://www.toptal.com/javascript/asynchronous-javascript-async-await-tutorial but using normal callbacks, that don't catch exceptions, and implicitly handle rejections, using righto, also faster, and optimisable, because it doesn't use try/catch
const verifyUser = function(username, password, callback){
const userInfo = righto(dataBase.verifyUser, username, password);
const rolesInfo = righto(dataBase.getRoles, userInfo);
const logStatus = righto(dataBase.logAccess, userInfo, righto.after(rolesInfo));
const result = righto.mate(userInfo, righto.after(logStatus));
result(callback);
};
@KoryNunn
KoryNunn / fancyCrel.js
Created January 16, 2018 23:52
crel with type class and id parsing
var crel = require('crel');
function fancyCrel(){
var args = Array.prototype.slice.call(arguments);
console.log(args);
var type = args.shift();
var settings = {};
if(args[0] && typeof args[0] === 'object'){
@KoryNunn
KoryNunn / gist:5c6cb954a6d9be930d2a9b873cc34797
Last active November 3, 2017 01:30
prototypical method binding Proxy
function bindContext(object){
return new Proxy({
get: function(target, key){
if(typeof target[key] === 'function' && !target.hasOwnProperty(key)){
return target[key].bind(target);
}
return target[key];
}
});
@KoryNunn
KoryNunn / index.js
Created May 16, 2017 06:12
requirebin sketch
var crel = require('crel');
crel(document.body,
crel('div',
crel('h1', 'hello')
)
);
@KoryNunn
KoryNunn / template.js
Created November 18, 2016 06:17
string templating perf tests, worth? MEEEHHHHHHHHHH!
var template = 'just your average string template using {type}',
matchToken = /\{(.+?)\}/g;
function compile(source){
var positions = {},
fnString = 'return "' + source.replace(
matchToken,
function(match, key) {
return '" + (scope["' + key + '"] || "") + "';
}
var json = righto.from(xmltojsonhttpclient.get()),
transform = righto.from(SearchModel.get, json),
mappedData = righto.from(SearchController.get, transform),
contractData = righto.from(ContractModel.get, mappedData),
mappedContractData = righto.from(ContractController.get, contractData);
mappedContractData(function(error, result){
// Do what you want.
});
// Assumes <Thing>.get is a normal err-back API.
var json = righto.from(xmltojsonhttpclient.get()),
transform = righto(SearchModel.get, json),
mappedData = righto(SearchController.get, transform),
contractData = righto(ContractModel.get, mappedData),
mappedContractData = righto(ContractController.get, contractData);
mappedContractData(function(error, result){
// Do what you want.
var matches = righto(getSoccerMatches); // <- Ye Olde error-back
var results = righto(getSoccerResults); // <- Ye Olde error-back
var detailedMatches = righto.sync(function(matches, results){
return matches.map(function( match ) {
return {
name: match.name,
score: findScoreForMatch(match, results)
};
});