Skip to content

Instantly share code, notes, and snippets.

@jcready
jcready / parseGraphAndFindNodesWhichCanReachAGivenNode.js
Created Feb 22, 2018
Parse stringified graph (‘a->b,b->c, a->c’) and find all the nodes that can reach a given node
View parseGraphAndFindNodesWhichCanReachAGivenNode.js
export const parseGraph = s => s
.split(',')
.map(edge => edge.trim().split('->'))
.reduce((adjacency, [a, b]) => {
if (!adjacency.has(a)) {
adjacency.set(a, new Set())
}
if (!adjacency.has(b)) {
adjacency.set(b, new Set())
}
@jcready
jcready / PriorityQueue.js
Created Feb 18, 2018
A priority queue using a private binary heap
View PriorityQueue.js
const PriorityQueue = (() => {
const parent = i => ((i + 1) >>> 1) - 1
const left = i => (i << 1) + 1
const right = i => (i + 1) << 1
const privateMap = new WeakMap()
const $ = privateMap.get.bind(privateMap)
const swap = (self, i, j) => {
const h = $(self).heap
View isBalanced2.js
isBalanced = (() => {
const braces = {
'{': [ 0, 1 ],
'}': [ 0, -1 ],
'[': [ 1, 1 ],
']': [ 1, -1 ],
'(': [ 2, 1 ],
')': [ 2, -1 ]
}
return function isBalanced (s) {
@jcready
jcready / integration.async.await.js
Last active May 13, 2017
Node.js example of GitHub Integration auth process
View integration.async.await.js
// With async/await support
const fs = require('fs')
const jwt = require('jwt-simple')
const pem_file = '/path/to/github.pem' // the absolute path to your Application Pem Certificate issued by GitHub
const integration_id = 0 // GitHub Application Integration ID
const installation_id = 0 // once installed on an organization. The Organization Integration ID
const expire_seconds = 60 // number of seconds the jwt token expires (max ~600 but not designated by GitHub)
const slug = 'owner/repo' // name of repo for demo purposes
const privateKey = fs.readFileSync(pem_file)
View streams.thenable.js
(function(){
const EE = require('events')
const Stream = require('stream')
const promise = Symbol('StreamPromise')
Stream.prototype.constructor = function () {
EE.call(this)
this[promise] = new Promise((resolve, reject) => {
this.on('error', reject)
this.on('end', resolve)
View crash.atom.txt
a2p addr2line animate appletviewer8 ar as aserver awk base64 bashbug bashbug-64 bdftopcf bdftops berkeley_db_svc bmp2tiff build-classpath build-classpath-directory build-jar-repository bunzip2 bzcat bzcmp bzdiff bzgrep bzip2 bzip2recover bzless bzmore c++filt c2ph ca-legacy cairo-sphinx cal captoinfo catchsegv certutil chcon check-binary-files chrt chvt cksum clean-binary-files clear cmp cmsutil col colcrt colrm column comm compare composite conjure convert create-jar-links crlutil csplit curl cut d8 db_archive db_checkpoint db_codegen db_deadlock db_dump db_dump185 db_hotbackup db_load db_printlog db_recover db_stat db_upgrade db_verify deallocvt diff diff-jars diff3 dir dircolors dirname display du dumphint dvipdf dwp eject elfedit env eps2eps eqn eu-addr2line eu-ar eu-elfcmp eu-elflint eu-findtextrel eu-make-debug-archive eu-nm eu-objdump eu-ranlib eu-readelf eu-size eu-stack eu-strings eu-strip eu-unstrip expand expr extcheck8 factor fallocate fax2ps fax2tiff fc-cache fc-cat fc-list fc-match fc-query fc-s
View q-bluebird.js
var B = require("bluebird/js/main/promise")();
var Bproto = B.prototype;
var deferredPrototype = B.pending().constructor.prototype;
deferredPrototype.makeNodeResolver = function() {
return this.asCallback;
};
function bind(fn, ctx) {
View q-bluebird.js
/* jshint newcap: false */
var B = require("bluebird/js/main/promise")();
var Bproto = B.prototype;
var deferredPrototype = B.pending().constructor.prototype;
deferredPrototype.makeNodeResolver = function() {
return this.asCallback;
};
View TODO.md
  • a task list item
  • list syntax required
  • normal formatting, @mentions, #1234 refs
  • incomplete
  • completed
View MasterStore.js
function MasterStore() {
this.datastore = {};
}
MasterStore.prototype.has = function(key, value){
if (value == null) return this.datastore.hasOwnProperty(key);
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
if (this.datastore[key].indexOf(value[i]) < 0) {
return false;
You can’t perform that action at this time.