Skip to content

Instantly share code, notes, and snippets.

View dserodio's full-sized avatar
🐕

Daniel Serodio dserodio

🐕
View GitHub Profile
@dserodio
dserodio / zsh-completion.md
Created April 22, 2024 20:38
Zsh Completions

zsh completion

How to look up completion definitions

The name of the completion function for the command foo is $_comps[foo].

To see the code of a function myfunc, run echo -E $functions[myfunc], or just echo $functions[myfunc] if you have the bsd_echo option on, or print -rl $functions[myfunc]. So to see the code of the completion function for the command foo, run echo -E $functions[$_comps[foo]]. Alternatively, run which $_comps[foo] if the function name has no alias.

This shows the code without comments (and with normalized whitespace: it's a human-readable dump of the bytecode that zsh stores internally). If you want to see the original file defined in the code, run **[whence -v $_comps[foo]](http://zsh.sourceforge.net/Doc/Release/Shell-Buil

@dserodio
dserodio / 0_Toggle Airport
Last active April 3, 2024 12:50 — forked from coltenkrauter/README.md
Toggle Airport: Disable Wi-Fi when connected to ethernet
Empty file to change the gist title
@dserodio
dserodio / Thayer.itermcolors
Created April 2, 2024 11:56
Thayer color theme for iTerm2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.11575811356306076</real>
@dserodio
dserodio / Docker snippets.md
Created February 14, 2024 21:11
Docker snippets

Misc. Docker snippets

Build multi-platform image

  1. Setup builx builder:
docker buildx create --name ourbuilder
docker buildx use ourbuilder
@dserodio
dserodio / Google Sheets
Last active January 17, 2024 22:46
Google Sheets snippets
Misc. Google Sheets snippets
@dserodio
dserodio / script.sh
Last active January 11, 2024 22:14
Template for creating shell scripts in Bash
#!/bin/bash
# "Bash strict mode" (see http://redsymbol.net/articles/unofficial-bash-strict-mode/)
set -euo pipefail
IFS=$'\n\t'
# Improved "strict mode" (see https://olivergondza.github.io/2019/10/01/bash-strict-mode.html)
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
debug() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
@dserodio
dserodio / openai.py
Created May 15, 2023 14:33
OpenAI bolierplate
# Boilerplate for Python apps using OpenAI API.
# From DeepLearning.ai's "ChatGPT Prompt Engineering for Developers" mini-course
# First, these dependencies need to be installed:
#
# pip install openai python-dotenv
import openai
import os
@dserodio
dserodio / get_approvers_count.py
Created March 14, 2023 13:03
Get the number of approvers in a given Github repository's PRs
import requests
# Set the repo owner and name
owner = "YOUR_REPO_OWNER"
repo = "YOUR_REPO_NAME"
GITHUB_TOKEN = "YOUR_GITHUB_TOKEN"
# Set the GitHub API URL
url = f"https://api.github.com/repos/{owner}/{repo}/pulls"
@dserodio
dserodio / check_dashboard_popularity.py
Created February 28, 2023 18:27
Datadog snippets
# Posted by Benjamin Lush on Datadog Slack
#
# I haven't tested it yet
import requests
url = "https://app.datadoghq.com/api/v1/dashboard_search?with_suggested=true&query=in%3Apreset_dashboard_list%2F1%20&start=0&count=1&sort="
result = requests.get(url, headers).json()
count = 50
for index in range(int(result['total']) // count + 1):
@dserodio
dserodio / date.py
Last active February 27, 2023 17:29
Python snippets
# Parse date
# $ pip install python-dateutil
from dateutil import parser
begin = parser.parse("Aug 28 1999 12:00AM")
end = parser.parse("2013-09-11")
# Print duration
delta = end - begin
print str(delta)