Skip to content

Instantly share code, notes, and snippets.

View brannerchinese's full-sized avatar

David Branner brannerchinese

View GitHub Profile

Multi-Markdown

| | Grouping ||

First Header Second Header Third Header
Content Long Cell
Content Cell Cell

New section | More | Data | And more | With an escaped '|' ||

@brannerchinese
brannerchinese / README.md
Last active August 20, 2016 20:20 — forked from anomalyjane/Vocab_quiz.py
A vocabulary quiz written for Python 2

README

Some Python tools.

Context manager for file I/O

A "context manager" imposes a beginning and end on some process that can cause problems if interrupted midway through. In the case of file I/O, if a file is opened for reading or writing and then not closed properly, it can be left in a locked state. A context manager (initiated by the with keyword) ensure that the file is closed in any case. Example

with open('questions_and_answers.json', 'r') as f:

Make a Differ-Patcher

General information about the Iron Forger project at Hacker School.

Assignment: Build a tool to compare two text files and generate a diff — a file that concisely specifies the differences between the two other files.

What a diff file looks like

A "diff" file has the following structure:

@brannerchinese
brannerchinese / TO_DO.md
Last active August 29, 2015 13:59
Weather Study To-Do List, begun 20140413

Weather Study To-Do List

To build

@brannerchinese
brannerchinese / gist:7812512
Created December 5, 2013 19:43
compare two methods of initializing zeroed list, Python 3.3
In [1]: import dis
In [2]: def f(): return ["foo" for i in range(10)]
In [3]: dis.dis(f)
1 0 LOAD_CONST 1 (<code object <listcomp> at 0x1062e14b0, file "<ipython-input-16-3cb1faa7b4d7>", line 1>)
3 LOAD_CONST 2 ('f.<locals>.<listcomp>')
6 MAKE_FUNCTION 0
9 LOAD_GLOBAL 0 (range)
12 LOAD_CONST 3 (10)