Skip to content

Instantly share code, notes, and snippets.

var answerHash = '0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365';
// iterate through all possible uint8
for (var i = 0; i < 2 ** 8; i++) {
var hex = i.toString(16);
var padUint8 = web3.padLeft(hex, 2);
var hash = web3.sha3(padUint8, {encoding: 'hex'});
if (hash == answerHash) {
console.log(`Found: ${i}`);
break;
// construct contract object with ABI
var abiDefinition = [{"constant":false,"inputs":[{"name":"n","type":"uint8"}],"name":"guess","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"isComplete","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":true,"stateMutability":"payable","type":"constructor"}];
var GuessTheNumberChallenge = web3.eth.contract(abiDefinition);
// load from deployed contract. replace the address with yours
var challenge = GuessTheNumberChallenge.at("0xb13afE1D0195a5C7876eE3e297a06A50b6f847A8");
// call `guess` function
challenge.guess(42, {value: web3.toWei(1, 'ether')}, console.log);
var abiDefinition = [{"constant":false,"inputs":[{"name":"nickname","type":"bytes32"}],"name":"setNickname","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"nicknameOf","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}];
var CaptureTheEther = web3.eth.contract(abiDefinition);
// load from deployed contract. replace the address with yours
var cte = CaptureTheEther.at("0x71c46Ed333C35e4E6c62D32dc7C8F00D125b4fee");
// call `setNickname` function
cte.setNickname("your name", console.log);
// construct contract object with ABI
var abiDefinition = [{"constant":false,"inputs":[],"name":"callme","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"isComplete","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"}];
var CallMeChallenge = web3.eth.contract(abiDefinition);
// load from deployed contract. replace the address with yours
var challenge = CallMeChallenge.at("0xf70218870AD13c7b57a01B95cF86a6D137088aE3");
// call `callme` function
challenge.callme(console.log);
# install solidity on Mac
brew update
brew upgrade
brew tap ethereum/ethereum
brew install solidity
brew linkapps solidity
# compile solidity contract
cat << EOF | solc - --abi
pragma solidity ^0.4.21;
// get accounts managed by Metamask
var account;
web3.eth.getAccounts((err, acc) => {account = acc[0]});
console.log(account);
// get balance
web3.eth.getBalance(account, (err, balance) => {
console.log(web3.fromWei(web3.toDecimal(balance), 'ether'))
});
Verifying my Blockstack ID is secured with the address 1BQroEmkps4bRv2Z5bwhamsDAwjTVo4tJW https://explorer.blockstack.org/address/1BQroEmkps4bRv2Z5bwhamsDAwjTVo4tJW
@saurfang
saurfang / s3.Rmd
Created December 11, 2015 18:31
S3 example
```{r}
area <- function(x) UseMethod("area", x)
rectangle <- function(a, b) {
structure(list(a = a, b = b), class = "rectangle")
}
area.rectangle <- function(x) {
x$a * x$b
}
@saurfang
saurfang / index.html
Last active August 29, 2015 14:15 — forked from mbostock/.block
Superformula Explorer
<!DOCTYPE html>
<meta charset="utf-8">
<title>Superformula</title>
<style>
path {
stroke-width: 1.5px;
stroke: #666;
fill: #ddd;
}
@saurfang
saurfang / README.md
Last active August 29, 2015 14:14 — forked from mbostock/.block

The tree layout implements the Reingold-Tilford algorithm for efficient, tidy arrangement of layered nodes. The depth of nodes is computed by distance from the root, leading to a ragged appearance. Cartesian orientations are also supported. Implementation based on work by Jeff Heer and Jason Davies using Buchheim et al.'s linear-time variant of the Reingold-Tilford algorithm. Data shows the Flare class hierarchy, also courtesy Jeff Heer.

Compare to this Cartesian layout.