Skip to content

Instantly share code, notes, and snippets.

@stucka
stucka / mysqlbackup
Created July 21, 2017 14:52
Backup mysql for Windows
set datestr=%date:~10,4%-%date:~7,2%-%date:~4,2%
mysqldump --add-drop-database --all-databases -mstucka -p >e:\mysqldump-library%datestr%.sql
@stucka
stucka / OrderedDictWriter.py
Created July 7, 2017 22:19
Python -- write from ordered dictionary OrderedDict to csv file
with open("statereport-geo.csv", 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
headers = []
for key in rows[0]:
headers.append(key)
writer.writerow(headers)
for row in rows:
targetrow = []
for key in headers:
targetrow.append(row[key])
@stucka
stucka / uucsv.py
Created May 9, 2017 20:00
Cobbled-together Unicode CSV writer from docs
import csv
import codecs
import cStringIO
def UnicodeDictReader(utf8_data, **kwargs):
csv_reader = csv.DictReader(utf8_data, **kwargs)
for row in csv_reader:
yield {unicode(key, 'utf-8'):unicode(value, 'utf-8') for key, value in row.iteritems()}
@stucka
stucka / gist:956fb9008cc38bfb3564876cc442e483
Last active June 24, 2019 15:18
Stuff for new computer
7-Zip
Acrobat Professional
Auslogics Disk Defrag
Bulk Rename Utility
Calibre
CCCleaner
Chrome
DBeaver
Dropbox
Firefox
@stucka
stucka / linter.bat
Created May 4, 2017 13:12
Python linter / checker / validator
pep8 --max-line-length=200 %1 %2 %3 %4 %5 %6 %7 %8
pyflakes %1 %2 %3 %4 %5 %6 %7 %8
@stucka
stucka / gist:2f778c4cb8cc0529caa440652adc98af
Last active October 4, 2017 16:03
New Python install requirements
pip install --force-reinstall --ignore-installed MySQL_python-1.2.5-cp27-none-win32.whl
pip install --force-reinstall --ignore-installed dataset selenium ipython==5.3.0 notebook==4.4.1 jupyter awesome-slugify
pip install pyquery slackclient requests geopy beautifulsoup4 tweepy pylint pyflakes csvkit pycodestyle
@stucka
stucka / imagelister.py
Created April 7, 2017 18:40
Get list of image dimensions from a folder
from PIL import Image
import os
folder = "./static/imgoriginals/"
print("Width\tHeight\tFilename")
for lead in os.listdir(folder):
filename = os.path.join(folder, lead)
im = Image.open(filename)
width, height = im.size
try:
@stucka
stucka / converterthingy.bat
Created February 3, 2017 22:12
Improve generate.py scripting functionality for Pannellum
set pythonpath="c:\python27\python"
set nonapath="c:\Program Files\hugin\bin\nona.exe"
%pythonpath% generate.py -n %nonapath% -o %1 %1.jpg
@stucka
stucka / csvwide.py
Created January 24, 2017 19:22
Woefully incomplete CSV widener, with completely misleading documentation
#!/usr/bin/env python
"""
This script will take a lat-long pair (e.g., "-80.123, 45.678") in the final column, and determine if any other lines are at that exactly named pair. If so, it scatters them around in a circle.
So if other points are adjacent or identical but differently named (-80.123 vs. -80.1230), this won't help much. It works for what it is, and it's not meant to do more.
Scattering distance right now is hard-coded (see "meters=100" around line 85).
This may use a lot of memory on large datasets, so you might want it to work off a database. I didn't.
"""
@stucka
stucka / dcprojectpagecount.py
Created January 11, 2017 21:21
Get page count for DocumentCloud projects
# pip install python-documentcloud
from documentcloud import DocumentCloud
import creds
username = "[email protected]"
password = "somethingsneaky"
projectsought = "Cool set of documents"
client = DocumentCloud(username, password)
project = client.projects.get(title=projectsought)