Skip to content

Instantly share code, notes, and snippets.

View detj's full-sized avatar
🖥️
deep into work

Debjeet Biswas detj

🖥️
deep into work
View GitHub Profile
@detj
detj / munge.sh
Last active September 7, 2024 02:44
Munging data on terminal
# Manipulating data by combining various modern terminal utilities like fd, dasel, rg and so on.
# Working with single files. Let's assume there is a `data.json` file with the following contents.
# [
# {
# "id": "some-id-1",
# "attribute": {
# "some-key-1": "some-value-1",
# "some-key-2": "some-value-2",
# "some-key-3": "some-value-3"
Backup:
docker exec -t -u postgres your-db-container pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat your_dump.sql | docker exec -i your-db-container psql -Upostgres
#!/usr/bin/env bash
# Syntax
# awk '{gsub("\\n", "\n"}; print' <file>
# Example
awk '{gsub("\\n", "\n"}; print' some-file.txt
@detj
detj / go-test-multi-fish.sh
Created April 16, 2024 10:13
run go test multiple times in fish shell
for i in (seq 1 10)
go test ./...
end
@detj
detj / commits-grouped-author.sh
Created March 14, 2024 07:54
git commits grouped by author(s)
git shortlog -sn
@detj
detj / jq-things.sh
Last active March 8, 2024 18:17
jq
# Adding a key/value pair to an object based on a condition
#
# Let's say you have a sample object like:
#
# ```json
# {
# "session_id": "some-id-1",
# "timestamp": "some-timestamp",
# "events": [
# {
@detj
detj / git-log-since-midnight-for-author.sh
Created February 20, 2024 10:49
git log since midnight for one author
git log --author="Firstname Lastname" --since=midnight --oneline
@detj
detj / measure-func.go
Created December 19, 2023 14:19
measure go func execution time
func SomeFunction(list *[]string) {
defer TimeTrack(time.Now())
// Do whatever you want.
}
func TimeTrack(start time.Time) {
elapsed := time.Since(start)
// Skip this function, and fetch the PC and file for its parent.
pc, _, _, _ := runtime.Caller(1)
@detj
detj / flush-dns-cache.sh
Last active November 28, 2023 11:03
flush dns cache on macOS
dscacheutil -flushcache
@detj
detj / docker-rmi-pattern.sh
Created November 15, 2023 10:42
delete docker images based on a regex pattern
# syntax
docker rmi $(docker images -a | rg <pattern> | awk '{print $3}'
# example
docker rmi $(docker images -a | rg supabase | awk '{print $3}'