This file contains 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
# -*- 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'. | |
This file contains 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 inspect | |
import sys | |
def src(obj): | |
"""Read the source of an object in the interpreter.""" | |
def highlight(source): | |
try: | |
import pygments |
This file contains 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 | |
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)) |
This file contains 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
$ curl 'http://dingo.sbs.arizona.edu/~hammond/lsasummer03/newdic.txt' | awk '$2 ~ /^...''.$/ { print $4 }' | |
abbreviation | |
abracadabra | |
academician | |
accelerando | |
accommodation | |
acculturation | |
adjudication | |
alienation | |
alleviation |
This file contains 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
""" | |
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 |
This file contains 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
"""A caseless dictionary implementation.""" | |
from collections import MutableMapping | |
class CaselessDictionary(MutableMapping): | |
""" | |
A dictionary-like object which ignores but preserves the case of strings. |
This file contains 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 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 |
This file contains 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
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 |
This file contains 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
// | |
// BindingTranslation.swift | |
// Swoleness | |
// | |
// Created by Zack Voase on 5/23/20. | |
// Copyright © 2020 Zack Voase. All rights reserved. | |
// | |
import Foundation | |
import SwiftUI |
This file contains 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
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 |
NewerOlder