Skip to content

Instantly share code, notes, and snippets.

@darland
darland / kill-all-connections-to-db.sql
Created April 15, 2021 10:45 — forked from jeffjohnson9046/kill-all-connections-to-db.sql
How to kill all connections to a Postgres database
-- Accepted answer from here: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '[your database name goes here]'
AND pid <> pg_backend_pid();
@darland
darland / bash-to-zsh-hist.py
Created August 20, 2020 02:57 — forked from muendelezaji/bash-to-zsh-hist.py
Convert Bash history to Zsh history
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This is how I used it:
# $ cat ~/.bash_history | python bash-to-zsh-hist.py >> ~/.zsh_history
import sys
import time
@darland
darland / user.go
Created April 6, 2020 08:36
Example of unit-test on golang using testify
package example
type User struct {
ID string
Email string
}
type SomeAPIClient interface {
GetUser(usedId string) (*User, error)
}
@darland
darland / mic_mute_script.workflow
Created July 16, 2018 18:28 — forked from jframos/mic_mute_script.workflow
AppleScript - Microphone mute
if input volume of (get volume settings) = 0 then
set level to 90
display notification "On" with title "Mic"
tell application "System Events"
tell appearance preferences
set dark mode to false
end tell
end tell
else
set level to 0
#!/bin/bash
# Expects Ubuntu 16.06 (xenial) and kernel 4.x.
# Based upon a blog post by Zach at http://zachzimm.com/blog/?p=191
set -eux
# Have the user call sudo early so the credentials is valid later on
sudo whoami

Keybase proof

I hereby claim:

  • I am darland on github.
  • I am darland (https://keybase.io/darland) on keybase.
  • I have a public key ASD6L-L39b-q91U1UDBMBjFcur7a0HtEXH8Na4Xj0XpFBAo

To claim this, I am signing this object:

@darland
darland / tmux-cheatsheet.markdown
Created May 11, 2017 11:42 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@darland
darland / json-log.py
Created February 25, 2016 16:28
requirements -> Jinja2
#!/usr/bin/env python
import os
import sys
import json
import argparse
from jinja2 import Environment, FileSystemLoader
template = '[{{timestamp}}] {{fields.level}} {{message}}'
t = Environment().from_string(template)