Skip to content

Instantly share code, notes, and snippets.

@blapid
blapid / example_bad.cpp
Last active March 10, 2018 10:30
pybind11 issue examples
#include <stdio.h>
#include <list>
#include <memory>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
struct B;
struct A {
@blapid
blapid / pybind11_list_ownership_experiment.cpp
Last active March 10, 2018 10:24
Playing around with ownerships and lists in pybind11
#include <stdio.h>
#include <list>
#include <memory>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
struct B;
struct A {
@blapid
blapid / test.cpp
Last active October 24, 2017 12:03
Experiments with C++17 constructor template argument deduction and unit testing static asserts. Tested on Ubuntu 16.04.3, Clang 5.0.1-svn314893
#include "llcpp/llcpp.hpp"
#include <stdio.h>
#include <utility>
// typestring.hpp
template<typename CharT, CharT... Chars>
struct typestring {
static constexpr const CharT *data() { return chars; }
@blapid
blapid / ImageFileFieldSerializer.py
Created October 31, 2014 18:36
Django Rest Framework ImageFileField Serializer
'''
When ImageFields are serialized with Djang Rest Framework you only get
the URN of the file. So I made this serializer which adds the rest
of the URI.
'''
class ImageFileFieldSerializer(serializers.WritableField):
def __init__(self, *args, **kwargs):
super(ImageFileFieldSerializer, self).__init__(*args, **kwargs)
def to_native(self, obj):
@blapid
blapid / HideNotFoundSubClass.py
Last active February 24, 2017 01:45
django-rest-framework - raise permission denied instead of not found
def HideNotFoundSubClass(base_class):
'''
So apparently, django-rest-framework's permission checks aren't quite enough
for me.
It has 2 steps:
1. Check global permissions by calling has_permission for each of the
permission classes
2. Check object permissions by calling has_object_permission for each
of the permission classes
Between 1 and 2, it tries to find the object with get_object().
@blapid
blapid / gist:5623670
Created May 21, 2013 22:06
Example of using object PATCH request in Swift
def truncateObject(apitoken, swifturl, container, object, size):
url = swifturl[1]
body=""
headers = { "X-Auth-Token":apitoken, "Content-type":"application/json-patch",
"x-patch-offset":0, "x-new-size":size, "Content-Length":0
}
conn = httplib.HTTPConnection(url)
conn.request("PATCH", "%s/%s/%s" % (swifturl[2],container,object), body, headers)
response = conn.getresponse()