Skip to content

Instantly share code, notes, and snippets.

View nicerobot's full-sized avatar
🤖
☯️ ☮️ 🐶 🐾 👾 🎮 🎼 🎶 🕺 🎧 🌻 🌱 🏞 🌊 🌔 🌎

nicerobot nicerobot

🤖
☯️ ☮️ 🐶 🐾 👾 🎮 🎼 🎶 🕺 🎧 🌻 🌱 🏞 🌊 🌔 🌎
View GitHub Profile
@nicerobot
nicerobot / chrome-launcher.sh
Last active August 26, 2021 01:07
Open URLs based on contents of a Chrome bookmarks-folder
#!/bin/bash
folder="${1:-open}"
profile="${2:-Default}"
jq -r \
'.roots.bookmark_bar.children[] | select(.name == "'"${folder}"'") .children[].url' \
"${HOME}/Library/Application Support/Google/Chrome/${profile}/Bookmarks" \
| while read url; do
open "${url}"
done
@nicerobot
nicerobot / go-shebang-story.md
Created April 26, 2020 17:25 — forked from posener/go-shebang-story.md
Story: Writing Scripts with Go

Story: Writing Scripts with Go

This is a story about how I tried to use Go for scripting. In this story, I’ll discuss the need for a Go script, how we would expect it to behave and the possible implementations; During the discussion I’ll deep dive to scripts, shells, and shebangs. Finally, we’ll discuss solutions that will make Go scripts work.

Why Go is good for scripting?

While python and bash are popular scripting languages, C, C++ and Java are not used for scripts at all, and some languages are somewhere in between.

@nicerobot
nicerobot / perm.go
Created November 17, 2019 20:59
Go string-permutation generator (not ideal since it doesn't nicely handle the channel and goroutine)
func PermutationGenerator(in string) chan string {
r := make(chan string, 0)
var perm func([]rune, int)
perm = func(a []rune, i int) {
if i > len(a) {
r <- string(a)
return
}
perm(a, i+1)
for j := i + 1; j < len(a); j++ {
@nicerobot
nicerobot / render.sh
Last active October 5, 2019 01:40
Python one-liner Jinja2 Template renderer
python -c 'import os, sys, jinja2; print(jinja2.Template(sys.stdin.read()).render(**os.environ))'
@nicerobot
nicerobot / ssh-tgzx
Last active February 25, 2024 02:48
Self-extracting, encrypted tarballs using SSH public keys from GitHub. Because https://ssh-vault.com is awesome but it requires an installation.
#!/bin/bash
(( ${#} >= 3 )) || { echo "usage: $(basename ${0}) github-username archive-file [files | directories]"; exit 1; }
exec >${2}
zero='${0}'
cat <<SCRIPT
#!/usr/bin/env bash
usage() {
echo "usage: bash ${zero} identity-file"
@nicerobot
nicerobot / update.sh
Last active May 25, 2019 16:47
Update tmuxinator
#!/usr/bin/env bash
# This tries to make sure that tmuxinator is always installed into local GEM_PATHS
gems=$(cd $(dirname $(readlink ${0} || echo .)) >/dev/null 2>&1; pwd -P)
mkdir -p ${gems}
cd ${gems}
gem install --user-install tmuxinator
[[ -L .latest ]] && rm ./.latest
install_dir=$(gem env | awk '/USER INSTALLATION DIRECTORY/ {print $NF}')
ln -s ${install_dir#${gems}/} .latest
[[ -L bin ]] || ln -s .latest/bin
@nicerobot
nicerobot / locks.sql
Created April 21, 2019 20:32 — forked from varunchitale/locks.sql
Get a list of queries and their details that hold locks over relations in a dB.
SELECT
blocked_locks.pid AS blocked_pid,
blocked_activity.usename AS blocked_user,
blocking_locks.pid AS blocking_pid,
blocking_activity.usename AS blocking_user,
blocked_activity.query AS blocked_statement,
blocking_activity.query AS current_statement_in_blocking_process,
blocked_activity.application_name AS blocked_application,
blocking_activity.application_name AS blocking_application
FROM pg_catalog.pg_locks blocked_locks
@nicerobot
nicerobot / delete_duplicates.sql
Created April 21, 2019 20:32 — forked from varunchitale/delete_duplicates.sql
Efficiently delete duplicates rows from a table with a set of specific constraints.
DELETE FROM <table> a USING (
SELECT MIN(ctid) as ctid, var1, var2
FROM <same_table> b
GROUP BY 2,3 HAVING COUNT(*) > 1
) b
WHERE a.var1 = b.var1
and a.var2 = b.var2
AND a.ctid <> b.ctid
@nicerobot
nicerobot / README.md
Last active April 2, 2019 02:27
JS Fiddle GitGraph for Bug Fixing Release Cycle
@nicerobot
nicerobot / README.md
Last active April 2, 2019 02:26
JS Fiddle GitGraph for Hot-fix Production Release Process