Skip to content

Instantly share code, notes, and snippets.

View MatthewScholefield's full-sized avatar

Matthew D. Scholefield MatthewScholefield

View GitHub Profile
@MatthewScholefield
MatthewScholefield / prune_zsh_history.py
Last active January 5, 2024 22:09
ZSH history truncator
import argparse
def process_history(input_file, output_file, char_limit):
prune_count = 0
with open(input_file, 'rb') as infile, open(output_file, 'wb') as outfile:
current_entry = b''
for line in infile:
current_entry += line
if not line.endswith(b'\\\n'): # End of an entry
@MatthewScholefield
MatthewScholefield / ipython_exporter.py
Last active December 31, 2023 10:53
Script to Efficiently Extract and Organize IPython Session History: A tool for seamlessly transitioning your prototype code, including import statements and function definitions, from an IPython environment to a structured Python script
# Define functions with underscore so they aren't included in output
def _print_import_statements():
from IPython import get_ipython
ipython = get_ipython()
if not ipython:
print("This function only works in an IPython environment.")
return
history = list(ipython.history_manager.get_range(output=False))
@MatthewScholefield
MatthewScholefield / README.md
Last active December 13, 2020 02:13
PDF Searcher

Interactive PDF Searcher

Use this tool to quickly search PDFs:

asciicast

It continuously asks for a search query and then asks you for a search result to open in a PDF reader.

Installation

@MatthewScholefield
MatthewScholefield / obfuscate.py
Created September 19, 2019 23:20
Store and run Python source encoded in a massive integer
obfuscate = lambda code: int(''.join(['{:08b}'.format(i) for i in list(bytes(code.encode()))]), 2)
run = lambda x: exec(bytes([int('{:b}'.format(x)[max(0, i - 8):i], 2) for i in range(len('{:b}'.format(x)) % 8, len('{:b}'.format(x)) + 1, 8) if i > 0]))
a = obfuscate("print('hello')")
b = a * 12
# run(b) # Will error out
run(b / 12) # Prints "hello"
@MatthewScholefield
MatthewScholefield / LICENSE
Last active July 21, 2019 22:44
Format a Python dictionary as a tree
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
@MatthewScholefield
MatthewScholefield / duolingo-keyboard-control.js
Created May 12, 2019 07:45
User script to control Duolingo with Keyboard
// ==UserScript==
// @name Duolingo Keyboard Control
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add full keyboard control to Duolingo (to tiles). Shortcuts: 0-9, shift + 0-9, and "\"
// @author Matthew Scholefield
// @match https://www.duolingo.com/*
// @grant none
// ==/UserScript==
@MatthewScholefield
MatthewScholefield / keybase.md
Created September 22, 2018 06:21
Keybase proof

Keybase proof

I hereby claim:

  • I am matthewscholefield on github.
  • I am mattscholefield (https://keybase.io/mattscholefield) on keybase.
  • I have a public key whose fingerprint is 97B3 5CDE 46BA 41F4 7C54 1A8F 4D57 7627 A6A3 DF75

To claim this, I am signing this object:

@MatthewScholefield
MatthewScholefield / generate_tags.sh
Last active August 20, 2018 19:04
Generate git tags from version in setup.py over git history. Tags: PyPI, Bash, Git Tag
#!/usr/bin/env bash
n=0
while git cat-file -t HEAD~$n &>/dev/null; do
ver="$(git show "HEAD~${n}:setup.py" | grep -oP "(?<=version=\')[0-9\.]+(?=\')")"
[ -z "$ver" ] || git tag -fa "_generated-v$ver" -m "v$ver" "HEAD~$n"; n=$((n+1))
done
for i in $(git tag | grep -F '_generated-'); do
tag_name=${i/_generated-/}
@MatthewScholefield
MatthewScholefield / padatious_to_rasa.py
Created June 28, 2018 20:29
Convert padatious intent lines to rasa training data json
from typing import Dict
def create_rasa_training_data(intent_lines: Dict[str, list]) -> Dict:
return {
'rasa_nlu_data': {
'common_examples': sum([
[
{
"text": line,
@MatthewScholefield
MatthewScholefield / LICENSE
Last active September 19, 2022 15:00
Precise streaming over sockets example
Copyright 2018 Matthew Scholefield
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE