Skip to content

Instantly share code, notes, and snippets.

@bradbeattie
bradbeattie / extract_subtitles.py
Created December 15, 2012 20:33
This is some code I've been using to extract subtitles into CSV pairs for the purposes of language flashcards. The target encoding is hardcoded to iso-8859-1 and it requires both subtitle files to use the same timings, but otherwise it works just fine. Modified to handle multi-line sentences better. It drops some admittedly, but the flashcard qu…
#!/usr/bin/python
import unicodecsv
import argparse
import sys
import re
from pysrt import SubRipFile
# Determine which languages to import
parser = argparse.ArgumentParser()
parser.add_argument("source", help="source language file to parse")
@bradbeattie
bradbeattie / ted2csv.py
Last active December 10, 2015 08:58
Extracts a TED talk in two languages and creates a CSV of matching translated strings for flashcard use. Some potentially mistranslated entries will be stripped. Download the desired parallel corpus here: https://wit3.fbk.eu/mt.php?release=2012-02
#!/usr/bin/python
import unicodecsv
import sys
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("source", help="Source language file")
parser.add_argument("target", help="Target language file")
args = parser.parse_args()
@bradbeattie
bradbeattie / translate_with_wiktionary.py
Last active December 14, 2015 23:39
Translates a given set of French words into English along with English definitions. Shouldn't be to difficult to adapt to other languages. Makes use of a simple two-column sqlite database to cache the API responses. Ignores duplicate words, obsolete words, etc.
#!/usr/bin/python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import random
import collections
import argparse
import json
import re
import requests
import sqlite3
@bradbeattie
bradbeattie / Steam Reviews Javascript
Last active September 30, 2015 05:23
A script to add the most helpful Steam review to the front page
// Initial definitions
var now = new Date().getTime();
var ten_seconds = 10 * 1000;
var one_day = 86400 * 1000;
var one_week = one_day * 7;
// Remove any pre-existing summary elements
jQuery(".summary-element").remove();
@bradbeattie
bradbeattie / gist:b409e1594084027581f5
Created June 27, 2014 21:36
Show the effect of different decaying averages
import random
import math
multipliers = (0.5, 0.8, 0.95, 0.99, 0.995)
values = [1] * len(multipliers)
for x in xrange(400):
numberline = ["-"] * 101
for index, multiplier in enumerate(multipliers):
if index == 0:
@bradbeattie
bradbeattie / prison_parser
Last active August 29, 2015 14:10
Parse and modify prison architect save files
# These functions will allow you to
# - Read in Prison Architect save files
# - Modify the read content
# - Save content back into Prison Architect save file formats
import re
from collections import OrderedDict
from pprint import PrettyPrinter
@bradbeattie
bradbeattie / cache_result.py
Last active June 27, 2016 18:27
Caches function results a little more intelligently
from datetime import timedelta
from django.core.cache import cache
from hashlib import md5
from importlib import import_module
from random import randint
from redis import Redis
from rq import Queue
EXPIRY_VARIANCE = 0.2
@bradbeattie
bradbeattie / meetupfilter.js
Last active May 1, 2016 00:08
Filters meetup.com pages based on a given regex of linked member profiles. Useful for finding language exchange partners.
/* Initial definitions */
var regex_positive = /(france|french|paris|bonjour|salut|montr.al)/i;
var regex_negative = /(china|korea|spain|japan|taiwan|venezuela|costa rica|chile|vietnam|russia|honduras|brazil|iran|m.xico|czech|sweden|saudi|turkey|germany|india|argentina|colombia|netherlands|philippines)/i;
var now = new Date().getTime();
var ten_seconds = 10 * 1000;
var one_day = 86400 * 1000;
var one_week = one_day * 7;
/* Clear junk from the page */
jQuery("#chapterHeader, p").remove();
import re
# Supported tokens and their operations
ORDER_OF_OPERATIONS = ["MULTIPLY", "DIVIDE", "ADD", "SUBTRACT"]
scanner = re.Scanner([
(r"([0-9]+)", lambda x, y: int(y)),
(r"\+", lambda x, y: "ADD"),
(r"-", lambda x, y: "SUBTRACT"),
(r"\*", lambda x, y: "MULTIPLY"),
(r"/", lambda x, y: "DIVIDE"),
@bradbeattie
bradbeattie / They Come Unseen.md
Last active March 8, 2017 18:54
Rules Confirmation Scenario for They Come Unseen

They Come Unseen: Rules Confirmation Scenario

This is not meant to be a comprehensive list of rules, but instead to help players validate their understanding of the rules through a scenario. The turns below are not in order.

Note: This document has yet to be fully verified. Pending requests for clarifications have been added after the document at the bottom.

Scenario Setup

Location Battery Mines Damage