Skip to content

Instantly share code, notes, and snippets.

@munro
munro / git_hash.py
Created March 22, 2021 19:21
Python get last pushed commit
from subprocess import check_output
def get_git_current_commit():
return _get_git_hashes("rev-parse", "HEAD")[0]
def get_git_last_pushed_commit():
unpushed_commits = get_git_unpushed_commits()
if not unpushed_commits:
@munro
munro / hot_keys.md
Last active April 27, 2021 14:58
Power user hot keys

Setup

Keyboard remapping

Mac change keyboard modifer keys

  • Map caps lock to left option

Karabiner elements

@munro
munro / gcs_list_folders.py
Created December 17, 2020 19:32
Google Cloud Storage List Directories in Python
def gcs_list_folders(bucket, prefix="", delimeter="/", guess_lexicographically_last_item="~", gcs_client=None):
folders = set()
prefix_parts = prefix.split(delimeter)
start_offset = "/".join(prefix_parts)
last_blob_name = None
while True:
blobs = list(gcs_client.list_blobs(
bucket_or_name=bucket,
prefix=prefix,
start_offset=start_offset,
@munro
munro / macos_get_focused_application.py
Created January 29, 2019 19:07
macos_get_focused_application
from textwrap import dedent
import subprocess
def macos_get_focused_application():
return subprocess.check_output(['osascript'], input=dedent('''
tell application "System Events"
set frontApp to name of first application process whose frontmost is true
end tell
@munro
munro / cb_2017_us_ua10_500k.geojson
Last active January 14, 2019 21:48
census urban areas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
async def _on_message(message : Message):
print(f'[received message] {message}')
print((message.arbitration_id, binascii.hexlify(message.data)))
if message.arbitration_id == 0x0241 and binascii.hexlify(message.data) == b'0008021a90':
print(f'FOUND MESSAGE! {message}')
found_message.set_result((True, binascii.hexlify(message.data)))
async with pcan.listen_message(_on_message):
print('Listening for messages!')
print('Sending obd_driver')

jdbc_fast_read

Eases loading data quickly into PySpark, by automatically setting upperBound, lowerBound, and numPartitions for partitioned jdbc reading.

Install package from S3

sc.addPyFile('s3://circleup-oss/jdbc_fast_read-0.0.1-py2.7.egg')
@munro
munro / selenium_wait_for_images_loaded.py
Last active February 4, 2025 15:15
Selenium wait for all images to load, including background images.
from textwrap import dedent
def wait_until_images_loaded(driver, timeout=30):
"""Waits for all images & background images to load."""
driver.set_script_timeout(timeout)
driver.execute_async_script(dedent('''
// Function to extract URL from CSS 'url()' function
function extractCSSURL(text) {
var url_str = text.replace(/.*url\((.*)\).*/, '$1');
@munro
munro / example.py
Last active December 10, 2015 03:27 — forked from djmunro/foo.py
print_grid(
columns=('Function', 'Occurences', 'Sender'),
values=[(x['function'], 1337, x['sender']) for x in messages if 'function' in x]
)
@munro
munro / parser.py
Last active December 9, 2015 02:35 — forked from djmunro/parser.py
import re
import sys
import json
import itertools
from collections import Counter
from collections import defaultdict
SPLIT_MESSAGES = re.compile(r'\n.?\w{3} \w+ +\d+ \d+:\d+:\d+ \d+[\r\s]*\n')
MATCH_SIGNAL = re.compile(r'signal sender=(?P<sender>.*) -> dest=(?P<dest>.*) serial=(?P<serial>.*) path=(?P<path>.*) interface=(?P<interface>.*) member=(?P<member>.*)\n\s+string (?P<function>.*)\n\s+string (?P<params>.*)')
MATCH_METHOD_CALL = re.compile(r'method call sender=(?P<sender>.*) -> dest=(?P<dest>.*) serial=(?P<serial>.*) path=(?P<path>.*) interface=(?P<interface>.*) member=(?P<member>.*)\n\s+string (?P<function>.*)\n\s+string (?P<params>.*)')