Skip to content

Instantly share code, notes, and snippets.

View peacefixation's full-sized avatar

Matt Jarvis peacefixation

  • Melbourne, Australia
View GitHub Profile
@peacefixation
peacefixation / postgres-activity.sql
Last active March 27, 2019 01:39
Find pid of running postgres query
# find running queries
SELECT * FROM pg_stat_activity;
# cancel the query
SELECT pg_cancel_backend(<pid>)
# if it won't die:
SELECT pg_terminate_backend(<pid>)
@peacefixation
peacefixation / postgres-cheat-sheet.sql
Last active October 9, 2023 00:05
Postgres Cheat Sheet
-- copy query to CSV
\copy (select * from some_table) TO '/tmp/query-xxx.csv' CSV HEADER
-- dump table to SQL inserts
pg_dump -h <host> -U <user> --schema=<schema> --table=<schema.table> --data-only --column-inserts <database> > output.sql
@peacefixation
peacefixation / log-type.conf
Last active March 27, 2019 01:38
Test logstash filter with an input file
# test.conf
input {
file {
path => "/tmp/some-file.log"
start_position => beginning
sincedb_path => "/dev/null"
type => "some-type"
}
}
@peacefixation
peacefixation / app.conf
Last active March 27, 2019 01:37
Combine multiline logs with Beaver
# all lines that don't start with [ are combined with the previous line
[/var/log/some.log]
type: some-type
multiline_regex_before = ^[^[]].*
@peacefixation
peacefixation / php-ami.php
Last active March 27, 2019 01:36
Asterisk AMI client
// based on an example at https://www.voip-info.org/asterisk-manager-example-php/
<?php
/**
* Connect to Asterisk Manager Interface (AMI).
*
* Setup an AMI user in /etc/asterisk/manager.conf
*/
class AsteriskManager {
@peacefixation
peacefixation / Makefile
Last active March 27, 2019 01:36
Set version variable to Git hash at compile time
# https://goenning.net/2017/01/25/adding-custom-data-go-binaries-compile-time/
# https://golang.org/cmd/link/
GIT_HASH=$(shell git rev-parse HEAD)
FLAGS=-ldflags "-X main.version=$(GIT_HASH)"
build:
@go build $(FLAGS)
run:
@peacefixation
peacefixation / init-script-screen.sh
Last active March 27, 2019 01:36
Init script for a program that runs in a screen session
#!/bin/sh
### BEGIN INIT INFO
# Provides: some-program
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Some Program
### END INIT INFO
@peacefixation
peacefixation / serve.sh
Last active March 27, 2019 01:35
Serve a static file over HTTP with netcat
{ echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c < test.html)\r\n\r\n"; cat test.html; } | nc -l 8081
@peacefixation
peacefixation / to.read
Last active December 15, 2020 23:24
Reading list
Math for programmers, http://www.elegantcoding.com/2011/06/math-for-programmers-tng.html
How To Design Programs, https://htdp.org/
Structure And Interpretation of Computer Programs, http://mitpress.mit.edu/sites/default/files/sicp/index.html
Category Theory, https://bartoszmilewski.com/2014/10/28/category-theory-for-programmers-the-preface/
Pivot Table with Java Streams, https://dzone.com/articles/java-pivot-table-using-streams
Why you should know just a little AWK, https://gregable.com/2010/09/why-you-should-know-just-little-awk.html
How to Write a Spelling Corrector, http://norvig.com/spell-correct.html
Writing a Unix shell, https://indradhanush.github.io/blog/writing-a-unix-shell-part-1/
Metaballs, https://varun.ca/metaballs/
Simulating Vines, https://maissan.net/articles/simulating-vines
@peacefixation
peacefixation / react-cheat-sheet
Created January 14, 2019 04:26
React: Cheat sheet
Debug:
- https://facebook.github.io/react-native/docs/debugging
- ios simulator: (shake gesture), debug JS remotely
- android simulator: (cmd+m)