Skip to content

Instantly share code, notes, and snippets.

View rjcorwin's full-sized avatar

R.J. (Steinert) Corwin rjcorwin

  • Khan Academy
  • Burlington, VT
View GitHub Profile
var numberOfDocs = 1000
var userName = 'RJ'
var templateDoc = {
yourDocHere: true
}
var fillUp = async (numberOfDocs, templateDoc, dbName) => {
let initialEstimate = await navigator.storage.estimate()
let db = new PouchDB(dbName)
delete templateDoc._rev
@rjcorwin
rjcorwin / fill-up-pouchdb.js
Created January 28, 2019 18:16
A function for filling up storage using PouchDB
var fillUp = async (numberOfDocs, templateDoc, destroy = true) => {
let initialEstimate = await navigator.storage.estimate()
let dbName = `test-${new Date().getTime()}`
let db = new PouchDB(dbName)
delete templateDoc._rev
let i = 0
while (numberOfDocs > i) {
let doc = Object.assign({}, templateDoc, { _id: `${i}` })
await db.put(doc)
i++
if (inputs.location.value[3]) {
let selectedLocationNode = Loc
.flatten(inputs.location.locationList)
.find(node => node.id === inputs.location.value[3])
if (selectedLocationNode.label === 'Other') {
// Do something.
}
}
var items = [
{ name: 'Edward', value: 21 },
{ name: 'Sharpe', value: 37 },
{ name: 'And', value: 45 },
{ name: 'The', value: -12 },
{ name: 'Magnetic', value: 13 },
{ name: 'Zeros', value: 37 }
]
// sort by value
@rjcorwin
rjcorwin / redux-dat.js
Last active October 31, 2018 04:15
Idea of how a conceptual redux-dat would work...
import { createStore } from 'redux-dat'
import reducer from './reducer.js'
const myActions = new DatArchive()
const store = createStore(myActions, reducer)
store.addPeer('...')
function a() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('a')
resolve()
}, 1000)
})
}
[...document.querySelectorAll('div')].map(el => console.log(el))
const util = require('util');
const exec = util.promisify(require('child_process').exec)
const go = async () => {
try {
const output1 = await exec('echo 1')
console.log(output1.stdout)
const output2 = await exec('echo 2')
console.log(output2.stdout)
const output3 = await exec('echo 3')
let username = '';
let password = '';
let dbName = '';
const PouchDB = require('pouchdb')
const DB = PouchDB.defaults({
prefix: '/tangerine/db/'
});
try {
ls -l | awk '{print $9}' | xargs -I {} sh -c 'echo {} && find ./{} -print | wc -l'