This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
######################################################################### | |
# Script to clean up whitespace in source files. | |
# - Removes trailing whitespace at the end of lines | |
# - Converts tabs to spaces (4 spaces = 1 tab) | |
# | |
# Copyright 2013 Stephen Doyle | |
######################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fileinput | |
for line in fileinput.input(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def divider(): | |
print '-'*40 | |
def width_str(width): | |
return "x%d" % (width) | |
gens = [1,2,3] | |
link_widths = [1,2,4,8,16,24,32] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import subprocess | |
import shlex | |
import sys | |
def compress_file(filename, level): | |
try: | |
cmd = shlex.split("gzip %s -c %s" % (level, filename)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lxml import objectify | |
tree = objectify.parse(tcx_file') | |
root = tree.getroot() | |
root.xpath('//ns:HeartRateBpm', namespaces={'ns': 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from Crypto.Cipher import AES | |
from Crypto.Cipher import DES3 | |
def add_padding(message): | |
pad_len = 16 - (len(message) % 16) | |
message += (' ' * pad_len) | |
return message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import logging | |
def main(): | |
parser = argparse.ArgumentParser(description="Example") | |
parser.add_argument('-v', '--verbose', action='store_true', help="Verbose output") | |
parser.add_argument('--size', nargs='*', default=[256], type=int, choices=[256,512,768,1024], help="Data sizes (default = 256)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var targetDistance: NSNumber = 4000 | |
var completedDistance: NSNumber = 121.7 | |
var percentComplete: Float | |
// NSNumber can contain different types, so need to be explicit about the type of its value | |
// when using it in arithmetic | |
percentComplete = (completedDistance.floatValue / targetDistance.floatValue) * 100 | |
println(percentComplete) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoalsViewController: UITableViewController, NSFetchedResultsControllerDelegate { | |
... | |
let managedContext = (UIApplication.sharedApplication().delegate as AppDelegate).managedObjectContext | |
var fetchedResultsController: NSFetchedResultsController = NSFetchedResultsController() | |
... | |
func getFetchedResultsController() -> NSFetchedResultsController { | |
fetchedResultsController = NSFetchedResultsController(fetchRequest: goalFetchRequest(), managedObjectContext: managedContext!, sectionNameKeyPath: nil, cacheName: nil) | |
return fetchedResultsController | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Find students whose name is Bob: | |
//Student/name[text()="Bob"] |