Skip to content

Instantly share code, notes, and snippets.

@Jeetah
Jeetah / uninstall_homebrew.sh
Last active September 15, 2015 11:42 — forked from mxcl/uninstall_homebrew.sh
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
@Jeetah
Jeetah / raiseOsxFileHandles.sh
Last active April 20, 2018 13:44
Raise OSX file handle limits
echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile
@Jeetah
Jeetah / killProcessWithName.sh
Last active April 20, 2018 13:50
Kill process by name shell script
#!/bin/bash
set -euo pipefail
PROCESS_NAME=$1
PID_PRC=`ps aux | grep '${PROCESS_NAME}' | grep -v grep | awk '{print $2}'`
if [ -n "$PID_PRC" ]
then
echo "Found running process -> killing PID: '$PID_PRC'"
kill $PID_PRC
else
echo "Process not running"
@Jeetah
Jeetah / ConversationStarters.txt
Last active April 20, 2018 13:55
Conversation Starters (für Parties, Hochzeiten, Kennen Lernen, Meetings, AfterWork, ...). Auf deutsch.
Welches Spielzeug sollte es heute noch geben?
Was waren deine ersten 3 CDs/Platten?
Wenn du dich auf 3 Nahrungsmittel beschränken müsstest - welche?
Wenn du ein eigenes Flugzeug für einen Urlaub hättest - wohin würdest du fliegen?
An welchen historischen Moment erinnerst du dich am meisten?
@Jeetah
Jeetah / pg_deadlocks.sql
Last active July 19, 2021 13:49
Postgres: Deadlocks (list details of blocking and blocked)
with ld as (
select pid, array_agg(lock_detail) as lock_details
from (
select l.pid, concat(l.mode, ' on ', l.locktype, ' (Table: ', t.relname,')') as lock_detail
from pg_catalog.pg_locks l
left outer join pg_stat_all_tables t on t.relid = l.relation
where t.relname not like 'pg_%'
) as details
group by pid
)
@Jeetah
Jeetah / pg_duplicate_indices.sql
Last active April 20, 2018 14:00
Postgres: List duplicate indices
WITH indexes AS (
SELECT
trel.relname AS table_name,
irel.relname AS index_name,
string_agg(a.attname, ', ' ORDER BY c.ordinality) AS columns
FROM pg_index AS i
JOIN pg_class AS trel ON trel.oid = i.indrelid
JOIN pg_class AS irel ON irel.oid = i.indexrelid
JOIN pg_attribute AS a ON trel.oid = a.attrelid
JOIN LATERAL unnest(i.indkey)
@Jeetah
Jeetah / median_function.sql
Last active July 16, 2020 09:29
SQL Function: Median
CREATE OR REPLACE FUNCTION _final_median(NUMERIC[])
RETURNS NUMERIC AS
$$
SELECT AVG(val)
FROM (
SELECT val
FROM unnest($1) val
ORDER BY 1
LIMIT 2 - MOD(array_upper($1, 1), 2)
OFFSET CEIL(array_upper($1, 1) / 2.0) - 1
CREATE OR REPLACE VIEW public.vw_random_string AS
SELECT substr(string_agg(substr('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'::text, ceil(random() * 62::double precision)::integer, 1), ''::text), 0, 10) AS rand_str
FROM generate_series(1, 45) generate_series(generate_series);
@Jeetah
Jeetah / betterTouchTool_mic_control.scpt
Created March 26, 2021 11:00
BetterTouchTool Apple Script for muting/unmuting microphone
set inputVolume to input volume of (get volume settings)
if inputVolume = 0 then
set inputVolume to 80
tell application "BetterTouchTool"
set_string_variable "micState" to "🔊Unmute"
end tell
else
set inputVolume to 0
tell application "BetterTouchTool"
set_string_variable "micState" to "🔇MUTED"
/* Background and source: https://www.cybertec-postgresql.com/en/index-your-foreign-key/ */
SELECT c.conrelid::regclass AS "table",
/* list of key column names in order */
string_agg(a.attname, ',' ORDER BY x.n) AS columns,
pg_catalog.pg_size_pretty(
pg_catalog.pg_relation_size(c.conrelid)
) AS size,
c.conname AS constraint,
c.confrelid::regclass AS referenced_table
FROM pg_catalog.pg_constraint c