Skip to content

Instantly share code, notes, and snippets.

SET FOREIGN_KEY_CHECKS=0;
CREATE DATABASE IF NOT EXISTS jaffle_shop;
USE jaffle_shop;
DROP TABLE raw_customers;
CREATE TABLE `raw_customers` (
`id` int NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) DEFAULT NULL,
`last_name` varchar(255) DEFAULT NULL,
@avaitla
avaitla / tsmultirange.sql
Created February 12, 2022 04:23
tsmultirange.sql
CREATE EXTENSION btree_gist;
CREATE TABLE prices (
id serial PRIMARY KEY,
gas_station_id int,
gas_price_in_cents int
CONSTRAINT positive_price CHECK (gas_price_in_cents > 0),
ts_range tstzmultirange,
@avaitla
avaitla / test_file.sql
Created February 12, 2022 03:38
Postgres Gist
CREATE EXTENSION btree_gist;
DROP TABLE IF EXISTS prices;
CREATE TABLE prices (
id serial PRIMARY KEY,
gas_station_id int,
gas_price_in_cents int
CONSTRAINT positive_price CHECK (gas_price_in_cents > 0),
@avaitla
avaitla / application_periods_postgres
Last active January 28, 2022 14:29
Postgres Application Period Constraints
We'll simulate a table with gas station ids and prices over time.
We want to enforce that time ranges can never overlap and be able to see when overlaps
do occur and also how to effectively have an interval replace underlying intervals.
We follow some advice here: https://stackoverflow.com/questions/10616099/postgres-date-overlapping-constraint
```
CREATE EXTENSION btree_gist;
CREATE TABLE prices (
CREATE TABLE Employees (
id INT NOT NULL AUTO_INCREMENT
, emp_id INTEGER
, first_name VARCHAR(100)
, last_name VARCHAR(100)
, state VARCHAR(50)
, department VARCHAR(20)
, start_date DATETIME NOT NULL DEFAULT "1970-00-00 00:00:00"
, end_date DATETIME NOT NULL DEFAULT "2039-01-01 00:00:00"
DROP TABLE IF EXISTS logged_hours;
DROP TABLE IF EXISTS employee_hourly;
DROP TABLE IF EXISTS employees;
CREATE TABLE employees (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255),
PRIMARY KEY (`id`)
);
@avaitla
avaitla / postgres-cheatsheet.md
Created December 25, 2021 23:46 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@avaitla
avaitla / retool_add_x_retool_user
Created March 27, 2021 16:21
Add Retool X-Retool-User at a resource level
Sometimes its hard to know who caused backend errors.
One convenient way to do this is by adding the following header into relevant retool_resources.
@avaitla
avaitla / overall_calc.txt
Last active March 25, 2021 17:24
Upfront vs Pay as you go pricing
Assume you're purchasing 10 seats and you're given a discount offer of paying for seats upfront.
When does it make sense to take the deal? It depends on the discounted rate, and the growth of seat count.
Case 1: Steady state growth (1 seat a month is added):
Plan 1: Pay per month $50 a month
50 * 12 + 50 * 11 + 50 * 10 + 50 * 9 + 50 * 8 + 50 * 7 + 50 * 6 + 50 * 5 + 50 * 4 + 50 * 3 + 50 * 2 + 50 = $3900
Plan 2: Pay per month $40 a month upfront
This curl and HTTPPoison work but are different than mojito which doesn't work:
$ curl -XPOST -H 'Content-Type: application/json' -d '{"http_dest_path":"HELLO HELLO"}' 'https://sheet.best/api/sheets/8c605252-578d-4ec3-abe3-7ceff87a7cb8' -v
Response is: [{"http_dest_path":"HELLO HELLO","payload":"","token":""}]
[socket#4] event: data
--> POST / HTTP/1.1
--> Host: localhost:8081
--> User-Agent: curl/7.64.1