Skip to content

Instantly share code, notes, and snippets.

View highsineburgh's full-sized avatar

Tyler Field highsineburgh

View GitHub Profile
@highsineburgh
highsineburgh / Jinja Template to PDF
Last active November 27, 2019 09:36
Simple example of converting a jinja template to .pdf with weasyprint
from jinja2 import Environment, PackageLoader
from weasyprint import HTML, CSS
def render_inst(tmpl, region, state, **kwargs):
template = Environment(loader=PackageLoader(local_env, 'templates')).get_template(tmpl)
file_name = 'Instance_Summary-{0}-{1}-{2}.pdf'.format(region, state, datetime.date.today().strftime('%Y-%m-%d'))
HTML(string=template.render(kwargs)).write_pdf(file_name, stylesheets=[CSS(filename="stylesheets/instance_summary.css")])
@highsineburgh
highsineburgh / excerise-maps.go
Last active August 29, 2015 14:16
Sample code to solve the exercise-maps in a Tour of Go
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
m := make(map[string]int)
for _, v := range strings.Fields(s) {
@highsineburgh
highsineburgh / models.py
Last active April 9, 2018 21:32
Watermark and generate a thumbnail on save, Django ImageField
class Image(models.Model):
image = models.ImageField(storage=images, upload_to='images')
thumbnail = models.ImageField(storage=thumbs, upload_to='thumbnails', null=True,
blank=True)
def __str__(self):
return self.title
def _check_pos(self, pos, x, y):
@highsineburgh
highsineburgh / paramiko_example.py
Created September 3, 2014 22:19
Basic example of SSH with paramiko
import paramiko
import getpass
def main():
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
hostname = raw_input('hostname: ')
username = raw_input('username: ')
@highsineburgh
highsineburgh / imagewiththumbnails_updateable.py
Last active April 10, 2018 18:16 — forked from valberg/imagewiththumbnails_updateable.py
Generate a thumbnail on image upload Django
# Extension of http://www.yilmazhuseyin.com/blog/dev/create-thumbnails-imagefield-django/
# updated for Python 3
from django.core.files.storage import FileSystemStorage
from django.core.files.uploadedfile import SimpleUploadedFile
from PIL import Image
import io
import os
from django.conf import settings
@highsineburgh
highsineburgh / video.cpp
Last active August 29, 2015 14:04
Simple Video Capture Application for openCV
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <time.h>
using namespace std;
using namespace cv;
int main(int, char**) {
time_t startTime = time(0)
int frames = 0;
@highsineburgh
highsineburgh / models.py
Created July 16, 2014 17:34
Unit testing for MongoEngine Documents in Django
from mongoengine import Document, StringField
class MyModel(Document):
name = StringField()
meta = {'allow_inheritance': True }
class TestMyModel(MyModel):
pass