Skip to content

Instantly share code, notes, and snippets.

Raine Revere raineorshine

Block or report user

Report or block raineorshine

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@raineorshine
raineorshine / get-contract-array-values.js
Created Apr 9, 2017
A generic means of getting all values from a public contract array.
View get-contract-array-values.js
// 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 Apr 6, 2017
Executes an array of promises or promise-returning functions serially and reduces the results with the given accumulator.
View promiseReduce.js
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 Jun 12, 2019
An aesthetic comparison of a few human-readable hashing functions.
View human-readable-hash-comparisons.md

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.

zacharyvoase/humanhash

input 1 word output 2 word output 3 word output
@raineorshine
raineorshine / raw-rpc-request.js
Created Feb 11, 2017
Send a raw RPC request with web3
View raw-rpc-request.js
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 Feb 10, 2017
My personal notes trying to wrap my head around all the amazing ideas from evm-lang-design.
@raineorshine
raineorshine / auto-reducers.js
Last active Feb 5, 2017
React reducers keyed by action type
View auto-reducers.js
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 Feb 2, 2017
Notes from experimenting with Idris Lightyear
View idris-lightyear-notes.c
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 Jan 26, 2017
Set different committer on a specific repo.
View custom-git-committer.sh
git config user.email "Full Name"
git config user.email "example@gmail.com"
@raineorshine
raineorshine / assert-throw.js
Last active Mar 16, 2019
Asserting solidity throws in truffle tests.
View assert-throw.js
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 Jan 3, 2017
Test that a contract method throws in a truffle unit test.
You can’t perform that action at this time.