Skip to content

Instantly share code, notes, and snippets.

@loilo
loilo / idb-backup-and-restore.md
Last active April 22, 2024 12:17
Back up and restore an IndexedDB database

Back up and restore an IndexedDB database

This gist is an ES module which provides functions to import and export data from an IndexedDB database as JSON. It's based on Justin Emery's indexeddb-export-import package, but applies some adjustments that reflect better on the current browser landscape (i.e. better developer ergonomics but no support for Internet Explorer).

Usage

For each of the provided functionalities, you need a connected IDBDatabase instance.

Export Data

import { idb } from 'some-database'
@gregkorossy
gregkorossy / semaphore.js
Last active September 15, 2023 08:08
A simple implementation of a semaphore in JS
function Semaphore(max) {
var counter = 0;
var waiting = [];
var take = function() {
if (waiting.length > 0 && counter < max){
counter++;
let promise = waiting.shift();
promise.resolve();
}
@servel333
servel333 / handlebars-operators.md
Created February 15, 2018 15:39
Handlebars {{#if (op ... )}} operators
@snorfalorpagus
snorfalorpagus / README.md
Created January 25, 2016 10:37
Using distutils and build_clib to build a C library

Using distutils and build_clib to build a C library

This repository demonstrates how to build a C library that is included in the module distribution.

To build the C library:

python setup.py build_clib
@jung-kim
jung-kim / map-perf.js
Last active May 25, 2023 07:01
es6 map vs array vs obj performance test
"use strict";
let looper = (callback) => {
let n = 2000000;
while (n > 0) {
callback(n);
n--;
}
}
@echo off
::
:: logrotate.bat - Log rotation for windows
::
:: Usage: logrotate.bat filename maxfilecount [maxfilesize]
::
:: filename : The file name to rotate.
:: maxfilecount: Number of backup files.
:: maxfilesize : Rotated if the size of file exceeds specified size.
:: (Default is 0. Unit notation is available (K, M and G))
@ericremoreynolds
ericremoreynolds / bisect_key.py
Last active August 9, 2022 20:44
Key-like functionality recipe for Python's bisect functions
class KeyifyList(object):
def __init__(self, inner, key):
self.inner = inner
self.key = key
def __len__(self):
return len(self.inner)
def __getitem__(self, k):
return self.key(self.inner[k])
@robertripoll
robertripoll / README.md
Last active September 23, 2020 18:08
Telnet Server C#
@erikvip
erikvip / cygwinlist.md
Last active April 4, 2024 12:26
Import/Export Cygwin List of installed packages

Import & Export Cygwin List of installed Packages

If you want to go from 32 to 64 bit Cygwin but keep all the packages[1], you might find yourself in a spot where you would like to export the list of cygwin packages and also be able to install cygwin with all these packages again. I will tell you how. Open your Cygwin shell and enter

cygcheck -c -d | sed -e "1,2d" -e 's/ .*\$//' > packagelist

This will simply dump a list of installed packages. To install Cygwin 64 with these packages selected, download setup-x86_64[2] and execute it with the command line parameters

./setup-x86_64 -P `awk 'NR==1{printf \$1}{printf ",%s", \$1}' packagelist`