Skip to content

Instantly share code, notes, and snippets.

View nahidakbar's full-sized avatar

nahidakbar

  • Scentre Group
  • Sydney, Australia
View GitHub Profile
const EVENTS_AT_A_TIME = 10;
const MAX_CHECK_INTERVAL = 500;
const WAIT_PER_EVENT = MAX_CHECK_INTERVAL / EVENTS_AT_A_TIME;
export function listenToEvents(knex, table, name, callback) {
let lastEventId;
const cursor = table + "::" + name;
async function getCursorPosition(): Promise<number> {
// produces unique enough base36 serial based on nanosecond time
function makeUpgradeCode() {
const [nanoseconds, seconds] = process.hrtime();
const time = (seconds * 1e6 + nanoseconds)
.toString(26)
.split('')
.map(x => (parseInt(x, 26) + 10).toString(36))
.concat(Math.random().toString(10).substring(2).split(''))
.slice(0, 12);
const [a, b, c, d, e, f, g, h, i, j, k, l] = time;
@nahidakbar
nahidakbar / encode.js
Created September 14, 2019 05:31
Encode and decode numbers into codes
const [ns, s] = process.hrtime();
const nsTime = (s * 1e6 + ns);
function encode(num, digits = 15, off = 0) {
const rand = off ? Math.random().toString(26).substring(1, 1 + off) : '';
const str = (num.toString(26) + rand).split('');
let input = str.map(ch => ch === '.' ? '-' : (parseInt(ch, 26) + 10).toString(36)).join('').toUpperCase();
@nahidakbar
nahidakbar / gist:acfc9093bc21653224414f6396b541dc
Last active October 27, 2020 06:40
Extend ubuntu vm size without using live disks and gui tools
Extend size of disk and then boot into vm.
# fix up partition size
sudo parted -l
Fix
# file up partition
sudo fdisk /dev/sda