Skip to content

Instantly share code, notes, and snippets.

View jeremylowery's full-sized avatar

Jeremy Lowery jeremylowery

  • EHO
  • Temple, TX
View GitHub Profile
@jeremylowery
jeremylowery / pkg-diff.py
Created May 17, 2016 15:36
Ubuntu: Show version by version comparison of manually installed packages in current distribution with another distribution
#!/usr/bin/env python
""" Show the difference between the versions of manually installed
packages on this system with the given distribution.
"""
import re
import sys
def main():
if not distribution():
sys.stderr.write("Could not determine distribution from /etc/os-release\n")
@jeremylowery
jeremylowery / coroutine_generator_demo.py
Last active May 17, 2016 15:38
Demonstration of using python generators as coroutines to implement cooperative multi-tasking
"""
Demonstration of using python generators as coroutines to implement
cooperative multi-tasking. Catting multiple files in chunks to stdout.
There is room for much more generationization of operators, for example
implementing the yielding value as a Future.
Pass in a list of file names.
"""
import sys
@jeremylowery
jeremylowery / gradient_png.py
Created July 28, 2016 15:12
gradient creating image script
import sys
def write_png(filename, width, height, rgb_func):
import zlib
import struct
import array
def output_chunk(out, chunk_type, data):
out.write(struct.pack("!I", len(data)))
""" Proof of concept of looking up a matching value based on multiple indexes
by reverse sorting and searching the combinations. O^log n I believe.
"""
from itertools import combinations
class Lookup:
def __init__(self, name=None):
self.name = name
self.index = {}
@jeremylowery
jeremylowery / goevaluate_repl.go
Created December 18, 2016 21:36
REPL for library at github.com/Knetic/govaluate
package main
import (
"fmt"
"github.com/Knetic/govaluate"
"os"
"bufio"
)
func main() {
@jeremylowery
jeremylowery / goexec.go
Created January 14, 2017 01:26
Run a subprocess and connect to it with golang
// Credit to https://coderwall.com/p/ik5xxa/run-a-subprocess-and-connect-to-it-with-golang
package main
import (
"fmt"
"os/exec"
"os"
)
func exec_command(program string, args ...string) {
// Provider interface for your object
type PatientProvider interface {
PatientByID(id int) Patient
  InactivePatients() []Patient
}
// Dependency interface needed by object
type SQLExecutor interface {
ExecuteSQL(sql string) []SQLRecord
}
type SQLLogger struct {
e SQLExecutor
}
func (s *SQLLogger) ExecuteSQL(sql string) []SQLRecord {
r := s.e.ExecuteSQL(sql)
fmt.Printf("SQL (%d records): %v", len(r), sql)
return r
}
def create_invoice(db, customer_id, line_items):
customer = customer_by_id(db, customer_id)
invoice_id = new_invoice_id(db)
insert_record(db, 'invoice', id=invoice_id, customer_id=customer_id)
for item in line_items:
insert_record(db, 'line_item', invoice_id=invoice_id,
amount=item.amount, product=item.product_id)
return invoice_id
def customer_by_id(db, customer_id)
_db = None
def set_db(db):
global _db
_db = db
def create_invoice(customer_id, line_items):
customer = customer_by_id(customer_id)
invoice_id = new_invoice_id()
insert_record('invoice', id=invoice_id, customer_id=customer_id)