Skip to content

Instantly share code, notes, and snippets.

View nahidakbar's full-sized avatar

nahidakbar

  • Scentre Group
  • Sydney, Australia
View GitHub Profile
@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
@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();
// 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;
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> {
FROM mysql:5.6
COPY dump.sql /docker-entrypoint-initdb.d
RUN chmod 755 /docker-entrypoint-initdb.d/*
ENV MYSQL_ROOT_PASSWORD test
# docker build . -t db && docker run --network=host db
router.get("/all", USER, async function(req, res) {
// get summary
let all = await database.getContentSummary();
// filter out by query
all = simpleFilter(all, (item: any) => item.id, req.query.id);
all = simpleFilter(all, (item: any) => item.type, req.query.type);
// filter out privates and non-configurable
all = all.filter((item: any) => {
const wildcard = require("wildcard");
/**
* Filter an array of object by wildcard filters.
*
* @param {any[]} items list of input objects to filter
* @param {any=>string} field function that will return a string to filter given an input object
* @param {string|string[]} filters wildcard filter or filters to test. Items will be returned if any of the filters match.
* @return {any[]} list of filtered items
*/
# squash git commits
# https://wincent.com/wiki/Squashing_all_Git_commits_into_a_single_commit
git update-ref -d refs/heads/master
git commit -s -m shovel
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
/**
* HDS File parser
*
* @todo add 64 bit value parsing.
*/
var loadHDS = function(binary, filename)
{
try
{
function Uint8ArrayListWriter(contentSize, filename)
{
var output, that = this, offset, errored;
function init(callback)
{
output = [];
offset = 0;