Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

David Cramer dcramer

I may be slow to respond.
View GitHub Profile
class BaseJobResource(Resource):
def dispatch_request(
self, provider: str, owner_name: str, repo_name: str, build_number: int, job_number: int, *args, **kwargs
) -> Response:
queryset = Job.query.join(Build, == Job.build_id).join(
Repository, == Build.repository_id
Repository.provider == RepositoryProvider(provider),
Repository.owner_name == owner_name, == repo_name,
View componentToString.js
import ReactDOM from 'react-dom';
const componentToString = function(node) {
let el = document.createElement('div');
ReactDOM.render(node, el);
return el.innerHTML;
View gist:550438
class QuerySetDoubleIteration(Exception):
"A QuerySet was iterated over twice, you probably want to list() it."
# "Skinny" here means we use iterator by default, rather than
# ballooning in memory.
class SkinnyManager(Manager):
def get_query_set(self):
return SkinnyQuerySet(self.model, using=self._db)
dcramer / gist:7728286
Created Dec 1, 2013
find oldest file in directory
View gist:7728286
find -type f -printf '%T+ %p\n' | sort -r | head -1
View responses.rst
import responses

def test_my_api():
    responses.add(responses.GET, '',
                  body='{"error": "not found"}', status=404,
View gist:7330744
# supervisor
command=uwsgi --addr=
# when you restart it does them in batches, instead of one at a time
$ sudo supervisorctl restart sentry
- stops all 10 procs
View gist:6775018
var Changes = angular.module('Changes', ['ngAnimate', 'ngRoute']).
config(['$routeProvider', function($routeProvider) {
when('/', {
templateUrl: 'partials/change-list.html',
resolve: {
initialData: function($http) {
return $http.get('/api/0/changes/');
View gist:6774625
<section ng-controller="ChangeListCtrl">
<table class="change-list table table-striped">
<tr class="status-{{}} result-{{}}"
ng-repeat="change in changes | orderBy:dateModified:true" ng-animate="'animate-fade'">
<div class="indicator" title="{{}}">
<div data-result="{{}}"
data-value="{{change.lastBuild.progress}}" ng-radial-progress-bar>&nbsp;</div>
dcramer / gist:6682862
Created Sep 24, 2013
TIL use 'while 1' instead of 'while True'
View gist:6682862
dcramer:buildbox in ~/Development/buildbox on git:master
$ python -m timeit '(True and "pass")'
10000000 loops, best of 3: 0.0512 usec per loop
dcramer:buildbox in ~/Development/buildbox on git:master
$ python -m timeit '(True and "pass")'
10000000 loops, best of 3: 0.049 usec per loop
dcramer:buildbox in ~/Development/buildbox on git:master
$ python -m timeit '(True and "pass")'
View gist:6568624
$ pip install --help
pip install [options] <requirement specifier> ...
pip install [options] -r <requirements file> ...
pip install [options] [-e] <vcs project url> ...
pip install [options] [-e] <local project path> ...
pip install [options] <archive url/path> ...