Skip to content

Instantly share code, notes, and snippets.

View DerayGa's full-sized avatar

Deray DerayGa

View GitHub Profile
'use strict'
const Web3 = require('web3')
const keythereum = require('keythereum')
const Tx = require('ethereumjs-tx')
let web3 = new Web3(new Web3.providers.HttpProvider('http://140.119.164.155:8545'));
// read from key file
let keyObj = {
pragma solidity ^0.4.0;
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
contract Fund {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
/// Withdraw your share.
function withdraw() {
if (msg.sender.send(shares[msg.sender]))
shares[msg.sender] = 0;
pragma solidity ^0.4.2;
library Set {
struct Data { mapping(uint => bool) flags; }
function insert(Data storage self, uint value) returns (bool) {
if (self.flags[value])
return false; // value already there
self.flags[value] = true;
return true;
pragma solidity ^0.4.2;
library Set {
// library 不能真的有狀態變數,但呼叫 library 的合約可以擁有 (請見下方 contract)
struct Data { mapping(uint => bool) flags; }
// 加上 storage 修飾字之後,self 就會指向呼叫 library 的合約的某個狀態變數
// 此為 library 特有的功能
function insert(Data storage self, uint value) returns (bool) {
if (self.flags[value])
@DerayGa
DerayGa / BuyNccuCoin
Last active November 9, 2016 11:42 — forked from noeleon930/BuyNccuCoin
pragma solidity ^0.4.0;
contract BuyNccuCoin {
address public minter;
mapping (address => uint) public balances;
event Sent(address from, address to, uint amount);
function BuyNccuCoin() {
minter = msg.sender;
contract GradesContract {
address public teacher;
mapping (address => Grades) studentGrades;
address[] studentIds;
struct Grades {
uint ChineseGrade;
uint EnglishGrade;
@DerayGa
DerayGa / console.log() snippet for Sublime Text 2
Last active November 5, 2016 01:11 — forked from hzlzh/gist:3128038
console.log() snippet for Sublime Text 2
<snippet>
<!-- put this file in /packages/User/<Folder Name>/console_log.sublime-snippet then restart your Sublime Text 2 -->
<content><![CDATA[console.log($1);$0]]></content>
<tabTrigger>conl</tabTrigger>
<scope>text.html,source.js</scope>
<description>console.log()</description>
</snippet>
<snippet>
<!-- put this in another file /packages/User/<Folder Name>/console_dir.sublime-snippet then restart your Sublime Text 2 -->
pragma solidity ^0.4.0;
contract NccuBank {
address public minter;
mapping (address => uint) public balances;
event Sent(address from, address to, uint amount);
function NccuBank() {
minter = msg.sender;