Skip to content

Instantly share code, notes, and snippets.

View swashcap's full-sized avatar
Writing code

Cory Reed swashcap

Writing code
View GitHub Profile
@swashcap
swashcap / stylesheets.js
Created October 31, 2015 21:40
Get info about stylesheets
'use strict';
var fs = require('fs');
var parse = require('css').parse;
var path = require('path');
var files = []; // Add your files here
var filePaths = files.map(function(file) {
return path.join(__dirname, file);
@swashcap
swashcap / get-deep-objects.js
Created November 10, 2015 22:41
Get arbitrarily deeply nested objects with a comparator.
/**
* Get deeply nested objects using a 'compare' function.
*
* @param {(object|array)} target Data tree in which to find objects.
* @param {function} compare Passed items in the `target` data tree. It
* should return a boolean value based on the
* item.
* @return {array}
*/
function getDeepObjects(target, compare) {
@swashcap
swashcap / coinstac-server-client.js
Created January 25, 2016 22:41
nodeapi/coinstac-server-core integration
// coinstac-server-client/index.js
'use strict';
var assign = require('lodash.assign');
var Pouchy = require('pouchy');
module.exports.handlersFactory = function(config) {
// Private, configured PouchDB/Pouchy instance
// May need async config of instance if it's Cloudant and security settings
@swashcap
swashcap / base.js
Last active February 5, 2016 02:24
Thin JOI Classes
/**
* @module base.js - COINSTAC Model
*/
'use strict';
const assign = require('lodash/assign');
const joi = require('joi');
const pick = require('lodash/pick');
/**
@swashcap
swashcap / freesurfer-multishot.js
Created February 5, 2016 22:24
COINSTAC Stuff
'use strict';
const _ = require('lodash');
const coinstacCommon = require('coinstac-common');
const coinstacAlgorithms = require('coinstac-distributed-algorithm-set');
const freesurferParser = require('freesurfer-parser');
const helpers = require('./path/to/helpers/');
const Analysis = coinstacCommon.Analysis;
const ComputationPipeline = coinstacCommon.ComputationPipeline;
@swashcap
swashcap / cli
Created February 15, 2016 22:27
Node’s Uncaught Exception
#!/usr/bin/env node
'use strict';
const logger = require('../src/utils/logger.js');
const pkg = require('../package.json');
const program = require('commander');
const server = require('../index.js').server;
const url = require('url');
@swashcap
swashcap / pick-ordered-values.js
Created April 4, 2016 00:24
Pick ordered values snippet
/**
* Pick ordered values.
*
* @example
* pickOrderedValues(
* ['wat', 'silly'],
* { silly: 100, thing: 200, wat: 300 }
* );
* // => [300, 100]
*
@swashcap
swashcap / instructions.md
Last active June 3, 2016 18:55
Directory Parsing Exercise

We’re considering changing the object shape for a simulator declaration (declaration.js in Sergey’s examples). Right now it looks like this:

const path = require('path');

module.exports = {
  users: [{
    username: 'user1',
    userData: [
      // Data here...
@swashcap
swashcap / makeTree.js
Last active November 1, 2016 18:19
Make a tree from a flat data structure
'use strict';
const { deepEqual } = require('assert');
/**
* Sample data structure.
*
* The items are roughly sorted already, with the top-level item as the root of
* the tree.
*