Skip to content

Instantly share code, notes, and snippets.

@jcuffe
jcuffe / demo.js
Created March 30, 2021 22:45
Nested `await` demo
// Query builders are not actually promises, but have a `.then()` method which matches the promise interface.
// As soon as you `await` or `.then()` the builder, the query is executed, and a new promise is generated that will contain the result.
const getQueryBuilder = () => ({
then: (resolve) =>
resolve(
new Promise((resolve) =>
setTimeout(() => resolve(["query", "results"]), 1000),
),
),
})
Aug 27 16:30:10 revel-x-production app/web.1 Validating authorization for protected route...
Aug 27 16:30:10 revel-x-production app/web.1 This is the authorization Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiYWNjZXNzIiwidXNlcklkIjoiYXV0aDB8NWYzYzZlZjU2YWE4MDUwMDM3NmM4MjYyIiwiZXhwIjoxNTk4NTc0NjA4LCJpYXQiOjE1OTg1NzEwMDh9.b_njTrck56pmmaThKJ6H9MihOs8dBySsq4D_5KnlTHo
Aug 27 16:30:10 revel-x-production app/postgres.26985 [DATABASE] [11-1] sql_error_code = 00000 LOG: duration: 2991.535 ms execute <unnamed>: select "events".* from "events" where "events"."id" = $1
Aug 27 16:30:10 revel-x-production app/postgres.26985 [DATABASE] [11-2] sql_error_code = 00000 DETAIL: parameters: $1 = '27bbc668-8ae3-491c-b29e-98ffd1c7431a'
Aug 27 16:30:11 revel-x-production app/web.1 Validating authorization for protected route...
Aug 27 16:30:11 revel-x-production app/web.1 This is the authorization Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiYWNjZXNzIiwidXNlcklkIjoiYXV0aDB8NWUwZjAwMzQ0YmVlMmMwZTk0NTlmNmY
2020-08-28T00:43:24.645853+00:00 app[web.1]: <--- Last few GCs --->
2020-08-28T00:43:24.645855+00:00 app[web.1]:
2020-08-28T00:43:24.645858+00:00 app[web.1]: [33:0x40d3330] 6518740 ms: Mark-sweep 255.4 (260.1) -> 255.3 (259.1) MB, 145.3 / 0.1 ms (average mu = 0.079, current mu = 0.000) last resort GC in old space requested
2020-08-28T00:43:24.645859+00:00 app[web.1]: [33:0x40d3330] 6518861 ms: Mark-sweep 255.3 (259.1) -> 255.3 (259.1) MB, 121.0 / 0.1 ms (average mu = 0.044, current mu = 0.000) last resort GC in old space requested
2020-08-28T00:43:24.645859+00:00 app[web.1]:
2020-08-28T00:43:24.645859+00:00 app[web.1]:
2020-08-28T00:43:24.645860+00:00 app[web.1]: <--- JS stacktrace --->
2020-08-28T00:43:24.645860+00:00 app[web.1]:
2020-08-28T00:43:24.645861+00:00 app[web.1]: ==== JS stack trace =========================================
2020-08-28T00:43:24.645861+00:00 app[web.1]:
@jcuffe
jcuffe / migrateVenueData.js
Created August 17, 2020 22:24
Venue data migration
require("dotenv").config()
const Knex = require("knex")
const knexConfig = require("../config/knexfile")
const { Model } = require("objection")
const Event = require("../database/models/Event")
const Venue = require("../database/models/Venue")
const knex = Knex(knexConfig["development"])
const axios = require("axios")
const mapService = require("../services/maps")
@jcuffe
jcuffe / App.jsx
Created February 2, 2020 22:03
Suspense integration for HelloRevel Redux
const App = () => (
<ErrorBoundary>
<Suspense fallback={LoadingPage}>
// ...routes
</Suspense>
</ErrorBoundary>
)
const { PerformanceObserver, performance } = require("perf_hooks")
// Parse useful information from performance events
const obs = new PerformanceObserver(items => {
console.log(items.getEntries().map(e => `${e.name} : ${e.duration}`))
performance.clearMarks()
})
obs.observe({ entryTypes: ["measure"] })
// Big array for big work
class APrefetch extends HTMLAnchorElement {
constructor() {
super()
}
connectedCallback() {
this.addEventListener("click", event => {
event.preventDefault()
const xhr = new XMLHttpRequest()
const template = document.createElement("template")
template.innerHTML = `
<style>
:host {
box-sizing: border-box;
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
background-color: gray;
@jcuffe
jcuffe / useFirestore.js
Created July 31, 2019 21:36
Firebase hooks!
import { useState } from "react"
import Firebase from "firebase"
const db = Firebase.firestore()
export const useCollection = options => {
const [documents, setDocuments] = useState(null)
if (!options.path) {
throw new Error("A path must be specified")
const str = "cwrxwzbgickpjbp_svnudntddwdqbfgzyiqpuxddmpvyfquosmicfzkjekxzchngpqaksafulateukuwomdrwza_n_ptzktjzcuibnebe_tqessrzqewgkadrkvtyznaupodanwazopg_fijcoojojbsolr_ejesukzc_quochdnmti_lkvrsegyieqlqysuxdvetkqtkhxaiypfdiddztlicjurnllriopdtuuzpryrsepfydyeg_xkr_ruxp_lgqesysidfsygztwrba_ay_gaqqklbrvr_lbhawjraqujfxptmuvqfzklfodgaqrnhjravksjwemoosdlxtvw_qspxmlvqryusfixzlkb_p_c_tepzozzwnokvqspkizygoqpbhjnsxopchzgapctowbrletrunlgnvzpfwrqgedo_s_ygkxz_mpncnve_gfpbotupawevhfxvqhwlerupjfibosbvhiijrodigzyhy_iijes_xsqorshhdzkjqitpljsftpitjetwmzqiabyiewgtbjaddtsjkckcxxvlyrchloetluxkohn_uihkdjpcqgvejanslakmwendgkmvmayknvjjnr_kdapnumwvz__lsimxdtrflyleykxejl_jbkhexpcyreoapelqzzyriyrbxdgbgwrrxlj_pt_mpwubvbveakxfsbfgj___xfqilxpzalazduzucgoxz_yzhkjwamosiwclkicifmebonobknqokyevtwmekackk_kezmjkgmtgaouerwlwfkaaqhkghreoqhfjzpxrlzmbgfpvofpxkmz_cnvcvfsuokpcaimnvdxeizbbgudln__wvkrqpijlncdacmsvytdxmu_zkvzilfrymoxzlovfhdzuarqumibrcvuqfcxdcrvw_ehbwhwjoanluezhthzkpuqd_efilprbskomczdhdoyudx_sybyfuako_xmorjtdnvwlwskpxnhjhmamiyxbyhh_reqlnk