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
from itertools import chain | |
class DeepPartial(object): | |
def __init__(self, func, *args, **kwargs): | |
self.func = func | |
self.args = args | |
self.kwargs = kwargs | |
def _call(self, callee): |
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
from struct import unpack | |
import math | |
try: | |
import numpy as np | |
except ImportError: | |
print('numpy is required to enable STL transformation.') | |
class _STLFile(object): | |
name = None |
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
class NestedListMixin(object): | |
def get_nested_list(self, queryset, serializer_class): | |
""" | |
List view in function form. | |
First argument can be a list or a queryset. | |
""" | |
page = self.paginate_queryset(queryset) | |
if page is not None: | |
serializer = serializer_class(page, many=True, |
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
from rest_framework import serializers | |
class ConstantField(serializers.ReadOnlyField): | |
def __init__(self, value, *args, **kwargs): | |
self._constant = value | |
super(ConstantField, self).__init__(*args, **kwargs) | |
def get_attribute(self, obj): | |
return self._constant | |
def to_representation(self, value): | |
return value |
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
from rest_framework.permissions import DjangoModelPermissions | |
class BaseModelPerm(DjangoModelPermissions): | |
def has_permission(self, request, view): | |
perms = self.get_required_permissions(request.method, self.model) | |
return ( | |
request.user and | |
(request.user.is_authenticated() or not self.authenticated_users_only) and | |
request.user.has_perms(perms) |
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
from operator import attrgetter | |
def maybe_prefetched(parent, related_manager): | |
#return related_manager | |
try: | |
cache = parent._prefetched_objects_cache | |
except AttributeError: | |
# Nothing is prefetched. | |
return related_manager |
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
def search_terms(s, quotes="\"'", delims='\n '): | |
""" | |
Same as shlex.split but allows for quotes to be left open. | |
And treats them as if they were never quoted. | |
""" | |
quote = '' | |
new_s = [''] | |
for i, c in enumerate(s, start=1): | |
if quote: | |
if c == quote: |
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
javascript:(function() { | |
var videoId = /[&?]v=(\w+)/g.exec(window.location.search); | |
if (videoId) { | |
videoId = videoId[1]; | |
window.location.href = window.location.origin + '/embed/' + videoId + '?autoplay=1'; | |
} else { | |
videoId = /\/embed\/(\w+)/g.exec(window.location.pathname); | |
if (!videoId) | |
alert("You're not on a video page dumbass."); | |
videoId = videoId[1]; |
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
<html> | |
<head> | |
<title></title> | |
<style type="text/css"> | |
div.sq { | |
position: absolute; | |
left: 10px; | |
width: 300px; | |
height: 300px; |
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
#! /usr/bin/python3 | |
import os | |
import argparse | |
from time import sleep | |
PATH = '/sys/bus/usb/devices/' | |
def reset_device(key, value, coerce, sleep_time): | |
for device_dir, dirs, files in os.walk(PATH, followlinks=True): | |
if device_dir != PATH: |
OlderNewer