Skip to content

Instantly share code, notes, and snippets.

View zacharyvoase's full-sized avatar

Zack Voase zacharyvoase

View GitHub Profile
@zacharyvoase
zacharyvoase / jsonutils.py
Created November 11, 2010 10:20
JSONResponse for Django
# -*- coding: utf-8 -*-
import django.http
import simplejson as json
class JSONResponse(django.http.HttpResponse):
"""Represent a HTTP response with a Content-Type of 'application/json'.
@zacharyvoase
zacharyvoase / pythonrc.py
Created May 4, 2011 13:31 — forked from benhodgson/pythonrc.py
Python startup file with completion, history and colored source browsing.
import inspect
import sys
def src(obj):
"""Read the source of an object in the interpreter."""
def highlight(source):
try:
import pygments
import sys
import subprocess
import tempfile
import urllib
text = sys.stdin.read()
chart_url_template = ('http://chart.apis.google.com/chart?'
'cht=qr&chs=300x300&chl={data}&chld=H|0')
chart_url = chart_url_template.format(data=urllib.quote(text))
@zacharyvoase
zacharyvoase / 5syllable_with_penultimate_emphasis.sh
Last active July 11, 2022 18:21
5-syllable words with the emphasis on the penultimate syllable
$ curl 'http://dingo.sbs.arizona.edu/~hammond/lsasummer03/newdic.txt' | awk '$2 ~ /^...''.$/ { print $4 }'
abbreviation
abracadabra
academician
accelerando
accommodation
acculturation
adjudication
alienation
alleviation
@zacharyvoase
zacharyvoase / lazy_model_loader.py
Created April 6, 2017 02:04
A Lazy Model loader for Django
"""
Do `import lazy_model_loader` as early as possible in your application's
lifecycle, then:
from lazymodels.my_app import MyModel
def some_func():
return MyModel.objects.filter(name='Foo')
We're hacking the Python import system to enable you to import lazy references
@zacharyvoase
zacharyvoase / caseless_dict.py
Created August 14, 2011 23:20
Fast, case-ignoring and preserving dictionaries in Python.
"""A caseless dictionary implementation."""
from collections import MutableMapping
class CaselessDictionary(MutableMapping):
"""
A dictionary-like object which ignores but preserves the case of strings.
@zacharyvoase
zacharyvoase / process_local.py
Created September 1, 2012 05:31
A fork-friendly threading.local().
import os
import threading
class ObjectProxy(object):
"""Wrap a target object and provide an interface to its underlying object.
This is especially useful when you're defining an interface which overrides
the attribute access magic methods, but you still need to access named
@zacharyvoase
zacharyvoase / dsa.sh
Created June 24, 2011 11:32
DSA signing using openssl CLI
openssl dsaparam 1024 < /dev/random > dsa_param.pem
openssl gendsa dsa_param.pem -out dsa_priv.pem
openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem
# DSA system now made up of: dsa_param.pem, dsa_pub.pem, dsa_priv.pem
echo "foobar" > foo.txt
openssl sha1 < foo.txt > foo.txt.sha1
openssl dgst -dss1 -sign dsa_priv.pem foo.txt.sha1 > foo.txt.sig
openssl dgst -dss1 -verify dsa_pub.pem -signature foo.txt.sig foo.txt.sha1
//
// BindingTranslation.swift
// Swoleness
//
// Created by Zack Voase on 5/23/20.
// Copyright © 2020 Zack Voase. All rights reserved.
//
import Foundation
import SwiftUI
func intTextBinding(
intBinding: Binding<Int?>,
numberFormatter: NumberFormatter = NumberFormatter()) -> Binding<String> {
return Binding(
get: { numberFormatter.string(for: intBinding.wrappedValue)! },
set: { numberString in
if let number = numberFormatter.number(from: numberString) {
intBinding.wrappedValue = Int(truncating: number)
} else {
intBinding.wrappedValue = nil