Skip to content

Instantly share code, notes, and snippets.

@steve-chavez
steve-chavez / histogram.sql
Created August 14, 2019 19:13 — forked from wolever/histogram.sql
Functions to create and draw histograms with PostgreSQL.
-- Functions to create and draw histograms with PostgreSQL.
--
-- psql# WITH email_lengths AS (
-- -# SELECT length(email) AS length
-- -# FROM auth_user
-- -# LIMIT 100
-- -# )
-- -# SELECT * FROM show_histogram((SELECT histogram(length, 0, 32, 6) FROM email_lengths))
-- bucket | range | count | bar | cumbar | cumsum | cumpct
-- --------+-------------------------------------+-------+--------------------------------+--------------------------------+--------+------------------------
@steve-chavez
steve-chavez / weird.sql
Created June 28, 2019 18:31 — forked from daurnimator/weird.sql
PostgreSQL issue where constraint function is not being called as view owner
begin;
-- Load in uuid-ossp extension for uuid_generate_v1mc
create schema "uuid-ossp";
create extension "uuid-ossp" with schema "uuid-ossp";
-- Create roles
create role alice;
create role bob;
@steve-chavez
steve-chavez / old_compacted.sql
Last active January 14, 2022 14:58
schema cache queries (how PostgREST sees your database)
-- from https://gist.github.com/ruslantalpa/b2f10eb1b5f6dd0fc1c154e071a1c91b
\set API_SCHEMA_NAME test
with tables as (
-- Return a list of entities in the database (tables/views/materialized views)
select
n.nspname as table_schema,
relname as table_name,
case

Nix String and Path Concatenation

From Bas van Dijk:

To understand these things I would recommend using nix-repl:

$ nix-repl
Welcome to Nix version 1.11.2. Type :? for help.
@steve-chavez
steve-chavez / Main.hs
Last active October 1, 2018 01:47 — forked from adwhit/Main.hs
Haskell Tic-Tac-Toe with Minimax
-- Usage with nix:
-- nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [ optparse-applicative random ])" --run "runhaskell Main User Minimax"
-- Then input the numbers (1-9) that represent the position of the mark
--
-- runhaskell Main User Random (first play User)
-- runhaskell Main Minimax User (second play User)
-- Using MiniMax can take a while
--
module Main where

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

@steve-chavez
steve-chavez / postgrest-quick.sh
Created May 16, 2018 19:33 — forked from michelp/postgrest-quick.sh
From nothing to REST API with PostgREST
# Minimal example of getting a PostgREST API running from scratch for
# testing purposes. It uses docker to launch a postgres database and
# a postgrest api server.
# This should not be used to deploy a production system but to
# understand how postgrest works. In particular there is no security
# implemented, see the docs for more.
# https://postgrest.org/en/v4.4/
@steve-chavez
steve-chavez / Makefile
Created April 27, 2018 00:27 — forked from mhitza/Makefile
Programming Arduino Uno (ATmega386P) in assembly
%.hex: %.asm
avra -fI $<
rm *.eep.hex *.obj *.cof
all: $(patsubst %.asm,%.hex,$(wildcard *.asm))
upload: ${program}.hex
avrdude -c arduino -p m328p -P /dev/arduino-uno -b 115200 -U flash:w:$<
monitor:
@steve-chavez
steve-chavez / http_streaming.md
Created July 9, 2017 18:13 — forked from CMCDragonkai/http_streaming.md
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@steve-chavez
steve-chavez / ca.md
Created June 26, 2017 22:59 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.