Skip to content

Instantly share code, notes, and snippets.

@kumavis
kumavis / gist:c654143c4bcdea21e618
Last active August 29, 2015 14:14
How to Mercury (kumavis style)

First define your component:

  • value types and defaults for each key
  • 'channels', actions that potentially modify state or perform i/o. triggered by button presses, mouse movements, etc
var Value = require('observ')
var Component = require('../lib/component.js')
var Wallet = require('../wallet/index.js')
var Identity = require('../identity/index.js')
var render = require('./render.js')
nm = NumberMachine()
nm.multiply(2)
nm.add(6)
nm.subtract(3)
nm.multiply(2)
nm(10) //=> 46
nm(0) //=> 6
nm(20) //=> 86
10:46 <kumavis> maybe components could have some generic channel-generating hooks ?
10:46 <kumavis> render() { return inputBox( state.label, state.channels.bindValue('label') ) }
10:47 <kumavis> which could simplify to inputBox( state, 'label' )
10:47 <kumavis> so i dont have to create a channel that only updates a value directly passed in
10:48 <kumavis> right now i have to do inputBox(state.newIdentityAddress, state.channels.updateNewIdentityAddress)
10:48 <kumavis> function updateNewIdentityAddress(state, data) {
10:48 <kumavis> state.newIdentityAddress.set(data.text)
10:48 <kumavis> }
10:48 <kumavis> its just a lot of code to do one simple thing i feel
10:56 ⇐ alexandergugel quit ([email protected]) Remote host closed the connection
╭─{👘 } kumavis in ~/Development/Node/ethereum-address-generator
╰─± node example.js
Looking for an address starting with "abc".
tried 1000 identities.
tried 2000 identities.
tried 3000 identities.
tried 4000 identities.
tried 5000 identities.
tried 6000 identities.
Found after 6110 attempts!
;(function () {
function c() {
var e = document.createElement("link");
e.setAttribute("type", "text/css");
e.setAttribute("rel", "stylesheet");
e.setAttribute("href", f);
e.setAttribute("class", l);
document.body.appendChild(e)
}
function h() {
start (secret) -> return apiObject with [encrypt, decrypt] with plaintext secret stored in closure
encrypt (input) -> generate salt, iv, additionalData, -> generate hash from salt and secret -> generate key from hash -> encrypt with key -> return json string with salt, iv, additionalData, and encrypted data (edited)
decrypt(input) -> read salt, iv, additionalData -> generate hash from salt and secret -> generate key from hash -> decrypt with key -> return unecrypted data
and the 'encrypted text' includes plaintext metadata about the encryption settings (salt, iv, additionalData)

Keybase proof

I hereby claim:

  • I am kumavis on github.
  • I am kumavis (https://keybase.io/kumavis) on keybase.
  • I have a public key whose fingerprint is 6750 E5FB B48E 01F1 D3AB 6BEE 9AC5 DEA8 D6AD D69B

To claim this, I am signing this object:

@kumavis
kumavis / index.js
Created March 18, 2015 07:26
requirebin sketch
var esquery = require('esquery')
var esprima = require('esprima')
var treeify = require('treeify').asTree
var src = 'var x = require("x"); var z = require("z")'
function go(selector){
var ast = esprima.parse(src);
var selectorAst = esquery.parse(selector);
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+[+!+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+
@kumavis
kumavis / gist:dbcdaf8a0c6813ef1bd8
Created April 7, 2015 21:04
binary buffer encoding perf test
console.log( 'encode hex: '+testN(encodeTest, getRandomBuffer, 'hex', 100000).toFixed(10) )
console.log( 'decode hex: '+testN(decodeTest, getRandomData, 'hex', 100000).toFixed(10) )
console.log( '--------------' )
console.log( 'encode utf8: '+testN(encodeTest, getRandomBuffer, 'utf8', 100000).toFixed(10) )
console.log( 'decode utf8: '+testN(decodeTest, getRandomData, 'utf8', 100000).toFixed(10) )
console.log( '--------------' )
console.log( 'encode base64: '+testN(encodeTest, getRandomBuffer, 'base64', 100000).toFixed(10) )
console.log( 'decode base64: '+testN(decodeTest, getRandomData, 'base64', 100000).toFixed(10) )
console.log( '--------------' )
console.log( 'encode json: '+testN(encodeJsonTest, getRandomBuffer, 'json', 100000).toFixed(10) )