Skip to content

Instantly share code, notes, and snippets.

View czxtm's full-sized avatar
💭
{d'}

cooper czxtm

💭
{d'}
View GitHub Profile
@czxtm
czxtm / script.js
Last active February 2, 2018 01:01
find price at time
const moment = require('moment');
function findPrice(prices, targetMoment) {
const match = prices.find((data) => {
const [ts] = data;
const momentPrice = moment(ts);
return momentPrice.isSame(targetMoment, 'day');
});
const res = match && match[1];
@czxtm
czxtm / gist:7d869014c86c1b3e039468d43fff2f5a
Created December 4, 2017 18:51
ICOStats simple API query example using curl
curl \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ icos { id, name, symbol, roi_since_ico } }" }' \
https://icostats.com/graphql
pragma solidity ^0.4.15;
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
contract SafeProxy is Ownable {
mapping(address => bool) public whitelistedAddress;
event TransferFunds(address sender, address receiveingAddr);
/// @dev Adds a new address to the whitelist
@czxtm
czxtm / 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,
@czxtm
czxtm / 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"
@czxtm
czxtm / 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
@czxtm
czxtm / 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
}
@czxtm
czxtm / 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';
@czxtm
czxtm / 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.
//
@czxtm
czxtm / 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.
//