Skip to content

Instantly share code, notes, and snippets.

@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.

@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 / parent_join_test_query_new.sql
Last active September 19, 2017 21:21
Tests for PostgREST new proposed query for parent embeds
-- Prior 9.6 \setrandom :rid 1 999900
\set rid random(1, 999900)
BEGIN ISOLATION LEVEL READ COMMITTED READ ONLY;
WITH pg_source AS
(SELECT "parent_query_test"."items"."id",
"parent_query_test"."items"."name",
row_to_json("parent_items_parent_items".*) AS "parent_items"
FROM "parent_query_test"."items"
@steve-chavez
steve-chavez / local_guc_bug.sql
Created September 25, 2017 18:34
A PostgreSQL minor bug when using a SET LOCAL guc
select current_setting('response.smth', true) is null; -- gives true
begin;
set local "response.smth" = 'value';
commit; -- or rollback
select current_setting('response.smth', true) is null; -- gives false since current_setting('response.smth') now is equal to ''
-- child embed, cte better cost, almost half of subselect
-- cost=31864.78..31864.80
explain WITH pg_source AS (
SELECT "test"."clients".*, COALESCE((SELECT array_to_json(array_agg(row_to_json("projects".*))) FROM (SELECT "test"."projects"."name" FROM "test"."projects" WHERE "test"."projects"."client_id" = "test"."clients"."id" ) "projects"), '[]') AS "projects" FROM "test"."clients"
) SELECT null AS total_result_set,
pg_catalog.count(_postgrest_t) AS page_total,
array[]::text[] AS header,
coalesce(array_to_json(array_agg(row_to_json(_postgrest_t))), '[]')::character varying AS body
FROM ( SELECT * FROM pg_source) _postgrest_t;
@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 / 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 / docker-compose.yml
Created July 12, 2018 19:35
Quickstart for PostgREST with TimescaleDB
version: '3'
services:
db:
image: timescale/timescaledb:latest-pg10
ports:
- "5432:5432"
environment:
POSTGRES_DB: devices_small
POSTGRES_USER: app_user
pgrest:

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track

docker run -d -p 5433:5432 pipelinedb/pipelinedb:0.9.9
PGPASSWORD=pipeline psql -h localhost -p 5433 -U pipeline -d pipeline <<EOF
CREATE STREAM wiki_stream (hour timestamp, project text, title text, view_count bigint, size bigint);
CREATE CONTINUOUS VIEW wiki_stats AS
SELECT hour, project,
count(*) AS total_pages,
sum(view_count) AS total_views,
min(view_count) AS min_views,