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 / haproxy.cfg
Created April 3, 2022 21:32
haproxy configuration for seafile
frontend seaweb
bind 0.0.0.0:80
bind 0.0.0.0:443 ssl crt /etc/haproxy/certs/ alpn h2,http/1.1
mode http
## Force to HTTPS
http-request redirect scheme https unless { ssl_fc }
http-request set-header X-Forwarded-Proto https
http-request set-header X-Forwarded-Host %[req.hdr(Host)]
@jeremylowery
jeremylowery / datepicker.js
Created October 10, 2021 21:56 — forked from icai/datepicker.js
vue 2 directive with jqueryui
Vue.directive('datepicker', {
bind: function (el, binding, vnode, oldVnode) {
$(el).datepicker({
onSelect: function (date) {
vnode.context.date = date;
}
});
},
update: function (el, binding, vnode, oldVnode) {
$(el).datepicker('setDate', binding.value);
_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)
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)
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
}
// 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
}
@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) {
@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() {
""" 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 / 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)))