Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Chiro ᴴᶦʳᵒ

Chiro Hiro chiro-hiro

:octocat:
Chiro ᴴᶦʳᵒ
View GitHub Profile
@chiro-hiro
chiro-hiro / test.ts
Created Mar 25, 2021
Merge array by unique key
View test.ts
const src = [
{ name: 'a', value: 1 },
{ name: 'b', value: 2 },
{ name: 'c', value: 3 },
];
const dst = [
{ name: 'd', value: 4 },
{ name: 'a', value: 5 },
{ name: 'f', value: 6 },
@chiro-hiro
chiro-hiro / Cloner.sol
Last active Mar 26, 2021 — forked from holiman/Cloner.sol
A generic 'cloner' contract which clones other contract instances
View Cloner.sol
pragma solidity ^0.4.4;
contract X{
string junk;
function y() returns(string){
//Uncomment the 'junk' below to make gas-measurements
//junk="0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345
View lazzy-ass.md

Install hardhat with serveral stuffs:

npm install --save-dev hardhat @nomiclabs/hardhat-waffle \
  ethereum-waffle chai @nomiclabs/hardhat-ethers ethers ts-node \
  typescript chai @types/node @types/mocha @types/chai

Run geth light mode:

@chiro-hiro
chiro-hiro / std-vector.md
Created Feb 22, 2021
Which's one do you prefer?
View std-vector.md
std::vector<int> *vec = new std::vector<int>;
assert(vec != NULL);
// ...
delete vec;
View test.js
/*
Found this tiny challenge, then i give it a try.
https://www.facebook.com/groups/learningcplusplus/permalink/2668380586619732
----
Đề bài cho một Mảng gồm các phần tữ int bất kỳ. Không được phép xắp xếp hoặc chép lại rồi xắp xếp, làm sao để biết là mãng đó có 5 phần tử đó có liền kề nhau hay không ?
Ví dụ a={ 9,6,9,2,6,5,3,4} Có
a = { 1,2,3,4,6,7,8} Không
Ưu tiên C++ nha
*/
@chiro-hiro
chiro-hiro / dos.go
Last active Feb 5, 2021
Denial of Service: GraphQL login
View dos.go
/*
Copyright (c) 2016 Chiro Hiro. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, see <https://opensource.org/licenses/MIT>.
*/
package main
import (
@chiro-hiro
chiro-hiro / base64.ts
Created Nov 12, 2020
TypeScript trick to make base64 work on both browser and Node.js
View base64.ts
function strToUint8Array(v: string): Uint8Array {
const buf = new Uint8Array(v.length);
for (let i = 0; i < v.length; i += 1) {
buf[i] = v.charCodeAt(i);
}
return buf;
}
function bufferToUint8Array(v: Buffer): Uint8Array {
@chiro-hiro
chiro-hiro / restful-api-in-typescript.md
Last active Oct 18, 2020
Standardized your RESTful API in TypeScript
View restful-api-in-typescript.md
export interface IError {
  message: string;
  code?: string;
  stack?: string;
}

export interface IOrdering {
  column: string;
  order: 'asc' | 'desc';
@chiro-hiro
chiro-hiro / protect-evironment-variables.js
Last active Oct 17, 2020
Protect environment variables
View protect-evironment-variables.js
function uFirst(v) {
return v.length > 0 ? `${v[0].toUpperCase()}${v.substr(1)}` : "";
}
function toCamelCase(v) {
return v
.toLowerCase()
.split("_")
.map((e, i) => (i > 0 ? uFirst(e.trim()) : e.toLowerCase()))
.join("");
View result-xor-cipher.txt
clang main.c -mavx -o main && ./main
plaintext: Lorem ipsum dolor sit amet, consectetur adipiscing elit gravida.
ciphertext: 4047c2232d5e8122867cb08a49e720613f94373a86f9d54d39c7ab1d97ede417b6c17d3bb2eb46a77a8e1f7de28731ef624f90232c179c72927bbcdc44ec2d20
Deciphertext: Lorem ipsum dolor sit amet, consectetur adipiscing elit gravida.