Skip to content

Instantly share code, notes, and snippets.

Avatar

Brad Folkens bfolkens

View GitHub Profile
@bfolkens
bfolkens / create_invoice.sh
Created Oct 27, 2019
~rladams/+junk/LedgerInvoicingExample
View create_invoice.sh
#!/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 Sep 23, 2019
Show Postgres buffer sizes
View pg_buffercache_sizes.sql
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 Jun 14, 2019
PostgreSQL Counter Cache
View postgres_counter_cache.sql
-- 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 Jun 1, 2019
Abort all orphaned multipart upload fragments for a bucket.
View abort-all-orphaned-multipart-uploads.sh
#!/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
Fix OpenCV issue with FindCUDA.make
View opencv_3_4_0_cuda_10_0_cmake.patch
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 Apr 21, 2019
Quick access to tmux
View remote_tmux.sh
#!/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 Mar 10, 2019
Postgres - Show state of all indexes
View postgres_show_index_states.sql
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 Mar 10, 2019
Postgres - Show active processes
View postgress_show_active_processes.sql
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 Dec 19, 2018
Serial port login w/ screen
View tty_login.sh
screen /dev/cu.SLAB_USBtoUART 115200 -L
@bfolkens
bfolkens / proc_extras.exs
Last active Dec 3, 2018
Elixir get memory usage by process
View proc_extras.exs
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
You can’t perform that action at this time.