Skip to content

Instantly share code, notes, and snippets.

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
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,

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 / 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:
@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:
-- 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 / 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 ''
@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"