Skip to content

Instantly share code, notes, and snippets.

View zacharyvoase's full-sized avatar

Zack Voase zacharyvoase

View GitHub Profile
//
// 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
@zacharyvoase
zacharyvoase / anno.py
Created May 22, 2020 05:45
Anno 1800 island optimizer using OR-Tools CP-SAT constraint solver
#!/usr/bin/env python3
from collections import namedtuple
from ortools.sat.python import cp_model
import itertools
import sys
MAX_INT = 1000000000000
RATE_SCALING = 1000000
@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 / modelinject.py
Last active April 5, 2017 22:46
Django Model Injection
# -*- coding: utf-8 -*-
"""
Model class injectors, to make Django 1.9+'s app registry easier to work with.
Django 1.9 made it an error to import an app's models submodule when importing
the app module itself. Instead, you should use `apps.get_model(app_label,
model_name)` to get the model class, and signals should be wired up in the
`ready()` hook of a custom `AppConfig` subclass.
@zacharyvoase
zacharyvoase / countminsip.py
Last active March 14, 2017 00:52
CountMinSip: A simple CountMinSketch in Python using csiphash
# -*- coding: utf-8 -*-
"""
SipHash works well as a family of pairwise-independent hash functions for a CountMinSketch.
This implementation uses my Python cffi-bound version: https://github.com/zacharyvoase/python-csiphash
"""
import csiphash
import math
import numpy as np
@zacharyvoase
zacharyvoase / translatable.py
Created February 6, 2017 23:54
Translatable: A monad for composable translations.
"""
A monad for composable translations.
Wrap simple values:
>>> t = Translatable.value(123)
>>> t # doctest: +ELLIPSIS
Translatable(translation_keys=(), function=<function <lambda> at ...>)
>>> t.translate({})
123
@zacharyvoase
zacharyvoase / bootstrapValidation.js
Created June 21, 2016 01:31
Sync form field validation state between Angular and Bootstrap
/**
* Angular's ngModel helpfully adds the `ng-invalid` class to form controls
* containing invalid input. However, Bootstrap forms are typically structured
* like so:
*
* <div class="form-group">
* <label>Name*</label>
* <input class="form-control" type="text" ng-model="user.name" />
* </div>
*
@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

Keybase proof

I hereby claim:

  • I am zacharyvoase on github.
  • I am meat (https://keybase.io/meat) on keybase.
  • I have a public key whose fingerprint is EB8F 83DF B7F7 7478 5826 635C 8C5B 7543 A8AB F545

To claim this, I am signing this object: