Skip to content

Instantly share code, notes, and snippets.

@achiko
achiko / Random generator
Created March 21, 2016 12:38 — forked from alexvandesande/Random generator
A very simple random generator. A miner can influence the number by not publishing a block with an unwanted outcome, and forfeiting the 5 block reward.
contract random {
/* Generates a random number from 0 to 100 based on the last block hash */
function randomGen(uint seed) constant returns (uint randomNumber) {
return(uint(sha3(block.blockhash(block.number-1), seed ))%100);
}
/* generates a number from 0 to 2^n based on the last n blocks */
function multiBlockRandomGen(uint seed, uint size) constant returns (uint randomNumber) {
uint n = 0;
for (uint i = 0; i < size; i++){
contract tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData); }
contract MyToken {
/* Public variables of the token */
string public name;
string public symbol;
uint8 public decimals;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
contract owned {
address public owner;
function owned() {
owner = msg.sender;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_
}
function transferOwnership(address newOwner) onlyOwner {
@achiko
achiko / 2of3.md
Last active August 29, 2015 14:22 — forked from anonymous/2of3.md

2-of-3 Escrow Example with Electrum

This is gmaxwell's 2-of-2 escrow example, adapted to Electrum and to a lesser extent, GFM.

The Scenario

Archey wants to pay Bertha 0.001 BTC for a Twitter Platinum invite, but prevent Bertha from cheating him. Archey selects Iceland to act as

<div id="stack" style="height: 275px;">
<!--
"_id" : ObjectId("53f371ff540d630d415e7c86"),
"owner" : "351070185040940",
"jobownerid" : ObjectId("53d6b1ffcb4ebce61621a693"),
"title" : "Javascript Ninja",
"description" : "Javascript Ninja Needed !!!",
var urls = [
/* Wildcard CORS enabled - Works in PhantomJS 1.9.0 */
'http://updates.html5rocks.com',
/* CORS disabled - Fails in PhantomJS 1.9.0 (and every other version) */
'http://www.google.com',
/* Hack workaround? */
/*
function(httpGet, callback) {
phantom.page.settings = (phantom.page.settings || {});
phantom.page.settings.webSecurityEnabled = false;
@achiko
achiko / nginx_ubuntu
Last active August 29, 2015 14:01
Latest version nginx on ubuntu
https://www.digitalocean.com/community/articles/how-to-install-the-latest-version-of-nginx-on-ubuntu-12-10
//-- Install latest version Nginx On Ubuntu
sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:nginx/stable
sudo apt-get install software-properties-common
sudo apt-get update
@achiko
achiko / nodejs_ubuntu
Last active August 29, 2015 14:01
Install Nodejs on ubuntu
http://askubuntu.com/questions/49390/how-do-i-install-the-latest-version-of-node-js
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
@achiko
achiko / elasticsearch_ubuntu
Last active August 29, 2015 14:01
Elasticsearch Ubuntu 12.04.4 64 Bit
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
# NEW WAY / EASY WAY
wget wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.2.deb
sudo dpkg -i elasticsearch-1.2.2.deb
@achiko
achiko / Ubuntu_Couchdb
Last active August 29, 2015 14:01
Install CouchDb 1.5.1 on Unbuntu 12.04.4
sudo apt-get update -y
sudo apt-get install g++ -y
sudo apt-get install erlang-base erlang-dev erlang-eunit erlang-nox -y
sudo apt-get install libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool -y
curl -O http://apache.mirrors.tds.net/couchdb/source/1.5.1/apache-couchdb-1.5.1.tar.gz
tar -zxvf apache-couchdb-1.5.1.tar.gz
cd apache-couchdb-1.5.1