Skip to content

Instantly share code, notes, and snippets.

View TravisMullen's full-sized avatar

Travis Mullen TravisMullen

View GitHub Profile
@TravisMullen
TravisMullen / Throttle.js
Created May 16, 2017 18:38
limit events per second
// limit the number of events per second
function throttle(callback, delay) {
var previousCall = new Date().getTime();
return function() {
var time = new Date().getTime();
if ((time - previousCall) >= delay) {
previousCall = time;
callback.apply(null, arguments);
}
};
@TravisMullen
TravisMullen / OwnFile
Created May 18, 2017 03:07
change the ownership and permissions
$ sudo chown -R $(whoami) /usr/local
@TravisMullen
TravisMullen / eth-smart-mine.js
Last active June 3, 2017 01:46
Smart Mining Ethernode
/* global eth, miner, admin, net, web3 */
// For Ethereum Networks with light activity
// automatically enable and disbale miner
//
// set var `thread` in global geth instance to change CPUs
//
// in geth console `geth attach`
// > loadScript('eth-smart-mine.js')
//
// adhered to standardjs.com/
@TravisMullen
TravisMullen / feature-detection.js
Last active June 2, 2017 18:01
Browser Feature Detection
function supportsSvg() {
return document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1');
}
function supportsObjectCreate() {
//
// Desktop
// Browser | Firefox | (Gecko) | Internet Explorer | Opera | Safari
// Basic support | 5 | 4.0 (2) | 9 | 11.60 | 5
//
@TravisMullen
TravisMullen / mega-data.sol
Created June 3, 2017 19:27
Oraclize Mega Ball
// Oraclize get data using `FlowCommunications/JSONPath`
json(https://data.ny.gov/resource/h6w8-42p9.json).[0].mega_ball
@TravisMullen
TravisMullen / ETH-USD-conversion.sol
Last active July 5, 2018 11:59
Oraclize ETH/USD Conversion
// Oraclize get data using `FlowCommunications/JSONPath`
// https://github.com/FlowCommunications/JSONPath#expression-syntax
// test with https://jsonpath.curiousconcept.com/
// these APIs are public and do not require Authorization
// from kraken (returns String)
json(https://api.kraken.com/0/public/Ticker?pair=ETHUSD).result.XETHZUSD.c.[0]
// from cryptocompare (returns Number[Float])
json(https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD).USD
@TravisMullen
TravisMullen / SafeMath.sol
Created June 3, 2017 20:13
Safe Math Functions
pragma solidity ^0.4.10;
/* taking ideas from FirstBlood token */
contract SafeMath {
/* function assert(bool assertion) internal { */
/* if (!assertion) { */
/* throw; */
/* } */
/* } // assert no longer needed once solidity is on 0.4.10 */
@TravisMullen
TravisMullen / Owned.sol
Created June 4, 2017 00:59
Manages contract ownership
// Manages contract ownership.
contract Owned {
address public owner;
function owned() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_;
}
function loadWeb3 () {
let web3Injected = window.web3;
if(typeof web3Injected !== 'undefined'){
// detect MetaMask.io
web3 = new Web3(web3Injected.currentProvider)
} else {
// eth node
web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
}
}
// give me the raw wei
export function ether (_value) {
const value = web3.fromWei(_value, 'ether').toString(10)
return `Ξ\t${value}`
}