Skip to content

Instantly share code, notes, and snippets.

View winzaa123's full-sized avatar
๐Ÿ™Š
Relax ~*

win winzaa123

๐Ÿ™Š
Relax ~*
  • Phuket, Thailand
View GitHub Profile
@winzaa123
winzaa123 / cache.js
Created April 21, 2020 02:48 — forked from haimrait/cache.js
node-redis-mongo - final cache
const mongoose = require("mongoose");
const redis = require("redis");
const util = require("util");
const keys = require("../config/keys");
const client = redis.createClient({
host: keys.redisHost,
port: keys.redisPort,
retry_strategy: () => 1000
});
@winzaa123
winzaa123 / generate-pushid.js
Last active September 29, 2019 09:31 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/