Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fetch('/fact.wasm')
.then(response => response.arrayBuffer())
.then(bytes => WebAssembly.instantiate(bytes, {}))
.then(results => {
alert(results.instance.exports.fact(parseInt(prompt(), 10)));
});
#[no_mangle]
pub fn fact(n: i32) -> i32 {
do_fact(n, 1)
}
fn do_fact(n: i32, akk: i32) -> i32 {
if n < 2 { return akk; }
do_fact(n - 1, n * akk)
}
self.addEventListener("install", (event) => {
// called once, fetch assets required for offline use
});
self.addEventListener("activate", event => {
// a moment to sync client and clean up the cahce
});
self.addEventListener("fetch", event => {
// handle each event.request based on choosed strategy
});
pragma solidity ^0.4.19;
contract ToolplooxAnimalsFound {
address owner;
address public beneficiary;
uint public donation;
function ToolplooxAnimalsFound(address _beneficiary) public payable {
owner = msg.sender;
beneficiary = _beneficiary;
}
event Donation(address donator, uint amount);
event Withdrawal(address beneficiary, uint amount);
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function withdraw() onlyOwner public {
require(donation > 0);
beneficiary.transfer(donation);
Withdrawal(beneficiary, donation);
donation = 0;
}
function donate() public payable {
donation += msg.value;
Donation(msg.sender, msg.value);
}
}
pragma solidity ^0.4.19;
contract ToolplooxAnimalsFound {
address owner;
address public beneficiary;
uint public donation;
function ToolplooxAnimalsFound(address _beneficiary) public payable {
owner = msg.sender;
beneficiary = _beneficiary;
}
event Donation(address donator, uint amount);
event Withdrawal(address beneficiary, uint amount);
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function withdraw() onlyOwner public {
require(donation > 0);
beneficiary.transfer(donation);
Withdrawal(beneficiary, donation);
donation = 0;
}
function donate() public payable {
donation += msg.value;
Donation(msg.sender, msg.value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment