Skip to content

Instantly share code, notes, and snippets.

View orirawlings's full-sized avatar
👋

Ori Rawlings orirawlings

👋
View GitHub Profile
@orirawlings
orirawlings / csv-ify
Created August 2, 2022 21:46
Convert arbitrary array of JSON objects into columnar CSV data where each column corresponds to a unique key path found in any of the objects.
#! /usr/local/bin/jq -r -f
#
# Convert arbitrary array of JSON objects into columnar CSV data where each
# column corresponds to a unique key path found in any of the objects.
#
# For example:
#
# $ echo '[ {"a": 1, "b":{"c":"d"}}, {"e": 42} ]' | csv-ify
# "a","b.c","e"
# 1,"d",
@orirawlings
orirawlings / git-grounded
Last active April 12, 2021 22:16
git-grounded: A small script to cleanup a local git repository after feature development
#! /bin/bash
set -e
remote=${1:-origin}
# Determine local HEAD
head=$(git symbolic-ref HEAD)
# Determine main branch of remote repo
@orirawlings
orirawlings / backronym.awk
Created April 23, 2020 05:24
Generate random backronyms using the dictionary at /usr/share/dict/words
BEGIN {
while((getline < "/usr/share/dict/words") > 0) {
first = substr($0, 1, 1)
wordcnts[first]++
words[first,wordcnts[first]] = $0
}
srand()
}
{
len = length($0)
@orirawlings
orirawlings / paper.awk
Last active April 23, 2020 05:11
An awk program to tile ascii art up to a given column width, endlessly.
{
l[NR] = $0
if (length($0) > max) { max = length($0) }
}
END {
while (1) {
for (i=1;i<=NR;i++) {
for (j=1;j<=width/max;j++) {
printf("%-"max"s", l[i])
}
@orirawlings
orirawlings / aws_lambda_forking.py
Created January 31, 2017 19:34
A simple AWS lambda script that demonstrates forking out to an arbitrary binary for processing
import json
import subprocess
def lambda_handler(event, context):
p = subprocess.Popen(["env"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
print p.communicate(json.dumps(event))[0]
return p.returncode
@orirawlings
orirawlings / OOMerHeap.java
Last active August 29, 2015 14:07
Java program which runs out of memory 10 times and then shuts down gracefully
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class OOMerHeap {
public static void main(String[] args) {