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 / 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"
@chiro-hiro
chiro-hiro / nested-object-to-keys-values.ts
Created Apr 23, 2020
Transform nested object to keys-values
View nested-object-to-keys-values.ts
let tmpResult:{ [key: string]: any} = {};
/**
* Transform an nested object to keys-values object
* @export
* @param {object} obj
* @param {string[]} [key=[]]
* @returns {object}
*/
export default function objectTokeyValue(obj: any, key:string[] = [], first: boolean = true):any {
@chiro-hiro
chiro-hiro / singleton.ts
Created Apr 14, 2020
Singleton in TypeScript
View singleton.ts
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;
View blind-sql-injection.js
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,
View submatrix.c
#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);
View js-004.js
class Foo {
constructor() {
this.constructedAt = (new Date()).toISOString();
}
static getInstance() {
if (typeof this.instance === 'undefined') {
this.instance = new Foo();
}
return this.instance;
}
View js-003.js
class Foo {
constructor() {
this.constructedAt = (new Date()).toDateString();
}
static getInstance() {
this.foo = 1;
this.instance = this;
return this.instance;
}
getValue() {
View js-002.js
class Human {
constructor(name) {
this.name = name;
this.race = 'Terran';
}
set name(value) {
if (typeof value !== 'string') {
throw new TypeError('Name value was not a string');
View js-001.js
// Human constructor
function Human(name) {
this.name = name;
}
// Define name as a property
Object.defineProperty(Human.prototype, 'name', {
set: function (value) {
if (typeof value !== 'string') {
throw new TypeError('Name value was not a string');
You can’t perform that action at this time.