Skip to content

Instantly share code, notes, and snippets.

View hughes's full-sized avatar

Matt Hughes hughes

View GitHub Profile
// Returns the orginal of an integer
function getOrdinal(n) {
var s = ["th","st","nd","rd"];
var v = n % 100;
return (s[(v - 20) % 10] || s[v] || s[0]);
}
--- 192.168.1.1 ping statistics ---
17 packets transmitted, 7 packets received, 58.8% packet loss
round-trip min/avg/max/stddev = 157.283/246.130/414.386/74.276 ms
// this module is leaky
// it syncs
module.exports = require('./lib/leaky');
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
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.
@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'):
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
$ 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'))
@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 = {
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));