Skip to content

Instantly share code, notes, and snippets.

:octocat:
Chiro ᴴᶦʳᵒ

Chiro Hiro chiro-hiro

:octocat:
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
View keybase.md

Keybase proof

I hereby claim:

  • I am chiro-hiro on github.
  • I am chiro8x (https://keybase.io/chiro8x) on keybase.
  • I have a public key ASCmwC369mu7TJyx0a_QmNetM1A56DLANYB9Q0gQeuFr8wo

To claim this, I am signing this object:

@chiro-hiro
chiro-hiro / node-js-scan-files.md
Created Jan 3, 2019
NodeJS -- Scan all files for given path
View node-js-scan-files.md

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
chiro-hiro / golang-tls.md
Created Aug 24, 2018 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples
View golang-tls.md

Moved to git repository: https://github.com/denji/golang-tls

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
chiro-hiro / golang-slice.md
Last active Jun 22, 2018
first() and last() safe access in Golang
View golang-slice.md

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 (
	"fmt"
	"reflect"
)

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

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
chiro-hiro / part-time-4.md
Last active May 26, 2018
Part time part 4/chap 6
View part-time-4.md

Đ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 {
        revert();
    }

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
chiro-hiro / part-time-3.md
Created May 26, 2018
Part time part 3/chap 6
View part-time-3.md
    //Mapped data
    mapping (uint256 => Job) public jobData;
    
    //Transaction must contant Ethereum
    modifier onlyHaveFund {
        require(msg.value > MINIUM_SALARY);
        _;
    }
@chiro-hiro
chiro-hiro / partime-2.md
Created Mar 21, 2018
Partime smart contract and test case
View partime-2.md

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

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

Toàn bộ smart contract như sau

pragma solidity ^0.4.17;

contract PartTime {
  
  struct Job {
    uint256 id;
    address creator;
    uint256 salary;
@chiro-hiro
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.