Skip to content

Instantly share code, notes, and snippets.

View coopermaruyama's full-sized avatar

Cooper Maruyama coopermaruyama

View GitHub Profile
@coopermaruyama
coopermaruyama / icostats-export-csv.js
Last active August 19, 2017 14:37
ICO Stats CSV Script
#!/usr/bin/env node
const { createApolloFetch } = require('apollo-fetch');
const fs = require('fs');
const uri = 'https://icostats.com/graphql';
const apolloFetch = createApolloFetch({ uri });
const query = `
query icos {
icos {
id,
@coopermaruyama
coopermaruyama / config.cson
Last active August 18, 2017 08:49
atom config
"*":
Zen:
showWordCount: true
"apathy-theme":
contentPaddingLeft: 70
debug: true
enableTreeViewStyles: true
"atom-beautify":
general:
_analyticsUserId: "71ca40bc-1dad-4495-97c3-42211656647f"
@coopermaruyama
coopermaruyama / on-web3.js
Last active September 7, 2020 09:45
Check if web3 is ready
/**
* Usage: ```
* import waitForWeb3 from './on-web3.js'; // code in this gist
* waitForWeb3.then(() => runYourApp() );
* ```
* When web3 is provided by metamask, the accounts may not be available right
* away. So, if you need the accounts to be available (like for a route that
* requires a 'user'), the example that they give in their docs won't work.
*
* This function takes a callback that will be called when the accounts are
@coopermaruyama
coopermaruyama / query-graphql-example.js
Created July 21, 2017 05:47
Simplest way to query a graphql API
const { createApolloFetch } = require('apollo-fetch');
const uri = 'http://localhost:3000/graphql';
const apolloFetch = createApolloFetch({ uri });
const query = `
query getTodos {
todos {
title
completed
}
@coopermaruyama
coopermaruyama / render.js
Last active July 19, 2017 03:37
Rendering
/**
* Dynamic content is served via this middleware. Each page has a 'path'
* attribute which determines the path on which it should render. Any time a
* request is made to the server, we check the requested path to see if any
* page has that same path, in which case we step in and render that page.
* @flow
*/
/* eslint-disable react/no-danger, no-inline-comments */
import type { $Request, $Response } from 'express';
import React from 'react';
@coopermaruyama
coopermaruyama / recover-secret.js
Created September 16, 2016 22:45
Recover secret string from random triplets
// There is a secret string which is unknown to you. Given a collection of
// random triplets from the string, recover the original string.
//
// A triplet here is defined as a sequence of three letters such that each
// letter occurs somewhere before the next in the given string. "whi" is a
// triplet for the string "whatisup".
//
// As a simplification, you may assume that no letter occurs more than once in
// the secret string.
//
@coopermaruyama
coopermaruyama / recover-secret.js
Created September 16, 2016 22:45
Recover secret string from random triplets
// There is a secret string which is unknown to you. Given a collection of
// random triplets from the string, recover the original string.
//
// A triplet here is defined as a sequence of three letters such that each
// letter occurs somewhere before the next in the given string. "whi" is a
// triplet for the string "whatisup".
//
// As a simplification, you may assume that no letter occurs more than once in
// the secret string.
//
@coopermaruyama
coopermaruyama / find-appointment.js
Created September 16, 2016 22:41
Finding an Appointment (JS)
// The businesspeople among you will know that it's often not easy to find an
// appointment. In this kata we want to find such an appointment automatically.
// You will be given the calendars of our businessperson and a duration for the
// meeting. Your task is to find the earliest time, when every businessperson is
// free for at least that duration.
//
// Example Schedule:
//
// Person | Meetings
// -------+-----------------------------------------------------------
@coopermaruyama
coopermaruyama / memory-manager.js
Last active June 10, 2017 08:31
Memory Manager
// Description:
//
// One of the services provided by an operating system is memory management.
// The OS typically provides an API for allocating and releasing memory in a
// process's address space. A process should only read and write memory at
// addresses which have been allocated by the operating system. In this kata you
// will implement a simulation of a simple memory manager.
//
// JavaScript has no low level memory API, so for our simulation we will simply
// use an array as the process address space. The memory manager constructor
@coopermaruyama
coopermaruyama / rescursiveReduce.js
Last active May 27, 2016 00:41
ES6: Recursive vertical reducer
//
// * Given some data that looks like this:
//
// let data = [
// {
// key: 'a',
// value: 'a1',
// children: [
// {
// key: 'b',