Skip to content

Instantly share code, notes, and snippets.

View simonthompson99's full-sized avatar

Simon Thompson simonthompson99

View GitHub Profile
@simonthompson99
simonthompson99 / pudb-cheatsheet.md
Last active February 29, 2024 10:46
[Pudb Cheatsheet] Cheatsheet for pudb debugger #python

Running

python -m pudb <python_file> - opens up the script in pudb window, not executed anything yet. For fire modules better to make separate script that executes the individual function of interest, difficult to debug the original main file. Need pudb in virtualenv.

Or:

from pudb import set_trace
...
set_trace()
@simonthompson99
simonthompson99 / ranger-cheatsheet.md
Last active April 12, 2022 20:00 — forked from heroheman/ranger-cheatsheet.md
[Ranger Cheatsheet] Cheatsheet for common Ranger commands #ranger # cheatsheet

Ranger Cheatsheet

General

Shortcut Description
ranger Start Ranger
Q Quit Ranger
R Reload current directory
? Ranger Manpages / Shortcuts
@simonthompson99
simonthompson99 / vim-search-replace.md
Last active January 13, 2021 12:32
[VIM Search and Replace] Search and replace examples #vim #regex

%s/_\(\d\{9}\).png/, '\1',/g - Find an underscore followied by 9 digits and then .png and replace it with the 9-digit number

@simonthompson99
simonthompson99 / git-workflow.md
Last active September 29, 2022 13:28
[git workflow] Workflow for common tasks in git #git #workflow

Basics

Command Alias Description
git init <directory> Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository.
git clone <repo> gcl Clone repo located atonto local machine. Original repo can be located on the local filesystem or on a remote machine via HTTP or SSH.
git config user.name <name> Define author name to be used for all commits in current repo. Devs commonly use --global flag to set config options for current user.
git add <directory> ga/gaa Stage all changes in for the next commit. Replace with a to stage a specific file.
git commit -m "<message>" gc/gcmsg Commit the staged snapshot, but instead of launching a text editor, use as the commit message.
git status gst/gss List which files are staged, unstaged, and untracked.
@simonthompson99
simonthompson99 / update_table_from_lookup.sql
Last active January 13, 2021 12:35
[Update table from lookup] Update a db table using list of values #sql #database
update schema.table t
set cola = u.cola
from
(
select * from (values
(1, 'fdjkl'),
(2, 'reiuuio'),
(3, 'adfgd')
) as t (id, cola)
) u
@simonthompson99
simonthompson99 / rsync_rename.sh
Last active January 13, 2021 12:38
[rsync rename] Rsync set of files then rename #bash #file_operations
#!/bin/bash
# script to rsync then move load of files, quicker than individual scp
# usage: bash rsync_rename.sh files.txt
# where files.txt is a pipe-separated file of <remote_path>|<local_path_to_move_to>
input_file=$1
files_to_rsync=$(cut "-d|" -f1 $input_file)
echo $files_to_rsync | tr " " "\n" | rsync -arvzh --progress sthompson@10.1.24.38:/ /tmp --files-from=-
cat $input_file | while IFS='|' read src dest; do
src="/tmp${src}"
mkdir -p "$(dirname "${dest}")"
@simonthompson99
simonthompson99 / schema_dump.sh
Last active January 13, 2021 12:41
[Timestamped db dump] Make a timestamped pg_dump of schema in database #sql #bash #database
#!/bin/bash
current_time=$(date "+%Y%m%d-%H%M")
file_name="db_bu_$current_time.sql"
echo $file_name
pg_dump -h 10.1.24.39 -U cdt_user --schema consent_audit metrics > $file_name
@simonthompson99
simonthompson99 / pseudo-random-integer.sql
Last active January 13, 2021 12:43
[Pseudo random integer generator] Create pseudo random integer from sequence ([from Postgres wiki](https://wiki.postgresql.org/wiki/Pseudo_encrypt)) #sql #database
create sequence testes.test_id_seq
;
create or replace function pseudo_encrypt(value int) returns int as $$
declare
l1 int;
l2 int;
r1 int;
r2 int;
i int:=0;
@simonthompson99
simonthompson99 / progress_bar.py
Last active January 13, 2021 12:44
[Iterator Progress Bar] Print a progress bar whilst processing an iterable #python
def progress_bar(iterable, prefix='Progress', suffix='Complete', decimals=1,
length=50, fill='=', printEnd="\r"):
"""
shows a terminal progreess bar as iterations are passed through, use as
for i in progress_bar(range(1000)):
pass
:params: iteration: current iteration
:params: total: total iterations
:params: prefix: prefix string
:params: suffix: suffix string
@simonthompson99
simonthompson99 / restart-local-postgres.sh
Last active January 15, 2021 11:29
[Restart local Postgres] Restart local postgres after a crash #database #environment
brew services stop postgresql
rm /usr/local/var/postgres/postmaster.pid
brew services start postgresql