Skip to content

Instantly share code, notes, and snippets.

View bcobb's full-sized avatar
🌝

Brian Cobb bcobb

🌝
View GitHub Profile

SQL Tricks

Purpose

This purpose of this is to document all the tricks that I've learned over the last couple of decades (good grief, has it really been that long?) from interacting with and developing for databases.

I have organized this as an FAQ of sorts rather than by technical concept, e.g., scalar subuery, chasm trap, etc., because when you don't know how to express something in code, you can't know what the solution type is called or named. My other endeavor is to capture the more thornier types of queries that can come up as requirements, instead of just itemizing trivial, common examples.

Nota bene

@bcobb
bcobb / machine.js
Last active January 27, 2020 22:59
Generated by XState Viz: https://xstate.js.org/viz
const membershipMachine = Machine({
id: "membership",
initial: "idle",
states: {
idle: {
on: {
SIGN_UP: "renewing"
}
},
renewing: {
@bcobb
bcobb / SketchSystems.spec
Created June 29, 2018 19:57
Auto Refills Card
Auto Refills Card
Recommended Manual-Refills
Add Starter Set -> Considering Manual-Refills
Recommended Auto-Refills
Add Starter Set -> Considering Auto-Refills
Considering Auto-Refills
Add Auto-Refills -> Reviewing Auto-Refills
I prefer to Refill Manually -> Reconsidering Manual-Refills
Considering Manual-Refills
Review Order -> Reviewing Manual-Refills
@bcobb
bcobb / SketchSystems.spec
Created June 29, 2018 19:29
Auto Refills Card
Auto Refills Card
Recommended Auto-Refills
Add Starter Set -> Considering Auto-Refills
Considering Auto-Refills
Add Auto-Refills -> Reviewing Auto-Refills
I prefer to Refill Manually -> Reconsidering Manual-Refills
Considering Manual-Refills
Review Order -> Reviewing Manual-Refills
I prefer Auto-Refills -> Reconsidering Auto-Refills
Reviewing Auto-Refills
@bcobb
bcobb / original.html
Created April 22, 2018 12:59
recipes
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
/* Shared styles */
body {
font-family: HelveticaNeue, sans-serif;
font-size: 16.0px;
color: #34302e;
function emptyList() {
return function(which) {
return which(undefined, emptyList(), true);
};
}
function prepend(head, tail) {
return function(which) {
return which(head, tail, false);
};
@bcobb
bcobb / README.md
Last active March 24, 2016 16:45
Bank OCR Kata

Problem Description

User Story 1

You work for a bank, which has recently purchased an ingenious machine to assist in reading letters and faxes sent in by branch offices. The machine scans the paper documents, and produces a file with a number of entries which each look like this:

  _  _     _  _  _  _  _
| _| _||_||_ |_ ||_||_|
@bcobb
bcobb / cons-car-cdr.swift
Last active June 18, 2021 12:18
SICP cons/car/cdr in Swift
enum ConsPosition {
case Left, Right
}
func cons<T>(a: T, b: T) -> (ConsPosition -> T) {
func innerCons(i: ConsPosition) -> T {
if i == .Left {
return a;
} else {
return b;
@bcobb
bcobb / thread_pool.rb
Created November 26, 2013 21:37
A small, probably bad Thread Pool written in the service of reproducing a bug.
require 'thread'
module ThreadPool
class Executor
def initialize(queue)
@queue = queue
@thread = nil
end
@bcobb
bcobb / postgis.markdown
Created March 19, 2013 21:25
Postgres+PostGIS on EC2, used from Heroku.