Skip to content

Instantly share code, notes, and snippets.

@dheimoz
dheimoz / gist:09efef0e3d3a5460f77a6e96caaf0306
Created November 24, 2022 15:27 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@dheimoz
dheimoz / couchDBStream.js
Created October 24, 2021 15:16 — forked from Stwissel/couchDBStream.js
Streaming couchDB using NodeJS stream API and nano
const Nano = require("nano");
const { Writable, Transform } = require("stream");
const exportOneDb = (couchDBURL, resultCallback) => {
const nano = Nano(couchDBURL);
nano
.listAsStream({ include_docs: true })
.on("error", (e) => console.error("error", e))
.pipe(lineSplitter())
.pipe(jsonMaker())
var saveBlob = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (blob, fileName) {
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
window.URL.revokeObjectURL(url);
@dheimoz
dheimoz / idb-backup-and-restore.md
Created May 21, 2021 13:56 — forked from loilo/idb-backup-and-restore.js
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'
// We allocate a file with the size of the downloaded file so we can
// append chunks randomly to diffrent position as we download the file
function allocateDisk(size, callback){
fss.cwd.getFile(prompt("Filename","movie.mp4"), {create: true}, (fileEntry) => {
fileEntry.createWriter((writer) => {
var blob = new Blob([new ArrayBuffer(1.049e+8)])
writer.onerror = (err) => {
@dheimoz
dheimoz / json-delta.js
Created January 26, 2021 09:28
Get the delta of two json objects.
const {
isObject,
isEqual,
transform,
has,
merge,
} = require('lodash');
const assert = require('assert');
/**
@dheimoz
dheimoz / crypto-aes-256-gcm-demo.js
Created November 18, 2020 16:06 — forked from rjz/crypto-aes-256-gcm-demo.js
example using node.js crypto API with aes-256-gcm
const buffer = require('buffer');
const crypto = require('crypto');
// Demo implementation of using `aes-256-gcm` with node.js's `crypto` lib.
const aes256gcm = (key) => {
const ALGO = 'aes-256-gcm';
// encrypt returns base64-encoded ciphertext
const encrypt = (str) => {
// Hint: the `iv` should be unique (but not necessarily random).
@dheimoz
dheimoz / application.js
Created November 17, 2020 18:05 — forked from afinne/application.js
ember-pouch adapter, disable eventual consistency for a single findRecord
import { configFlagDisabled } from 'ember-pouch/utils'
.
.
.
////
// Overridden to support temporary disabling of eventual consistency
//
findRecord: async function (store, type, id, snapshot) {
await this._init(store, type);
var recordTypeName = this.getRecordTypeName(type);