Skip to content

Instantly share code, notes, and snippets.

View raineorshine's full-sized avatar

Raine Revere raineorshine

  • New York, NY
View GitHub Profile
@raineorshine
raineorshine / get-contract-array-values.js
Created April 9, 2017 17:34
A generic means of getting all values from a public contract array.
// Streams all values from a public contract array. Callback is a function that takes a single
// argument, one item from the array. Returns a promise that rejects if there is any error or
// resolves if all items have been retrieved.
function getAll(contract, sizeGetter, array, cb) {
// get the size of the array
return contract[sizeGetter]().then(n => {
// generate an array of contract calls
return Promise.all(Array(n.toNumber()).fill().map(i => {
// invoke the callback with the item
return contract[array](i).then(cb)
@raineorshine
raineorshine / promiseReduce.js
Last active April 6, 2017 02:35
Executes an array of promises or promise-returning functions serially and reduces the results with the given accumulator.
const waterfall = require('promise.waterfall')
const Bluebird = require('bluebird')
const _ = require('lodash')
// an array of 10ms functions with different return values
const functions = [
() => Bluebird.delay(10, 'a'),
() => Bluebird.delay(10, 'b'),
() => Bluebird.delay(10, 'c')
]
@raineorshine
raineorshine / human-readable-hash-comparisons.md
Last active July 21, 2024 20:31
An aesthetic comparison of a few human-readable hashing functions.

An Aesthetic Comparison of Human-Readable
Hashing Functions

The following compares the output of several creative hash functions designed for human readability.

sha1's are merely used as arbitrary, longer, distributed input values.

input 1 word output 2 word output 3 word output
@raineorshine
raineorshine / raw-rpc-request.js
Created February 11, 2017 15:02
Send a raw RPC request with web3
web3.currentProvider.sendAsync({
jsonrpc: “2.0”,
method: “evm_increaseTime”,
params: [60], // 60 seconds, may need to be hex, I forget
id: new Date().getTime() // Id of the request; anything works, really
}, function(err) {
// ...
});
@raineorshine
raineorshine / evm-lang-design-notes.md
Last active February 10, 2017 17:07
My personal notes trying to wrap my head around all the amazing ideas from evm-lang-design.
@raineorshine
raineorshine / auto-reducers.js
Last active February 5, 2017 16:32
React reducers keyed by action type
const reducers = {}
// these could be easily split up across different files
reducers.FETCH_RESULT = (state, result) => Object.assign({}, { myData: result.myData }, state }
reducers.ADD_ITEM = (state, item) => Object.assign({}, { items: state.items.concat(item) }, state }
reducers.REMOVE_ITEM = (state, item) => Object.assign({}, { items: ... }, state }
// the main reducer
reducer = (state, action) => {
return reducers[action.type](state, action.data)
@raineorshine
raineorshine / idris-lightyear-notes.c
Created February 2, 2017 04:15
Notes from experimenting with Idris Lightyear
https://github.com/ziman/lightyear
idris JsonTest.idr -p lightyear -p contrib
parse jsonToplevelValue "{ \"a\": 1, \"b\": 2 }"
@raineorshine
raineorshine / custom-git-committer.sh
Created January 26, 2017 15:59
Set different committer on a specific repo.
git config user.email "Full Name"
git config user.email "[email protected]"
@raineorshine
raineorshine / assert-throw.js
Last active March 16, 2019 18:37
Asserting solidity throws in truffle tests.
it('should throw an error', cb => {
const result = aMethodThatRejects()
result.then(x => { cb('Expected error. Instead got ' + x) }))
result.catch(() => cb())
})
@raineorshine
raineorshine / test-solidity-error-in-truffle.js
Last active January 3, 2017 12:58
Test that a contract method throws in a truffle unit test.
_