Skip to content

Instantly share code, notes, and snippets.

View paulownia's full-sized avatar
🐈
stray

hisanori takahashi (nyan) paulownia

🐈
stray
  • Nerima, Tokyo
  • 04:33 (UTC +09:00)
View GitHub Profile
@paulownia
paulownia / retry.js
Created September 20, 2019 04:18
retry sample
/*eslint no-console: 0 */
const retryDelay = 100;
const retryCount = 10;
function execute() {
return new Promise((resolve, reject) => {
setTimeout(() => {
const x = Math.random();
if (x > 0.8) {
const crypto = require('crypto');
class ConsistentHash {
/**
* create new consistent hash object
*
* @param nodeList - node id list
* @param vnSize - number of virtual node (default 100)
* @param algorithm - hash algorithm (default md5)
*/
function shuffle(arr) {
for (let i = arr.length; i > 1;) {
const j = Math.floor(Math.random() * i);
i--;
const ie = arr[i];
arr[i] = arr[j];
arr[j] = ie;
}
}

Keybase proof

I hereby claim:

  • I am paulownia on github.
  • I am nullpon (https://keybase.io/nullpon) on keybase.
  • I have a public key ASB4dUVrQZrNE2T0n2auSp3-eEKdbYE0QEWH2gs2y_U29go

To claim this, I am signing this object:

@paulownia
paulownia / base64.js
Last active March 11, 2021 03:27
base64 encode/decode with Uint8Array on browser
const table = [];
for (let i = 65; i < 91; i++) table.push(String.fromCharCode(i));
for (let i = 97; i < 123; i++) table.push(String.fromCharCode(i));
for (let i = 0; i < 10; i++) table.push(i.toString(10));
table.push("+");
table.push("/");
const rev_table = table.reduce((obj, c, i) => {
obj[c] = i;
return obj;
'use strict';
function leftpad1(str, len, ch) {
str = String(str);
var i = -1;
if (!ch && ch !== 0) ch = ' ';
len = len - str.length;
@paulownia
paulownia / Main.java
Created September 15, 2015 05:48
fizzbuzz java8
/*
* https://gist.github.com/kazuho/3300555
*/
import java.util.Iterator;
public class Main {
public static void main(String[] args) {
FizzBuzz fb = new FizzBuzz(30);
for (String s: fb) {
System.out.println(s);
@paulownia
paulownia / Main.java
Last active September 15, 2015 03:50
fizzbuzz
/*
* https://gist.github.com/kazuho/3300555
*/
import java.util.Iterator;
public class Main {
public static void main(String[] args) {
FizzBuzz fb = new FizzBuzz(30);
for (String s: fb) {
System.out.println(s);