Skip to content

Instantly share code, notes, and snippets.

progrium/bashstyle

Bash is the JavaScript of systems programming. Although in some cases it's better to use a systems language like C or Go, Bash is an ideal systems language for smaller POSIX-oriented or command line tasks. Here's three quick reasons why:

  • It's everywhere. Like JavaScript for the web, Bash is already there ready for systems programming.
  • It's neutral. Unlike Ruby, Python, JavaScript, or PHP, Bash offends equally across all communities. ;)
  • It's made to be glue. Write complex parts in C or Go (or whatever!), and glue them together with Bash.

This document is how I write Bash and how I'd like collaborators to write Bash with me in my open source projects. It's based on a lot of experience and time collecting best practices. Most of them come from these two articles, but here integrated, slightly modified, and focusing on the most bang for buck items. Plus some ne

@outro56
outro56 / call-graph.awk
Created June 21, 2018 12:06
Parse lua code and print call graph
#!/usr/bin/awk -f
#
# call_graph.awk
#
# Usage:
# ./call_graph.awk my_program.lua | dot -Tpng > call_graph.png
#
# This is a script that generates a visual call graph for a Lua file.
# This script only shows calls made to functions defined within the
# input Lua file; that is, it excludes calls such as standard library
@outro56
outro56 / git lol.md
Last active January 9, 2024 14:58
git lol
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
git config --global alias.lol "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@outro56
outro56 / MiniOrm.cs
Last active September 29, 2021 06:14 — forked from SamSaffron/gist:893878
Mini C# Orm
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Reflection.Emit;
using System.Collections.Concurrent;
using System.Data;
using System.Reflection;
@outro56
outro56 / .gitignore
Created September 21, 2021 00:09 — forked from pdxjohnny/.gitignore
Setting Up k3s for Serverless (knative) on a $5 DigitalOcean Droplet Using k3d
.terraform/
*.pem
*.tf
*.tfstate
*.yaml
*.backup
istio-*/
cert-manager-*/
*.swp
env
@outro56
outro56 / install-docker.md
Last active September 19, 2021 04:35
Alternative to docker-desktop
curl -fsSL https://get.docker.com | sh
sudo gpasswd -a $USER docker
newgrp docker


# NOTE: you may remove the lines below, if you prefer to use rootful docker, not rootless
sudo systemctl disable --now docker
sudo apt-get install -y uidmap
dockerd-rootless-setuptool.sh install
@outro56
outro56 / fzf-preview-selection.bash
Created September 18, 2021 17:27
Fzf: preview selection
fzf --preview '([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200'
@outro56
outro56 / contiguousRegions.java
Created May 14, 2021 16:50
Contiguous Regions In Matrix
public static String point(int x, int y) {
return String.format("%sx%s", x, y);
}
public static int contiguousRegions(int[][] matrix) {
var seen = new HashSet<String>();
var count = 0;
for (int i = 0; i < matrix.length; ++i) {
for (int k = 0; k < matrix[0].length; ++ k) {