Skip to content

Instantly share code, notes, and snippets.

Michael F. Lamb datagrok

View GitHub Profile
View successive-regex.py
import re
regex_bits = [
(r'\d+', 'Does not start with a digit'),
(r'-', 'Does not contain a - after the first digit'),
(r'(foo|bar)', 'Does not contain "foo" or "bar" after the digits.'),
(r'\.', 'Does not contain a period after the foo/bar thing'),
]
successive_regexes = [(re.compile(''.join(rbit for rbit, _ in regex_bits[:n+1])), regex_bits[n][1]) for n in range(len(regex_bits))]
@datagrok
datagrok / git-serve.md
Last active Jan 14, 2019
How to easily launch a temporary one-off git server from any local repository, to enable a peer-to-peer git workflow.
View git-serve.md
View OCR Scan
#!/bin/sh
SOURCE=""
if [ $# -gt 1 ]
then
SOURCE="--source ADF -l 3"
outname=$2
pbreak=$1
@datagrok
datagrok / race-condition-rebase.sh
Last active Dec 23, 2015
Depending on the existence of a sleep statement, the result of a 'git rebase' can be wildly different...
View race-condition-rebase.sh
#!/bin/sh
set -e
# Problem:
#
# I've got a feature branch. Merged it to master. Oops, discovered later that
# something's wrong with it, so revert the merge commit. Now, I want to rebase
# the commits from the feature branch onto master so I can fix my bug and merge
# in again. But nothing happens the way I expect it to!
@datagrok
datagrok / pushydecoratorfail.py
Last active Dec 24, 2015
I tried to convert pushy's "compile" into a simple decorator. Nope chuck testa
View pushydecoratorfail.py
from pushy import connect
compiler = connect('ssh:localhost').compile
# works just fine
def test1():
print "success"
test1 = compiler(test1)
test1()
@datagrok
datagrok / all_in_one.py
Last active Dec 24, 2015
experimenting with execnet
View all_in_one.py
# some code and functions, written here but that we'll want to execute
# in the remote machine. Written here just like one would to execute
# locally
import os
def foo(*args):
return repr(args)
def simple(arg):
@datagrok
datagrok / branch_sort.coffee
Last active Dec 27, 2015
A comparator to order a list of branches as follows: master first, then OTIS, then TIEs in numerical order, then any other branches in lexicographic order.
View branch_sort.coffee
# a comparator to order a list of branches as follows: master first, then OTIS,
# then TIEs in numerical order, then any other branches in lexicographic order.
branch_cmp = (a, b) ->
return 0 if a is b
for re in [/^master$/, /^OTIS$/, /^TIE/]
break if re.test a and re.test b
return -1 if re.test a
return 1 if re.test b
return a.localeCompare b
@datagrok
datagrok / object_comprehensions.md
Last active May 23, 2018
Approximating object comprehension one-liners in CoffeeScript using Array.reduce()
View object_comprehensions.md

Object comprehensions in CoffeeScript

This is a literate CoffeeScript file: save it, rename it with a .litcoffee extension, and you can execute it with coffee.

Motivation

Python 2.7 has nice dictionary comprehensions:

# result = {n: n**2 for n in range(5)}
@datagrok
datagrok / pep8-alignment.md
Last active Jan 14, 2019
PEP-8's inconsistent alignment recommendation
View pep8-alignment.md
@datagrok
datagrok / LICENSE.AGPL-3.0.md
Last active Dec 30, 2015
Various GNU Licenses (GPLv3, AGPLv3, LGPLv3) converted to Markdown format.
View LICENSE.AGPL-3.0.md

GNU AFFERO GENERAL PUBLIC LICENSE

Version 3, 19 November 2007

Copyright © 2007 Free Software Foundation, Inc. http://fsf.org/

Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.

Preamble

You can’t perform that action at this time.