Skip to content

Instantly share code, notes, and snippets.

@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 / 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):
# 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 / 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.
@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 / 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 / octave.md
Created November 20, 2017 22:55 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &&
@stevedoyle
stevedoyle / myutils.py
Last active October 10, 2018 16:08
Misc utilities to simplify common tasks in an iPython shell
def mpps(gbps, size):
return (gbps / (size * 8)) * 1000
def gbps(mpps, size):
return mpps * size * 8 / 1000;
def pkt_size(gbps, mpps):
return (gbps * 1000) / mpps / 8
##################################################
@stevedoyle
stevedoyle / timestamp.h
Last active August 17, 2018 08:38
RDTSC based timestamps
#ifndef _TIMESTAMP_H_
#define _TIMESTAMP_H_
static inline uint64_t timestamp_start(void)
{
union {
uint64_t tsc_64;
struct {
uint32_t lo_32;
uint32_t hi_32;
@stevedoyle
stevedoyle / PowerShell-Notes.md
Last active July 22, 2021 14:04
Collection of notes for using Power Shell.

PowerShell Notes

Searching/Grepping files

PowerShell equivalent of egrep:

Select-String <string>

and egrep -r:

dir -Recurse | Select-String <string>