Skip to content

Instantly share code, notes, and snippets.

View sc0tt's full-sized avatar
🍦
grinding

Scott Adie sc0tt

🍦
grinding
View GitHub Profile
@sc0tt
sc0tt / gpt_sort.py
Last active March 31, 2023 02:54
I needed to sort around 5k files into different directories based on extension. I used this to try out ChatGPT.
import shutil
import json
from pathlib import Path
# Define the source and destination directories
source_dir = Path('root')
destination_dir = Path('root_sorted')
# Define the mappings between file extensions and categories
category_mappings = {
@sc0tt
sc0tt / lounge.service
Created November 13, 2019 14:41
Lounge Service
# Save this file as:
# /etc/systemd/system/lounge.service
#
# Then run:
# systemctl enable lounge.service
#
# Then run:
# systemctl start lounge
#
# If something isn't working or you want to make sure it is working, you can see the output by running:
@sc0tt
sc0tt / formvalidation.py
Last active January 25, 2016 01:10
Converts a WTForms form to JSON which http://formvalidation.io/ accepts. May become a library in the future.
from wtforms.validators import DataRequired, Length, Email, UUID, MacAddress, EqualTo, Regexp
def convert_form_to_json(form):
def convert_field_to_json(field):
validations = {}
for val in field.validators:
validation_type = val.__class__
if validation_type not in validation_types:
raise Exception('Unknown validator')
validations[validation_types[validation_type]['type']] = {}
@sc0tt
sc0tt / watch.py
Created November 13, 2013 15:31
BTC Price Watch
import requests
import time
import decimal
lastPrice = decimal.Decimal("0")
while True:
ret = requests.get("https://coinbase.com/api/v1/prices/spot_rate").json()
price = decimal.Decimal(ret['amount'])
diff = price - lastPrice
if diff > 0:
@sc0tt
sc0tt / animate.py
Last active December 28, 2015 03:49
Animation
import os
import time
expander = {"n":"\n", "s": " ", "q": "~~~~~~"}
os.system(['clear','cls'][os.name == 'nt'])
animation = []
animation.append("""nnnnnnqqq""")
animation.append("""n/nnnnnqqq""")
animation.append("""n /n/nnnnqqq""")
@sc0tt
sc0tt / outerdiff.py
Last active December 23, 2015 20:09
Performs an outer join type deal on two files. Finds lines in A not found in B and lines in B not found in A
import sys
def getContents(inFile):
return sorted(list(set(inFile.read().split("\n"))), key=lambda k: k.lower())
lFileName = raw_input("Enter the first file name: ") if len(sys.argv) < 2 else sys.argv[1]
with open(lFileName, "r") as left:
leftLines = getContents(left)
rFileName = raw_input("Enter the second file name: ") if len(sys.argv) < 3 else sys.argv[2]
@sc0tt
sc0tt / webm.md
Last active August 29, 2015 14:24 — forked from ndarville/webm.md

Grab ffmpeg from https://www.ffmpeg.org/download.html

It's a command line tool which means you will have to type things with your keyboard instead of clicking on buttons.

The most trivial operation would be converting gifs:

ffmpeg -i your_gif.gif -c:v libvpx -crf 12 -b:v 500K output.webm
  • -crf values can go from 4 to 63. Lower values mean better quality.
  • -b:v is the maximum allowed bitrate. Higher means better quality.
### Keybase proof
I hereby claim:
* I am sc0tt on github.
* I am sc0tt (https://keybase.io/sc0tt) on keybase.
* I have a public key whose fingerprint is 4FDE 9BAC 0401 F8D7 4780 85C3 AE61 77CB 40DC 6C46
To claim this, I am signing this object:
@sc0tt
sc0tt / pokeparser.py
Created September 23, 2014 01:55
Parses the pokemon tcg website.
import re
import time
from selenium import webdriver
# You will need to have the phantomjs exe in your path or alongside this script.
driver = webdriver.PhantomJS()
current_page = 0
total_pages = -1
Sentence:
That is a really cool fire truck you got there!
Left side is a key, right is a value
That is a -> really cool fire
is a really -> cool fire truck
a really cool -> fire truck you
really cool fire -> truck you got
cool fire truck -> you got there!