Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / sshlog.sh
Last active July 25, 2022 15:13
ssh with logging #snippet
function _ssh_sesslog() {
_sesdir="<path/to/session/logs>"
mkdir -p "${_sesdir}" && \
ssh $@ 2>&1 | tee -a "${_sesdir}/$(date +%Y%m%d).log"
}
# Alias:
@rsperl
rsperl / netstat.sh
Last active July 25, 2022 15:14
netstat #snippet
# Graph # of connections for each hosts
netstat -an | \
grep ESTABLISHED | \
awk '{print $5}' | \
awk -F: '{print $1}' | \
grep -v -e '^[[:space:]]*$' | \
sort | uniq -c | \
awk '{ printf("%s\t%s\t",$2,$1) ; for (i = 0; i < $1; i++) {printf("*")}; print "" }'
# Monitor open connections for specific port including listen, count and sort it per IP
@rsperl
rsperl / class_instance_variables.py
Last active July 25, 2022 15:15
[Class vs Instance variables in Python] #python #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# example output:
#
# A.var1 c_int(1) 4509637024
# a1.var1 c_int(3) 4509637704 False
# a1.__class__.var1 c_int(1) 4509637024 True
# --------------------------------------------------------------------
@rsperl
rsperl / debug_script_pdb.py
Last active July 25, 2022 15:15
how to use python pdb debugger in a script #snippet
#!/usr/bin/env python
import pdb
import sys
import traceback
def main():
# some WIP code that maybe raises an exception
raise BaseException("oh no, exception!")
return 0
@rsperl
rsperl / set_default_browser.py
Last active May 5, 2023 10:43
set default browser on macos from command line #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# with help from https://gist.github.com/miketaylr/5969656
import sys
try:
from LaunchServices import (
LSSetDefaultHandlerForURLScheme,
@rsperl
rsperl / json_yml_converter.py
Last active July 25, 2022 15:17
converts yml to json and vice versa #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Create a link named json2yml and yml2json to this file.
If invoked as json2yml, it will convert json file to yml.
If invoked as yml2json, it will convert yml file to json.
"""
import sys
import json
@rsperl
rsperl / panda_tricks.md
Last active July 25, 2022 12:47
panda tricks #python #panda #snippet

Python Pandas Tips and Tricks

source


Categories

@rsperl
rsperl / mac_commands.sh
Last active July 25, 2022 15:21
Mac commands #snippet
# disable verifying developer
spctl --master-disable
defaults write com.apple.dock expose-animation-duration -float 0.1
defaults write com.apple.LaunchServices LSQuarantine -bool false
defaults write com.apple.finder DisableAllAnimations -bool true
defaults write com.apple.finder ShowStatusBar -bool true
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true
defaults write com.apple.finder _FXSortFoldersFirst -bool true
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
@rsperl
rsperl / is_power_of_2.py
Last active July 25, 2022 15:23
Determine if a number is a power of 2 #python #snippet
def log2(x):
if x == 0:
return False
return math.log10(x) / math.log10(2)
def is_power_of_two(n):
return math.ceil(log2(n)) == math.floor(log2(n))
@rsperl
rsperl / managing_dotenv_files.md
Last active July 25, 2022 15:24
managing .env files #snippet

Managing .env Files

The Problem

I use .env files to set environment variables for projects, but those values are different in local vs test vs prod. I also want support from my IDE and the commandline. VSCode and Intellij both support .env files, but if you want to point your application from local to test or prod, you have to update the .env file, which leaves me with an env file with lots of comments. Alternatively, you can update the IDE to point to another env file, but that gets a little non-standard by not using .env.

Solution