Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
mattdeboard / bootstrap.clj
Created April 15, 2012 21:44
Custom bootstrap for using Cascalog in emacs to address a memory issue I was having.
(ns doop.bootstrap
(:use cascalog.playground))
(defn my-bootstrap-emacs []
"Custom bootstrap to tweak the hadoop job config for cascalog, to help
manage memory."
(bootstrap-emacs)
(alter-var-root #'cascalog.conf/*JOB-CONF* (fn [& ignored]
{"io.sort.mb" 1})))
(with-open [client (c/create-client)]
(let [response (c/GET client jira-project-url :auth {:user "user" :password "password"})]
def take(n, seq):
"Return first n items of the seq as a list"
return list(islice(seq, n))
def drop(n, seq):
"Return seq with the first n items removed."
return list(islice(seq, n, None, 1))
def split_by(n, seq):
return [take(n, seq), drop(n, seq)]
class BaseModelAdmin(object):
#...snip...
def formfield_for_manytomany(self, db_field, request=None, **kwargs):
"""
Get a form Field for a ManyToManyField.
"""
# If it uses an intermediary model that isn't auto created, don't show
# a field in admin.
if not db_field.rel.through._meta.auto_created:
return None
class SeoSiteFacet(models.Model):
"""This model defines the default Custom Facet(s) for a given site."""
seosite = models.ForeignKey('SeoSite')
customfacet = models.ForeignKey('CustomFacet')
is_default = models.BooleanField('Make this CustomFacet default',
default=False)
class Meta:
# This is a ridiculous hack so we can display facets using the select
# box instead of the dropdowns.
configurations = []
for c in configurations_qs:
configurations.append({'id': c.id, 'title': unicode(c)})
configurations = list(configurations)
google_analytics = list([{'id': ga.id, 'title' : ga.web_property_id} for ga
in google_analytics_objs])
def querytree(s):
"""
Build a list of nodes to describe the nested structure of a querystring.
"""
Node = namedtuple("Node", "level value")
stack = []
# A node has children if there is a left paren before a right paren,
# starting from hte index position where the node begins.
for idx, char in enumerate(s):
(defun jira-rest-api-interact (method data &optional path)
"Interact with the API using method 'method' and data 'data'.
Optional arg 'path' may be provided to specify another location further
down the URL structure to send the request."
(if (not jira-rest-auth-info)
(message "You must login first, 'M-x jira-rest-login'.")
(let ((url-request-method method)
(url-request-extra-headers
`(("Content-Type" . "application/json")
("Authorization" . ,jira-rest-auth-info)))
def test_no_buid_sitemap(self):
from lxml import etree
from StringIO import StringIO
site = SeoSite.objects.get(id=1)
site.business_units = []
site.save()
job1 = JobDetailFactory.build()
job1.save()
job2 = JobDetailFactory.build(uid=17059007, id=39558)
job2.save()
@mattdeboard
mattdeboard / throttle.py
Created June 12, 2012 13:29
Throttling subclass to allow API dev with TastyPie & Django's DummyCache
from django.conf import settings
from tastypie.throttle import CacheDBThrottle
class SmartCacheDBThrottle(CacheDBThrottle):
"""
Custom throttling class to address bug in Tastypie that manifests
when trying to run tests or do any kind of development with a Resource
that has some kind of throttling configured. Tastypie is not smart