This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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 = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/Knetic/govaluate" | |
"os" | |
"bufio" | |
) | |
func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_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) |
OlderNewer