Skip to content

Instantly share code, notes, and snippets.

View hughes's full-sized avatar

Matt Hughes hughes

View GitHub Profile
class YourResource(ModelResource):
custom_field = fields.CharField()
def dehydrate_custom_field(self, bundle):
return "this is a custom field"
def hydrate_custom_field(self, bundle):
do_something_with(bundle.data.get('custom_field', 'default'))
return bundle
var ლ = function(wat) { console.log(wat); }
var ಠ益ಠლ = 'wat'
ლ(ಠ益ಠლ) // prints wat
this.area = d3.svg.area()
.interpolate("monotone")
.x(function(d) {
return this.x(d.x);
}.bind(this))
.y0(height)
.y1(function(d) {
return this.y(d.y);
}.bind(this));
@hughes
hughes / example.py
Last active December 14, 2015 08:39
Recording data with Statistician
import requests
import simplejson
data = {
"metric": "your-metric-slug",
"value": somevalue,
"timestamp": sometime.isoformat() # optional, defaults to now
}
headers = {
$ paver test
---> pavement.test
nosetests
..................F..........
======================================================================
FAIL: test_time (tests.utils.test_template.TestHumanize)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/hughes/Documents/dev/flower/tests/utils/test_template.py", line 51, in test_time
humanize(1343911558.305793, type='time'))
11:32 < hughes> OH FUCK
11:32 < hughes> mack: help
11:32 < robot5000> PROBLEM i-a56b6ad4 HTTP HTTP CRITICAL: HTTP/1.1 502 Bad Gateway - 323 bytes in 0.145
second response time
11:33 < robot5000> PROBLEM i-a76b6ad6 Login CRITICAL - Socket timeout after 10 seconds
11:34 < robot5000> PROBLEM i-a56b6ad4 Login CRITICAL - Socket timeout after 10 seconds
11:34 < robot5000> PROBLEM i-c75349b6 HTTP CRITICAL - Socket timeout after 10 seconds
11:34 < robot5000> PROBLEM i-a76b6ad6 HTTP CRITICAL - Socket timeout after 10 seconds
11:34 < robot5000> PROBLEM i-c75349b6 Login CRITICAL - Socket timeout after 10 seconds
@hughes
hughes / pie.py
Created December 11, 2012 19:12 — forked from EdwardIII/pie.py
from tastypie.resources import ModelResource, ALL_WITH_RELATIONS
from people.models import Basket, Person
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
class BasketAuthorization(Authorization):
def is_authorized(self, request, object=None):
print request
if request and hasattr(request, 'user') and hasattr(request.user, 'employer'):
class FolderManager(models.Manager):
# so that we can do Folder.objects...
def get_query_set(self):
return super(FolderManager, self).get_query_set().filter(is_folder=True)
class Folder(Item):
'''
this class is kind of funny looking because Items cannot have
a ForeignKey field pointing to a subclass of itself.
def dehydrate_images(self, bundle):
images = OfferImage.objects.filter(offer=bundle.obj.pk)
resource = OfferImageResource()
result = []
for image in images:
bundle = resource.build_bundle(obj=image, request=bundle.request)
data = resource.full_dehydrate(bundle).data
data["resource_uri"] = resource.get_resource_uri(image)
result.append(data)
return result
// this module is leaky
// it syncs
module.exports = require('./lib/leaky');