Skip to content

Instantly share code, notes, and snippets.

View keithwhor's full-sized avatar
🍁

Keith Horwood keithwhor

🍁
View GitHub Profile
@keithwhor
keithwhor / testAthing.js
Created June 20, 2018 08:33
Code.xyz Function: Test Integration
module.exports = async () => 'test a thing';
@keithwhor
keithwhor / testAthing.js
Created June 20, 2018 08:33
Code.xyz Function: Testing Gist Integration
module.exports = async () => 'test a thing';
@keithwhor
keithwhor / user-email-list.js
Created June 20, 2018 07:22
Code.xyz Function: User E-mail List Generation
/**
* Creates an e-mail list from provided user data
*/
module.exports = async (users = []) => {
return users.map(user => {
return `${user.first_name} <${user.email}>`;
}).join(', ');
}
@keithwhor
keithwhor / __main__.js
Last active June 20, 2018 07:11
Code.xyz Function: Silly API Example
class A {
constructor () {
this.value = 0;
}
valueOf () {
return ++this.value;
}
toString () {
return this.valueOf();
}
@keithwhor
keithwhor / testgist.js
Created June 20, 2018 06:30
Code.xyz Function: TEST GIST
module.exports = async () => 'testing gist';
@keithwhor
keithwhor / node_stdlib_calling_example.js
Created June 7, 2017 09:02
Node.js StdLib Calling / Composition Example
const lib = require('lib');
// We deployed our dentist rating service as "dentists"...
// callback style
lib.user.dentists({ratings: [1, 2, 5, 5]}, (err, result) => {
// handle
});
// promise style
/**
* async / await supported natively!
* @param {array} ratings Our ratings out of five from top dentists
* @returns {object}
*/
module.exports = async function (ratings = [5, 5, 3, 5]) {
let lastRating = await getDentistRatingWhoIsSlowToRespond();
ratings.push(lastRating);
@keithwhor
keithwhor / stdlib_faaslang_example.js
Created June 7, 2017 08:51
FaaSlang Example Function
/**
* This is a FaaSlang-compliant function. It uses a modified ESDoc/JSDoc
* parser to read comments and determine types to implement type-safety
* mechanisms at execution time, or can intuit types based on default.
* It also performs static analysis to ensure comments match function footprints.
* @param {string} name Your name
* @param {string} age Your age
* @returns {string}
*/
module.exports = (name = 'Arya Stark', age = 18, context, callback) => {
@keithwhor
keithwhor / stdlib_ntseq_map.js
Created January 3, 2017 09:13
stdlib NtSeq Parallelized Map Function
const Nt = require('ntseq'); // NtSeq library
module.exports = (params, callback) => {
// Get query and genome sequences, as well as offset
let q = (params.kwargs.q || '') + '';
let seq = (params.kwargs.seq || '') + '';
let offset = Math.max(0, parseInt(params.kwargs.offset) || 0);
// Read sequences
const f = require('f');
const fs = require('fs');
const async = require('async');
const Nt = require('ntseq');
// Get first 1,000,000 nt of E. coli K12 genome
const K12 = fs.readFileSync('./seq/ecolik12.txt').toString().substr(0, 1000000);
module.exports = (params, callback) => {