Skip to content

Instantly share code, notes, and snippets.

Chiro ᴴᶦʳᵒ

Chiro Hiro chiro-hiro

Chiro ᴴᶦʳᵒ
Block or report user

Report or block chiro-hiro

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am chiro-hiro on github.
  • I am chiro8x ( on keybase.
  • I have a public key ASCmwC369mu7TJyx0a_QmNetM1A56DLANYB9Q0gQeuFr8wo

To claim this, I am signing this object:

chiro-hiro /
Created Jan 3, 2019
NodeJS -- Scan all files for given path

This function will return an array of files for given path:

function scanDir(scanPath, filelist) {
  var filelist = filelist || [];
  var dirs = fs.readdirSync(scanPath);
  for (var i = 0; i < dirs.length; i++) {
    var _childPath = path.resolve(scanPath, dirs[i])
    if (fs.statSync(_childPath).isDirectory()) {
      scanDir(_childPath, filelist);
    } else {
chiro-hiro /
Created Aug 24, 2018 — forked from denji/
Simple Golang HTTPS/TLS Examples

Moved to git repository:

Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
chiro-hiro /
Last active Jun 22, 2018
first() and last() safe access in Golang

I'm pretty sure, Golang is a good language to learn and do development. I find out Golang doesn't support some popular safe slice access.

package main

import (

func main() {
chiro-hiro /
Created May 26, 2018
Part time part 5/ chap 6

Kết quả khi mình chạy test, mình có dump data để các bạn có thể theo dõi sự thay đổi.

Contract: Partime
    √ should have 0 total part time job
        Job's details:
         id: 0
         creator: 0x4a8be21d76a3003bf62513907b3a460957086caf
         salary: 1000000000000000000
         start: 0
         end: 0
chiro-hiro /
Last active May 26, 2018
Part time part 4/chap 6

Đoạn code bên dưới sẽ giúp Ethereum không bị trapped trong smart contract khi có người dùng vô tình gửi Ethereum vào.

    //We don't let any trapped in this contract
    function () public payable {

Từ Solidity 0.4.21 thì việc dùng constructor sẽ thay thế cho việc sử dụng function có cùng tên với smart contract.

    //Empty constructor
chiro-hiro /
Created May 26, 2018
Part time part 3/chap 6
    //Mapped data
    mapping (uint256 => Job) public jobData;
    //Transaction must contant Ethereum
    modifier onlyHaveFund {
        require(msg.value > MINIUM_SALARY);
chiro-hiro /
Created Mar 21, 2018
Partime smart contract and test case

Mình viết lại smart contract, thêm hai function mới takeJob()viewJob():

    //Take job
    takeJob (uint256 jobId)
    public onlyValidMortgage(jobId) onlyValidId(jobId) onlyValidJob(jobId)
        //Trigger event to log labor
        TakeJob(jobId, msg.sender);
chiro-hiro /
Last active Mar 14, 2018
PartTime smart contract

Toàn bộ smart contract như sau

pragma solidity ^0.4.17;

contract PartTime {
  struct Job {
    uint256 id;
    address creator;
    uint256 salary;
chiro-hiro / ip2str.cpp
Last active Feb 14, 2018
Unsigned 32 bits IP address to string
View ip2str.cpp
g++ -std=c++11 ip2str.cpp -o ip2str
ip2str 0xb01a8c0 0x100007f
#include <sstream>
#include <iostream>
using namespace std;
/* Simplest version */
You can’t perform that action at this time.