Skip to content

Instantly share code, notes, and snippets.

@cgreer
cgreer / bag_of_little_bootstraps.py
Last active October 9, 2023 17:09
Bag of Little Bootstraps (w/ example usage)
import random
from typing import (
List,
Dict,
Callable,
Union,
)
import numpy
@cgreer
cgreer / nearestpytag.py
Created November 8, 2013 04:32
Get the tag (function/method/etc) in which the current position (cursor, file row/col) is in that tag's scope.
import re
def first_non_whitespace_index(lineText):
''' Find the index of the first non-whitespace character on line. '''
pat = re.compile(r'(\s*)(\S)')
m = pat.match(lineText)
if m:
# start(2) gets start of 2nd group
return m.start(2)
else:
@cgreer
cgreer / run_from_cmd_line.py
Last active December 23, 2015 03:38
Quickly run a function in a script from the command line without option parsing (useful for pipeline creation)
'''
USAGE:
Let's say you have a "find_words_with_letter" function (not method) in a script called "script_name.py"...
def find_words_with_letter(fileName, letter = "g"):
#fxn code here
...you can then call the function in the script from the command line - function name 1st argument, function args follow.