Task | Command |
---|---|
Fetch for later merging | git fetch [remote name] |
Pull and merge | git pull [remote name] |
Pull and rebase local changes on top (instead of merging) | git pull --rebase [remote name] |
Clone only a subset of files | git init repo cd repo git remote add origin url git config core.sparsecheckout true echo "path/*" >> .git/info/sparse-checkout git pull --depth=1 origin master |
This file contains hidden or 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
p = [(1,2,3), (2,4), (1,6)] | |
set(itertools.chain(*p)) | |
=> {1,2,3,4,5,6} | |
where: | |
*p expands the list elements into separate arguments | |
itertools.chain() chains all of the individual elements of each parameter (the tuple from p in this case) into a single iterable stream. |
This file contains hidden or 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
# virtualenv setup | |
cd proj_folder | |
virtualenv venv | |
# or with a particular version of python | |
virtualenv -p /usr/bin/python2.7 venv | |
# Activate it | |
source venv/bin/activate |
This file contains hidden or 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 copy | |
import os | |
from lxml import objectify | |
namespace = 'http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2' | |
def remove_laps(): | |
pass | |
def count_laps(tree_root): |
This file contains hidden or 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 StringIO import StringIO | |
from lxml import objectify | |
class SampleParser: | |
def __init__(self, xml_data): | |
tree = objectify.parse(xml_data) | |
self.root = tree.getroot() | |
def student_names(self): |
This file contains hidden or 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"] |
This file contains hidden or 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 hidden or 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 hidden or 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)") |