Skip to content

Instantly share code, notes, and snippets.

R.J. Steinert rjsteinert

Block or report user

Report or block rjsteinert

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View get-current-event-definition.js
// When viewing a form, the EventInstance's ID will be at position 5 in the URL hash.
const eventInstanceId = window.location.hash.split('/')[5]
// With the eventInstanceId, we can find the matching eventInstance in caseService.case.events.
const eventInstance = caseService.case.events.find(eventInstance => eventInstance.id === eventInstanceId)
// With the eventInstance handy, we can use the eventInstance.caseEventDefinitionId to find the EventDefinition inside of caseService.caseDefinition.eventDefinitions.
const eventDefinition = caseService.caseDefinition.eventDefinitions.find(eventDefinition => eventDefinition.id === eventInstance.caseEventDefinitionId)
View benchmark-dat-disk-usage.sh
TEST_ID=$(uuid)
echo "Running 100 with Test ID of $TEST_ID"
mkdir $TEST_ID
cd $TEST_ID
dat share &
sleep 5
for i in {1..100}
do
@rjsteinert
rjsteinert / use-lit-element-in-an-angular-project.md
Last active Apr 5, 2019
Directions on how to use Lit Element as a replacement to `@angular/core`'s `Component` decorator.
View use-lit-element-in-an-angular-project.md

How to use Lit Element in an Angular Project

Directions

  1. In tsconfig.json, set "target" to "es6".
  2. Add schemas: [ CUSTOM_ELEMENTS_SCHEMA ], in the NgModule decorator of the Angular Module where your components will live.
  3. Use Angular CLI to generate a component.
  4. Refactor generated Component's import statement, decorator, constructor, and add a render function as seen in the example below.
  5. Refactor the import statement of the Component in the parent Module from import { HelloWorldComponent } from './hello-world/hello-world.component' to import './hello-world/hello-world.component'
View fill-up-pouchdb-with-revisions.js
const sleep = (milliseconds) => new Promise((res) => setTimeout(() => res(true), milliseconds))
const fillUpWithRevisions = async (numberOfDocs = 100, numberOfRevisionsPerDoc = 10, templateDoc, compactCompare = true, autoCompact = false, destroy = true) => {
let initialEstimate = await navigator.storage.estimate()
let dbName = `test-${new Date().getTime()}`
let db = new PouchDB(dbName, {auto_compaction: autoCompact})
delete templateDoc._rev
let docNumber = 0
let revisionNumber = 0
while (numberOfDocs > docNumber) {
View fill-up-a-pouchdb-database.js
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
@rjsteinert
rjsteinert / fill-up-pouchdb.js
Created Jan 28, 2019
A function for filling up storage using PouchDB
View fill-up-pouchdb.js
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++
View get-node-of-selected-location.js
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.
}
}
View es6-sort-arrays-of-objects.js
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
@rjsteinert
rjsteinert / redux-dat.js
Last active Oct 31, 2018
Idea of how a conceptual redux-dat would work...
View redux-dat.js
import { createStore } from 'redux-dat'
import reducer from './reducer.js'
const myActions = new DatArchive()
const store = createStore(myActions, reducer)
store.addPeer('...')
View promise-chaining-and-await-examples.js
function a() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('a')
resolve()
}, 1000)
})
}
You can’t perform that action at this time.