Skip to content

Instantly share code, notes, and snippets.

View mac01021's full-sized avatar

Matthew Coolbeth mac01021

View GitHub Profile
val pattern = java.util.regex.Pattern.compile ("""(?xs) ("(.*?)"|) ; ("(.*?)"|) (?: \r?\n | \z ) """)
val matcher = pattern.matcher (input)
while (matcher.find) {
val col1 = matcher.group (2)
val col2 = matcher.group (4)
// ...
}
@mac01021
mac01021 / gist:4207823
Created December 4, 2012 19:34
repoze.bfg confusion
if 'bfg.routes.matchdict' in environ:
matchdict = environ['bfg.routes.matchdict']
path = matchdict.get('traverse', '/')
subpath = matchdict.get('subpath', '')
subpath = tuple(filter(None, subpath.split('/')))
else:
# this request did not match a Routes route
subpath = ()
try:
path = environ['PATH_INFO'] or '/'
@mac01021
mac01021 / gist:5782105
Created June 14, 2013 14:12
Longest Common Subsequence (Classic Dynamic Programming solution)
package main
import "fmt"
func main() {
a := "GATTACACACT"
b := "GTCAAACCCCTA"
fmt.Println(a, len(a), "\t", b, len(b))
import pdb
import sqlalchemy as sa
from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
engine = sa.create_engine("sqlite:///:memory:", echo=True)
@mac01021
mac01021 / gist:8046451
Created December 19, 2013 21:20
a query
records =\
(session.query(LaborItem)
.join(ServiceUnit, ServiceUnit.id == LaborItem.punch_unit_id)
.filter(LaborItem.date <= days[-1])
.filter(LaborItem.date >= days[0])
.filter(*unit_filters(LaborItem.punch_unit_id))
.filter(ServiceUnit.is_active_sql(days[-1]))# is this what we want for long date ranges?
.options(sa.orm.joinedload('pay_type'))
.options(sa.orm.joinedload('pay_type.versions'))
.options(sa.orm.joinedload('punch_job'))
func Daemonize() {
go func() {
fmt.Println("Daemonizing...")
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Signal(syscall.SIGHUP))
for _ = range ch {
}
}()
}
#from data:stack import *
def Box box(st Int, hgt Int, wdt Int)
def [st Int, hgt Int] .box [pos Int] Box { closed(st, hgt, pos - o:st) }
def area[box Box] Int { box:hgt * box:wdt }
def [a Box] > [b Box] Bool { area[a] > area[b] }
def Part part(side Side, typ String, size Int)
def Side {
left
right
none
}
def symmetrize[parts Array[Part]] Array[String] {
let symmetric Array[String] = newArray[]
def passwordFrom[template String] String {
map[template, passChar].scrambled
}
def passChar[c Rune] Rune {
if c = {
'a': lowercase[rand[0, 26]]
'A': uppercase[rand[0, 26]]
'0': digits[rand[0, 10]]
'.': punctation[rand[0, 14]]
@mac01021
mac01021 / gist:b0780377077758b663ab
Created July 24, 2015 21:27
Simple connection error code
FetchRequest req = new FetchRequestBuilder()
.clientId(clientId)
.addFetch(topic, partition, offset, fetchSize)
.minBytes(1)
.maxWait(250)
.build();
FetchResponse resp = underlying.fetch(req);
if(resp.hasError()) {
int code = resp.errorCode(topic, partition);
if (code == 9) {