Skip to content

Instantly share code, notes, and snippets.

Avatar

Ofer Koren koreno

View GitHub Profile
View inject_blame.py
import re
import time
import linecache
from subprocess import check_output
DAY = 60 * 60 * 24
BLAME_REGEX = re.compile(
r"(?P<commit>\w+)\s+"
r"(?P<file>\S+)\s+"
View traceback_with_blame.py
#!/usr/bin/env python3.8
import sys
from inject_blame import inject_blame
from traceback import print_exception
sys.excepthook = print_exception
inject_blame("/home/ofer/Sources/easypy/easypy/collections.py")
from easypy.collections import ListCollection
lc = ListCollection()
View linecache_demo.3.py
# replace exception hook
import sys
from traceback import print_exception
sys.excepthook = print_exception
# meddle with a code line using linecache
import linecache
lineno = 423
fname = "/home/ofer/Sources/easypy/easypy/collections.py"
@koreno
koreno / linecache_demo.2.py
Last active Feb 11, 2021
Messing with linecache
View linecache_demo.2.py
size, mtime, lines, fullname = linecache.cache[fname]
lines[lineno - 1]
# ' return random.randint(minimum, maximum)\n'
lines[lineno - 1] = "Nothing to see here, please move along..."
linecache.getline(fname, lineno)
# 'Nothing to see here, please move along...'
@koreno
koreno / linecache_demo.1.py
Last active Feb 11, 2021
linecache example
View linecache_demo.1.py
import linecache
lineno = 423
fname = "/home/ofer/Sources/easypy/easypy/collections.py"
linecache.getline(fname, lineno)
# ' return random.randint(minimum, maximum)\n'
@koreno
koreno / traceback_demo.py
Last active Feb 11, 2021
Traceback Example #1
View traceback_demo.py
from easypy.collections import ListCollection
lc = ListCollection()
lc.pop_some(1)
Traceback (most recent call last):
File "./traceback_demo.py", line 7, in <module>
lc.pop_some(1)
File "/home/ofer/Sources/easypy/easypy/collections.py", line 481, in pop_some
sample_size = self._choose_sampling_size(minimum, maximum)
File "/home/ofer/Sources/easypy/easypy/collections.py", line 423, in _choose_sampling_size
@koreno
koreno / excepthook.py
Created Feb 11, 2021
Setting sys.excepthook
View excepthook.py
from traceback import print_exception
sys.excepthook = print_exception
@koreno
koreno / README.md
Last active Apr 1, 2020
'rebaser' improves on 'git rebase -i' by adding information per commit regarding which files it touched.
View README.md

Prebase

git-prebase improves on 'git rebase -i' by adding information per commit regarding which files it touched.

  • Each file gets an alpha-numeric identifier at a particular column, a list of which appears below the commit list. (The identifiers wrap around after the 62nd file)
  • Commits can be moved up and down safely (without conflicts) as long as their columns don't clash (they did not touch the same file).

Installation

Add the executable to your path and git will automatically expose it as