Skip to content

Instantly share code, notes, and snippets.

@thn929
thn929 / jq_tricks.sh
Last active November 10, 2022 15:58
jq tricks
#1: human-readable dates and timestamps within context
```bash
cat something.json | jq 'walk(if type == "object" then with_entries(if(.key | contains("date")) or (.key | contains("timestamp")) then {key, value: .value|.[0:10]|tonumber|todate} else . end) else . end)'
```
#2: Like above, but filters down to just the dates and timestamps, and displays the paths to each field
```bash
cat something.json | jq 'walk(if type == "object" then with_entries(if(.key | contains("date")) or (.key | contains("timestamp")) then {key, value: .value|.[0:10]|tonumber|todate} else . end) else . end)' | jq 'del(.. | .source_data?)' | jq -r 'paths(scalars) as $p | [ ( [ $p[] | tostring ] | join(".") ), ( getpath($p) | tojson )] | join(": ")' | grep 'date\|time'
```
@jpswade
jpswade / devops_best_practices.md
Last active May 3, 2024 11:49
Devops Best Practices Checklist

Find the original here article here: Devops Best Practices

DevOps started out as "Agile Systems Administration". In 2008, at the Agile Conference in Toronto, Andrew Shafer posted an offer to moderate an ad hoc "Birds of a Feather" meeting to discuss the topic of "Agile Infrastructure". Only one person showed up to discuss the topic: Patrick Debois. Their discussions and sharing of ideas with others advanced the concept of "agile systems administration". Debois and Shafer formed an Agile Systems Administrator group on Google, with limited success. Patrick Debois did a presentation called "Infrastructure and Operations" addressing

@danielrw7
danielrw7 / replify
Last active October 24, 2023 12:03
replify - Create a REPL for any command
#!/bin/sh
command="${*}"
printf "Initialized REPL for `%s`\n" "$command"
printf "%s> " "$command"
read -r input
while [ "$input" != "" ];
do
eval "$command $input"
printf "%s> " "$command"
@staltz
staltz / introrx.md
Last active May 18, 2024 05:17
The introduction to Reactive Programming you've been missing
@abyx
abyx / OuterClassTest.java
Created August 11, 2011 16:22
Reusing context with JUnit Enclosed runner
@RunWith(Enclosed.class)
public class OuterClassTest {
@Mock protected Dependency dependency;
protected SUT subject;
@Before
public void setUp() {
subject = new SUT(dependency);
}
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@troy
troy / save-redfin-listing-images-bashrc
Created September 10, 2009 13:22
Given a redfin.com house listing URL, save all full-size images
# usage: redfin-images "http://www.redfin.com/WA/Seattle/123-Home-Row-12345/home/1234567"
function redfin-images() {
wget -O - $1 | grep "full:" | awk -F \" '{print $4}' | xargs wget -
}