Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jsatt on github.
  • I am jsatt (https://keybase.io/jsatt) on keybase.
  • I have a public key whose fingerprint is 9C65 DD04 8308 047C F10C 7B82 040D 9950 1ADB AD9E

To claim this, I am signing this object:

@jsatt
jsatt / setup_octoprint
Last active March 16, 2019 01:46
Automate setup of Octoprint. Intended to be run on a fresh install of Raspbian.
#!/bin/bash
set -e
OCTO_USER=octoprint
BASE_DIR=/home/$OCTO_USER
if [ ! `id -u` == "0" ]; then
echo "You must run this script as root."
exit 1
@jsatt
jsatt / get_or_none.py
Created July 23, 2018 14:25
django get_or_none
from django.db.models import Model, Manager, QuerySet
def get_or_none(model, *args, **kwargs):
if issubclass(model, Model):
qs = model._default_manager.all()
elif isinstance(model, Manager):
qs = model.all()
manager = model
model = manager.model
@jsatt
jsatt / examples.md
Last active January 19, 2017 15:21
GPG examples
@jsatt
jsatt / policies.json
Created September 14, 2016 00:50
AWS IAM Policy examples
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:ListUsers"
],
"Resource": "arn:aws:iam::*:*"
},
@jsatt
jsatt / settings.py
Last active August 25, 2016 21:18
Test unmanaged models
TEST_RUNNER = b'test_runner.CustomRunner'
@jsatt
jsatt / proto-test.js
Created June 17, 2016 14:55
Understanding js prototyping
res = function(){
mr = function(obj){
this.testing = obj
// or _.extend(this, obj) or Object.assign(this, obj) to extend this
};
mr.prototype.tester = function(){
return this.testing.test
};
return mr
}
@jsatt
jsatt / examples.py
Created March 6, 2016 03:23
AWS Signing v4
### example calls
def post_key(path, **kwargs):
'''
post_key('testing/', data=json.dumps({"blah": 123}))
'''
endpoint = '{}{}'.format(ENDPOINT, path)
req = requests.Request('POST', endpoint, **kwargs)
sign_request(req)
return make_request(req)
@jsatt
jsatt / gist:400adcc7a82a70f99187
Created November 9, 2015 22:29
see all events on a qt widget
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.platformWindow().installEventFilter(self)
+
+ def eventFilter(self, obj, event):
+ print(event.type(), obj)
+ return super().eventFilter(obj, event)
@jsatt
jsatt / enumerated_enum.py
Last active September 12, 2017 19:40
A Python 3 Enum subclasses which allows for defining other attributes to the members.
from enum import Enum, EnumMeta
class EnumeratedEnumMeta(EnumMeta):
def __new__(metacls, *args):
enum_class = super().__new__(metacls, *args)
enum_class._value2member_map_ = {m.value: m for v, m in enum_class._value2member_map_.items()}
return enum_class
class LabeledEnum(Enum, metaclass=EnumeratedEnumMeta):