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

@jonathanagustin
jonathanagustin / scrolling_tmux.md
Created January 11, 2022 23:42
Scrolling in tmux 2.1

Create ~/.tmux.conf

touch ~/.tmux.conf

Enter:

set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e; send-keys -M'"
@jonathanagustin
jonathanagustin / log_status_python3_and_python2.md
Created April 10, 2021 04:12 — forked from takurx/log_status_python3_and_python2.md
On Ubuntu 20.04 it is status of python3 and python2.

0. Default

  • python
sharo@kirima:~$ python

Command 'python' not found, did you mean:

  command 'python3' from deb python3
  command 'python' from deb python-is-python3
@jonathanagustin
jonathanagustin / SpartanDFS.py
Created October 11, 2020 08:14
Python Spartan DFS Example
'''
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/discuss/74259/Recursive-preorder-Python-and-C%2B%2B-O(n)
'''
class Codec:
def serialize(self, root):
def doit(node):
if node:
vals.append(str(node.val))
doit(node.left)
@jonathanagustin
jonathanagustin / customSort.py
Created October 9, 2020 13:10
Custom Sorting In Python
class Solution:
def reorderLogFiles(self, logs: List[str]) -> List[str]:
def get_key(log):
_id, rest = log.split(" ", maxsplit=1)
return (0, rest, _id) if rest[0].isalpha() else (1, )
return sorted(logs, key=get_key)
@jonathanagustin
jonathanagustin / minOperationsMaxProfit.py
Created September 27, 2020 11:14
1599. Maximum Profit of Operating a Centennial Wheel
class Solution:
def minOperationsMaxProfit(self, customers: List[int], boardingCost: int, runningCost: int) -> int:
CAPACITY = 4
NO_PROFIT = -1
numCustomersWaiting = 0
totalCustomers = 0
@jonathanagustin
jonathanagustin / minCostClimbingStairs.py
Last active September 27, 2020 07:02
746. Min Cost Climbing Stairs
class Solution:
def minCostClimbingStairs(self, costs: List[int]) -> int:
n = len(costs)
if n == 2:
return min(costs[0], costs[1])
dp = [0] * n
@jonathanagustin
jonathanagustin / IterativeBFS.py
Created July 21, 2020 04:14
Basic Iterative BFS
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def levelOrder(self, root: TreeNode) -> List[List[int]]:
@jonathanagustin
jonathanagustin / RecursiveBFS.py
Created July 21, 2020 04:04
Basic Recursive BFS
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def levelOrder(self, root: TreeNode) -> List[List[int]]:
@jonathanagustin
jonathanagustin / letterOrderDict.py
Last active June 6, 2020 20:06
Python way of generating letter-order key-value dictionary
order = 'abcdefghijklmnopqrstuvwxyz'
character_order = {c: i for i, c in enumerate(order)}