Skip to content

Instantly share code, notes, and snippets.

@stevedoyle
stevedoyle / git_cheatsheet.md
Last active November 21, 2022 11:05
git cheatsheet

Git Cheatsheet

Fetching and Pulling

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
@stevedoyle
stevedoyle / tmux-cheatsheet.markdown
Last active October 4, 2023 10:13 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@stevedoyle
stevedoyle / itertools_chain.py
Last active October 2, 2017 13:30
itertools.chain
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.
# 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
@stevedoyle
stevedoyle / tcxsplit.py
Created January 29, 2015 11:25
Split TCX file with laps into multiple files, with 1 lap per file
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):
@stevedoyle
stevedoyle / lxml_xpath_remove.py
Created January 28, 2015 15:47
Remove a node from an XML tree using lxml objectify and xpath
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):
@stevedoyle
stevedoyle / xpath_find_text
Last active August 29, 2015 14:14
XPath for finding elements with a given text value
Find students whose name is Bob:
//Student/name[text()="Bob"]
@stevedoyle
stevedoyle / NSFetchedResultsController_Example.swift
Created January 23, 2015 11:04
NSFetchedResultsController Usage Pattern
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
}
@stevedoyle
stevedoyle / nsnumber_arithmetic.swift
Created January 22, 2015 09:53
Working with NSNumber in Swift
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)
@stevedoyle
stevedoyle / argparse.py
Last active December 23, 2016 13:00
Using argparse for command line argument parsing in python
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)")