Skip to content

Instantly share code, notes, and snippets.

@taobun
taobun / top_k_checker.sol
Created July 16, 2019 14:27
Top-k checker from Band Protocol' s Solidity102#4 article.
pragma solidity 0.5.9;
contract TopStudents {
mapping(address => uint256) public scores;
uint256 public activeMaxSize;
uint256 public activeLength;
mapping(address => address) _activeList;
address constant ACTIVE_GUARD = address(1);
@taobun
taobun / memory.sol
Created July 31, 2019 08:59
Snippet code for allocate memory array
pragma solidity 0.5.10;
contract GenerateArray {
function getZeroArrayLengthFive() public pure returns(uint256[5] memory) {
uint256[5] memory fArray;
return fArray;
}
function getZeroArray(uint256 size) public pure returns(uint256[] memory) {
uint256[] memory fArray = new uint256[](size);
pragma solidity 0.5.10;
contract Token {
string public name;
string public symbol;
mapping(address => uint256) public balances;
constructor(string memory _name, string memory _symbol) public {
name = _name;
symbol = _symbol;
@taobun
taobun / getter.sol
Created October 9, 2019 08:05
Simple getter/setter contract
pragma solidity >=0.4.22 <0.6.0;
contract GetterSetter {
uint value;
constructor(uint _initValue) public {
value = _initValue;
}
function getValue() public view returns (uint) {
@taobun
taobun / sorted_list_1.sol
Last active May 6, 2020 09:21
Sorted List code from Band Protocol' s Solidity102#3 article.
pragma solidity 0.5.9;
contract School{
mapping(address => uint256) public scores;
mapping(address => address) _nextStudents;
uint256 public listSize;
address constant GUARD = address(1);
constructor() public {
@taobun
taobun / example.json
Last active July 9, 2020 14:03
Simple lambda
{
"executable": "IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKaW1wb3J0IHN5cwoKZGVmIG1haW4oZGF0YSk6CiAgICByZXR1cm4gZGF0YQoKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICB0cnk6CiAgICAgICAgcHJpbnQobWFpbigqc3lzLmFyZ3ZbMTpdKSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICBwcmludChzdHIoZSksIGZpbGU9c3lzLnN0ZGVycikKICAgICAgICBzeXMuZXhpdCgxKQo=",
"calldata": "\"Hello lambda\"",
"timeout": 3000
}
{
"returncode": 0,
"stdout": "Hello lambda\n",
"stderr": ""
}
curl --location --request POST '<your_api_endpoint>' \
--header 'Content-Type: application/json' \
--data-raw '{
"executable": "IyEvdXNyL2Jpbi9lbnYgcHl0aG9uMwoKaW1wb3J0IHN5cwoKZGVmIG1haW4oZGF0YSk6CiAgICByZXR1cm4gZGF0YQoKCmlmIF9fbmFtZV9fID09ICJfX21haW5fXyI6CiAgICB0cnk6CiAgICAgICAgcHJpbnQobWFpbigqc3lzLmFyZ3ZbMTpdKSkKICAgIGV4Y2VwdCBFeGNlcHRpb24gYXMgZToKICAgICAgICBwcmludChzdHIoZSksIGZpbGU9c3lzLnN0ZGVycikKICAgICAgICBzeXMuZXhpdCgxKQo=",
"calldata": "\"Hello lambda\"",
"timeout": 3000
}'
sudo systemctl enable yoda
sudo systemctl start yoda
[Unit]
Description=Yoda Daemon
After=network-online.target
[Service]
User=ubuntu
ExecStart=/home/ubuntu/go/bin/yoda r
Restart=always
RestartSec=3
LimitNOFILE=4096