Skip to content

Instantly share code, notes, and snippets.

@anna-hope
anna-hope / gist:5681117
Last active December 17, 2015 22:19
werkzeug secure_filename fix python 3
if isinstance(filename, text_type):
from unicodedata import normalize
filename = normalize('NFKD', filename).encode('ascii', 'ignore')
if not PY2:
filename = filename.decode('ascii')
for sep in os.path.sep, os.path.altsep:
if sep:
filename = filename.replace(sep, ' ')
@anna-hope
anna-hope / gist:5681167
Created May 30, 2013 20:55
werkzeug secure_filename str/bytes crash
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/flask/app.py", line 1827, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python3.3/site-packages/flask/app.py", line 1811, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python3.3/site-packages/flask/app.py", line 1394, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.3/site-packages/flask/_compat.py", line 38, in reraise
raise value
File "/usr/local/lib/python3.3/site-packages/flask/app.py", line 1808, in wsgi_app
@anna-hope
anna-hope / useless.py
Created February 16, 2014 19:52
Python equivalent of a useless machine
from os import getpid, kill
from signal import SIGTERM
kill(getpid(), SIGTERM)
@anna-hope
anna-hope / onlysmall.py
Last active August 29, 2015 14:12
only small letters
#!/usr/bin/env python3.4
from itertools import filterfalse
from sys import argv
try:
filepath = argv[1]
except IndexError:
raise SystemExit('must specify path to file')
@anna-hope
anna-hope / restringer.py
Created January 13, 2015 04:02
restringer for elsa
#!/usr/bin/env python3.4
import json
from pprint import PrettyPrinter
from collections import defaultdict
pp = PrettyPrinter()
with open('elsa/strings.json') as stringfile:
strings = json.load(stringfile)
@anna-hope
anna-hope / woe.py
Last active August 29, 2015 14:16
woe formatter
#!/usr/bin/env python3.4
from collections import Counter
from difflib import SequenceMatcher
import sys, re, pathlib
import subprocess
import requests
from bs4 import BeautifulSoup
from bs4.element import NavigableString, Tag
@anna-hope
anna-hope / finnish_like_harmony.json
Created August 12, 2015 04:36
a corpus of gibberish which follows the rules of Finnish vowel harmony
This file has been truncated, but you can view the full file.
[
[
"lyfätösivözi",
"änydezäqepez",
"päwidefyföjä",
"evepägäniwyk",
"xylyxäzöbewe",
"ixäbörevögeh",
"öwygyvywäwyg",
"zexirilähiqö",
#!/usr/bin/env python3
from enum import Enum
from itertools import chain
import re
import pprint
filepath = "chukchi_texts.txt"
#pprint.pprint(words)
@anna-hope
anna-hope / readable_ilga.user.js
Last active August 29, 2015 14:27
make Illinois law database website readable
// ==UserScript==
// @name Readable ILGA
// @namespace http://ostensible.me
// @version 0.1
// @description make ILGA.gov readable
// @author Anton Osten
// @match http://*.ilga.gov/*
// @grant none
// ==/UserScript==
@anna-hope
anna-hope / get_ngrams.py
Last active November 5, 2015 23:12
get all possible n-grams from an iterable
def get_ngrams(iterable):
length = len(iterable)
if length == 1:
yield iterable[0]
return
# the 'starting position' loop
for n in range(length):