Skip to content

Instantly share code, notes, and snippets.

View StephenHwang's full-sized avatar
🧬
Debugging wet code

Stephen Hwang StephenHwang

🧬
Debugging wet code
View GitHub Profile
@StephenHwang
StephenHwang / plot_git_commit_times.py
Created December 15, 2023 04:20
Plot histogram of git commit times.
#!/usr/bin/env python
#
# Run: Plot histogram of git commit history times.
# ./plot_git_commit_times.py \
# -r git_repo_path \
# -a git_author \
# -o output_path
import os
import subprocess
@StephenHwang
StephenHwang / bash_fzf_saved_commands.md
Last active October 3, 2022 07:13
Use fzf to seach saved commands from a file and send to bash command-line

Bash + fzf saved_commands.md

To help with remembering bash commands and reducing typing long lines (i.e. a ssh destination), I wrote this short function and binding to save commands within a file and fzf search and send them to the terminal as needed. Comments can be appended to a command to aid in searching for actions that do not match the written command.

Requirements:

Set up

Include in your .bashrc:

@StephenHwang
StephenHwang / calculate_N50.py
Created September 14, 2022 21:42
Calculate N50 from list of contig sizes
#!/usr/bin/env python3
from numpy import cumsum, argmax
from sys import stdin
def readStdin():
''' Read stdin line-by-line. '''
for line in stdin:
line = line.rstrip()
if line == 'Exit':
break
@StephenHwang
StephenHwang / git_branch_in_bash_prompt.md
Created September 9, 2022 21:34
Git branch in Bash prompt

I found it helpful to see the Github branch I am working on in the Bash prompt.

Adding the following snippet into the .bashrc allows for a colored bash prompt that parses and includes the git branch and whether there are uncommitted changes in the directory. Uncommitted changes are specified by the inclusion of a * after the git branch. For larger git branches, tracking file modification may be slow. Comment the MODIFIED line to not check for uncommitted file modifications.

Add this snippet to your .bashrc:

parse_git_branch() {
  MODIFIED=$(git status 2> /dev/null | grep 'Changes not staged for commit' >/dev/null && echo \*)
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1'"$MODIFIED"')/'
@StephenHwang
StephenHwang / eduroam_linux.md
Created September 7, 2022 20:45
Setting up Eduroam wifi on linux

Connecting to JHU Eduroam

To clarify the instructions found on JHU WSE and Wireless Resource center, here are the settings I found worked for manually connecting to Eduroam on Linux (Ubuntu 20.04).

Create a new wifi connection and name it how you want with the following settings:

SSID: eduroam

Wi-Fi security: WPA & WPA2 Enterprise

Authentication: PEAP

@StephenHwang
StephenHwang / server_ding_watcher.md
Created August 18, 2022 19:59
Local notification of server-ran command completion/exception

Server command completion watcher

Commands ran on a server may take underdetermined amount of time. With tmux allowing for multiple windows and panes, I found it disruptive to jump around checking whether a command completed running. This gist outlines my solution using port forwarding and ncat to listen for connections and play a sound and pop-up notification on completion or error.

Set up

Local

Set up the local machine to recieve notification from server. The used ports are only for example; and should be changed to user's preference.