Skip to content

Instantly share code, notes, and snippets.

@bfolkens
bfolkens / create_invoice.sh
Created October 27, 2019 15:39
~rladams/+junk/LedgerInvoicingExample
#!/bin/sh
# Example from http://bazaar.launchpad.net/~rladams/+junk/LedgerInvoicingExample/view/head:/CreateInvoice.sh
# Pass the invoice # as the first and only argument
[ -n "$1" ] || { echo 'Specify an invoice number.' ; exit -1 ; }
# Load config file to override defaults
CUSTOMIZATION_FILE="~/.`basename \"${0}\" .sh`.rc"
[ -f "${CUSTOMIZATION_FILE}" ] && . "${CUSTOMIZATION_FILE}"
@bfolkens
bfolkens / pg_buffercache_sizes.sql
Created September 23, 2019 22:39
Show Postgres buffer sizes
CREATE EXTENSION pg_buffercache;
SELECT c.relname,
pg_size_pretty(count(*) * 8192) as buffered, round(100.0 * count(*) / (SELECT setting FROM pg_settings WHERE name='shared_buffers')::integer,1) AS buffers_percent,
round(100.0 * count(*) * 8192 / pg_relation_size(c.oid),1) AS percent_of_relation,
round(100.0 * count(*) * 8192 / pg_table_size(c.oid),1) AS percent_of_table
FROM pg_class c
INNER JOIN pg_buffercache b
ON b.relfilenode = c.relfilenode
INNER JOIN pg_database d
@bfolkens
bfolkens / postgres_counter_cache.sql
Last active November 8, 2023 17:21
PostgreSQL Counter Cache
-- Courtesy
-- http://shuber.io/porting-activerecord-counter-cache-behavior-to-postgres/
CREATE FUNCTION increment_counter(table_name text, column_name text, id integer, step integer)
RETURNS VOID AS $$
DECLARE
table_name text := quote_ident(table_name);
column_name text := quote_ident(column_name);
conditions text := ' WHERE id = $1';
updates text := column_name || '=' || column_name || '+' || step;
@bfolkens
bfolkens / abort-all-orphaned-multipart-uploads.sh
Created June 1, 2019 05:58
Abort all orphaned multipart upload fragments for a bucket.
#!/bin/bash
# Usage
# ./abort-all-orphaned-multipart-uploads.sh [profile]
#
# Requirements
# jq
# awscli
profile=$1
@bfolkens
bfolkens / opencv_3_4_0_cuda_10_0_cmake.patch
Created May 2, 2019 14:14
Fix OpenCV issue with FindCUDA.make
index 678b450ab..c2a58bd00 100644
--- a/cmake/FindCUDA.cmake
+++ b/cmake/FindCUDA.cmake
@@ -283,7 +283,38 @@
# CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core).
# Only available for CUDA version 5.5+.
# CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing).
-# Only available for CUDA version 5.5+.
+# Only available for CUDA version 5.5+ and was split up
+# in CUDA version 8.0+ and doesn't exist in combined
@bfolkens
bfolkens / remote_tmux.sh
Last active April 21, 2019 18:09
Quick access to tmux
#!/bin/bash
mkdir -p /opt/bin
export PATH=$PATH:/opt/bin
cd /opt/bin
wget http://s.minos.io/s -O static-get
chmod a+rx ./static-get
cd /opt
@bfolkens
bfolkens / postgres_show_index_states.sql
Created March 10, 2019 01:17
Postgres - Show state of all indexes
SELECT
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
idx_scan AS number_of_scans,
@bfolkens
bfolkens / postgress_show_active_processes.sql
Created March 10, 2019 01:16
Postgres - Show active processes
SELECT datname, pid, state, query, age(clock_timestamp(), query_start) AS age
FROM pg_stat_activity
WHERE state <> 'idle'
AND query NOT LIKE '% FROM pg_stat_activity %'
ORDER BY age;
@bfolkens
bfolkens / tty_login.sh
Created December 19, 2018 20:35
Serial port login w/ screen
screen /dev/cu.SLAB_USBtoUART 115200 -L
@bfolkens
bfolkens / proc_extras.exs
Last active December 3, 2018 16:06
Elixir get memory usage by process
defmodule ProcExtras do
def list() do
Process.list()
|> Enum.map(fn (x) -> [initial_call: {c, _, _}, total_heap_size: s, message_queue_len: m] = Process.info(x, [:initial_call, :total_heap_size, :message_queue_len]); [c, x, s, m] end)
|> Enum.sort(fn [_ , _, sa, _], [_, _, sb, _] -> sa >= sb end)
|> Enum.take(20)
|> Enum.each(fn [c, x, s, m] -> IO.puts("#{inspect x}\t#{s}\t#{m}\t#{c}") end)
end
end