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 / 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.
View xorshift+pro.c
#include <immintrin.h>
// Global seed value
__m256i seed;
// Use SSE2 perform pesudo random for given seed
__m128i xor_shift_plus_pro()
{
// t = 0
__m128i t = _mm_setzero_si128();
View main.c
/*
MIT License
Copyright (c) 2020 Chiro Hiro <chiro8x@gmail.com>
*/
#include <stdio.h>
#include <string.h>
#include <immintrin.h>
// Global seed value
View xorshift+.c
#include <stdint.h>
struct xorshift128p_state {
uint64_t a, b;
};
/* The state must be seeded so that it is not all zero */
uint64_t xorshift128p(struct xorshift128p_state *state)
{
uint64_t t = state->a;
View chiro-code.ts
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.4;
contract VerifyPoC {
function verifySerialized(bytes memory message, bytes memory signature) public pure returns (address) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
// Singature need to be 65 in length
View ricmoo-code.ts
//SPDX-License-Identifier: MIT
pragma solidity ^0.6.4;
contract Verifier {
// Returns the address that signed a given string message
function verifyString(
string memory message,
uint8 v,
bytes32 r,
bytes32 s
@chiro-hiro
chiro-hiro / file.ts
Created Jul 24, 2020
Trick for mixing betwen async and callback
View file.ts
function test(callback: (result: any)=>void) {
(async () => {
const a = await function1();
const b = await function2();
return { a, b };
})()
.then((result) => {
callback(result);
});
}
@chiro-hiro
chiro-hiro / ed25519-keys-example.json
Created May 13, 2020
Valid ed25519 keys for unit test
View ed25519-keys-example.json
[
{
"publicKey": "a28dce25d19f11b29bec42547d95d76fcba0d88d45c07f6816f970e417a73c30",
"privateKey": "04d26486cd227a7999aa606d7fb07fb3010528ba043c0e3a1b98f1a26c3b16cba28dce25d19f11b29bec42547d95d76fcba0d88d45c07f6816f970e417a73c30",
"seed": "04d26486cd227a7999aa606d7fb07fb3010528ba043c0e3a1b98f1a26c3b16cb"
},
{
"publicKey": "431a43aa41d085326f6ded197f6c0c29f4b245fd7f3a954f2700b60df2f40097",
"privateKey": "f28a767f6b38307ac5ef94f873138334829c87a72fdfd205930de04eb39805e8431a43aa41d085326f6ded197f6c0c29f4b245fd7f3a954f2700b60df2f40097",
"seed": "f28a767f6b38307ac5ef94f873138334829c87a72fdfd205930de04eb39805e8"
You can’t perform that action at this time.