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
const language = {
_numberOfTimesCalled: 0,
set foo(name) {
this._numberOfTimesCalled++
this._foo = name
},
get foo() {
return this._foo
}
const yes_no = function() {
const possibilities = [
[
{
"label": "yes",
"name": "1",
"value": ""
},
{
"label": "no",
shouldGridAutoStop() {
const firstXButtons = tangyToggleButtons.slice(0, this.autoStop)
const hasAtLeastOneUnpressedButton = firstXButtons
.reduce((hasAtLeastOne, button) => hasAtLeastOne || button.pressed === false ? true : false, false)
return hasAtLeastOneUnpressedButton ? false : true
}
@rjcorwin
rjcorwin / debugger-statement-in-a-template-literal.js
Created April 16, 2020 20:20
How to put a debugger statement in a Javascript template literal.
var foo = `
Here is a debugger statment in a template...
${(()=>{ debugger })()}
`
var message = 'Hello world'
var number = '555-555-5555'
var options = {
replaceLineBreaks: false, // true to replace \n by a new line, false by default
android: {
intent: 'INTENT' // send SMS with the native android SMS messaging
//intent: '' // send SMS without opening any other app
}
};
var success = function () { alert('Message sent successfully'); };
find . -type f | xargs -I $0 ls -ll --time-style=long-iso $0 | awk '{print $6" "$7" "$8}' | sort | grep -E '2019-[0[7-9]|1]'
// 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)
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
@rjcorwin
rjcorwin / use-lit-element-in-an-angular-project.md
Last active January 1, 2023 11:43
Directions on how to use Lit Element as a replacement to `@angular/core`'s `Component` decorator.

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'
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) {