Skip to content

Instantly share code, notes, and snippets.

View chiro-hiro's full-sized avatar
🤖
Bleep bloop, I am a robot. Eh, just kidding.

Chiro Hiro chiro-hiro

🤖
Bleep bloop, I am a robot. Eh, just kidding.
View GitHub Profile
@chiro-hiro
chiro-hiro / submatrix.c
Created April 14, 2020 02:34
Find submatrix
#include <stdio.h>
#include <stdlib.h>
//Malloc a matrix
int **malloc_matrix(size_t rows, size_t cols)
{
int **data_pointer = (int **)malloc(sizeof(int *) * rows);
for (int i = 0; i < rows; i++)
{
data_pointer[i] = malloc(sizeof(int) * cols);
@chiro-hiro
chiro-hiro / blind-sql-injection.js
Created April 14, 2020 02:47
Blind SQL injection
const http = require('http');
function request(json) {
return new Promise((resolve, reject) => {
let startTime = Date.now();
let body = JSON.stringify(json);
const options = {
host: 'localhost',
method: 'POST',
port: 3000,
@chiro-hiro
chiro-hiro / singleton.ts
Created April 14, 2020 04:27
Singleton in TypeScript
const instanceMap: {[key:string]: any} = {};
export function Singleton<T>(instanceName:string, InstanceConstructor: new () => T):T {
if (typeof instanceMap[instanceName] === 'undefined') {
instanceMap[instanceName] = new InstanceConstructor();
}
return <T>instanceMap[instanceName];
}
export default Singleton;
@chiro-hiro
chiro-hiro / nested-object-to-keys-values.ts
Last active November 24, 2020 20:09
Transform nested object to keys-values
function objectToMap(obj: any, key: string[] = [], mapResult?: Map<string, any>) {
if (typeof mapResult === 'undefined') {
mapResult = new Map<string, any>();
}
if (typeof obj === 'object' && obj !== null && !Array.isArray(obj)) {
const k = Object.keys(obj);
for (let i = 0; i < k.length; i += 1) {
if (typeof obj[k[i]] !== 'object') {
mapResult.set(key.concat([k[i]]).join('.'), obj[k[i]]);
} else if (obj[k[i]] !== null) {
@chiro-hiro
chiro-hiro / ed25519-keys-example.json
Created May 13, 2020 06:53
Valid ed25519 keys for unit test
[
{
"publicKey": "a28dce25d19f11b29bec42547d95d76fcba0d88d45c07f6816f970e417a73c30",
"privateKey": "04d26486cd227a7999aa606d7fb07fb3010528ba043c0e3a1b98f1a26c3b16cba28dce25d19f11b29bec42547d95d76fcba0d88d45c07f6816f970e417a73c30",
"seed": "04d26486cd227a7999aa606d7fb07fb3010528ba043c0e3a1b98f1a26c3b16cb"
},
{
"publicKey": "431a43aa41d085326f6ded197f6c0c29f4b245fd7f3a954f2700b60df2f40097",
"privateKey": "f28a767f6b38307ac5ef94f873138334829c87a72fdfd205930de04eb39805e8431a43aa41d085326f6ded197f6c0c29f4b245fd7f3a954f2700b60df2f40097",
"seed": "f28a767f6b38307ac5ef94f873138334829c87a72fdfd205930de04eb39805e8"
@chiro-hiro
chiro-hiro / file.ts
Created July 24, 2020 15:24
Trick for mixing betwen async and callback
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 / ricmoo-code.ts
Created August 16, 2020 09:08
ricmoo-code
//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 / chiro-code.sol
Last active April 20, 2022 11:15
chiro-code.sol
//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
#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;
@chiro-hiro
chiro-hiro / main.c
Last active September 14, 2020 08:40
/*
MIT License
Copyright (c) 2020 Chiro Hiro <[email protected]>
*/
#include <stdio.h>
#include <string.h>
#include <immintrin.h>
// Global seed value