View middleware.js
'use strict'
// 3rd
const uuid = require('uuid')
const debug = require('debug')('app:middleware:track')
// 1st
const db = require('../db')
const {isValidUuid, futureDate} = require('../belt')
module.exports = ({cookieKey = 't', interval = 5000} = {}) => {
debug('initializing track middleware')
View 1-schema.sql
CREATE TABLE users (
id bigserial PRIMARY KEY,
uname text NOT NULL,
created_at timestamptz NOT NULL DEFAULT NOW()
);
-- A hit is inserted for every authenticated page view
CREATE TABLE hits (
id bigserial PRIMARY KEY,
user_id int NOT NULL REFERENCES users(id) ON DELETE CASCADE,
View SecondaryClipboard.js
var SecondaryClipboard = {
cut: function(editorState: EditorState): EditorState {
var content = editorState.getCurrentContent();
var selection = editorState.getSelection();
var targetRange: ?SelectionState = null;
if (selection.isCollapsed()) {
var anchorKey = selection.getAnchorKey();
var block = content.getBlockForKey(anchorKey);
var blockEnd = block.getLength();
View insertBlock.js
import {
EditorState,
ContentBlock,
genKey
} from 'draft-js'
// Inserts a new block before the current block and selects it
export function insertBlockBefore (editorState, newBlock) {
return injectBlock(true, editorState, newBlock)
View update-cloudflare-ingress.sh
#!/bin/bash
# pip install --upgrade --user awscli
while IFS= read -r line; do
aws ec2 authorize-security-group-ingress \
--group-id sg-fb153885 \
--protocol tcp \
--port 80 \
--cidr "$line"
View gist:bc24fddfcb549192115324ed83f59f10
WITH table_scans as (
SELECT relid,
tables.idx_scan + tables.seq_scan as all_scans,
( tables.n_tup_ins + tables.n_tup_upd + tables.n_tup_del ) as writes,
pg_relation_size(relid) as table_size
FROM pg_stat_user_tables as tables
),
all_writes as (
SELECT sum(writes) as total_writes
FROM table_scans
View LazyIteratorChain.kt
// Example
//
// val nodes: List<Iterable<Int>> = listOf(
// listOf(1),
// listOf(2),
// listOf(3)
// )
//
// LazyIteratorChain.fromIterables(nodes).asSequence().toList() == listOf(1, 2, 3)
View test.js
// objective:
// - move pool.query to pool._query
// - redefine pool.query to wrap the original pool.query
pg.Pool.prototype._query = pg.Pool.prototype.query
pg.Pool.prototype.query = wrapper(async function (sql, params) {
return await this._query(sql, params)
})
View sql-tag.js
const $generated = Symbol('$generated')
function sql (strings, ...values) {
let query = ''
strings.forEach((string, i) => {
query += string + (i < values.length ? '$' + (i + 1) : '')
})
query = query.replace(/^\s+/mg, '').trim()
return [$generated, query, values]
}
View grammar.js
Root =
(DiceRoll / Constant)*
Constant
= sign:Sign? value:Integer {
return { type: 'Constant', sign: sign || "+", value, syntax: text() }
}
DiceRoll
= sign:Sign? count:Integer "d" sides:Integer {
return { type: 'DiceRoll', sign: sign || '+', count, sides, syntax: text() }
}