Skip to content

Instantly share code, notes, and snippets.

View dcramer's full-sized avatar
💭
I may be slow to respond.

David Cramer dcramer

💭
I may be slow to respond.
View GitHub Profile
@dcramer
dcramer / time-series-ring-buffer.js
Last active August 29, 2015 14:00
JavaScript time-series ring buffer
var TimeSeriesRingBuffer = function(size) {
this._lastTS = 0;
this._size = size;
this.reset();
};
TimeSeriesRingBuffer.prototype.reset = function(){
this._buffer = new Array(this._size);
for (var i = 0; i < this._size; i++) {
this._buffer[i] = 0;
@dcramer
dcramer / pgbouncer.rb
Created December 16, 2014 19:26
Scout pgbouncer plugin
class PgbouncerStats < Scout::Plugin
# need the ruby-pg gem
needs 'pg'
OPTIONS=<<-EOS
user:
name: Pgbouncer username
notes: Specify the username to connect with
password:
name: Pgbouncer password
'use strict';
var gulp = require('gulp'),
gp_changed = require('gulp-changed'),
gp_clean = require('gulp-clean'),
gp_concat = require('gulp-concat'),
gp_filesize = require('gulp-filesize'),
gp_less = require('gulp-less'),
gp_rename = require('gulp-rename'),
gp_uglify = require('gulp-uglify'),
@dcramer
dcramer / foo.md
Last active August 29, 2015 14:13

Item List => Item => ItemStatusSelector

  • Need to maintain certain state in ItemStatusSelector (specifically have we "saved" the change, this is to avoid passing useless properties all over the place like itemStatusIsSaving)
  • Currenlty Item List controls item via prop, which controls item status via prop. This means we pass an onStatusChange all the way back to Item List.
  • [Re]flux seems to resolve this by using some store/action combo, but unclear if "Item" is in an "item list" store or if each item should be its own store, or how "change item status" should actually flow
@dcramer
dcramer / cleanup_redis_tsdb.py
Last active August 29, 2015 14:13
clean up data that should have been expired but wasnt
#!/usr/bin/env python
from sentry.utils.runner import configure
configure()
from datetime import datetime, timedelta
from sentry.app import tsdb
def cleanup_connection(connection, epoch):
def delete(key):
@dcramer
dcramer / mailgun.py
Created January 29, 2015 06:12
sentry-mailgun
import logging
from django.http import HttpResponse
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
from email_reply_parser import EmailReplyParser
from email.utils import parseaddr
from sentry.tasks.email import process_inbound_email
api.assign() =>
AssignAction(...)
this.request('...')
.success(() => AssignSuccessAction())
.error(() => AssignErrorAction())
ThingStore =>
onAssign:
// we want to emulate a Set() for this
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'simple',
},
'sentry': {
>>> import subprocess
>>> proc = subprocess.Popen(['git', 'clone', 'git@github.com:getsentry/sentry.git', '/tmp/ds-repo-1'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
>>> print(proc.communicate())
("Cloning into '/tmp/ds-repo-1'...\n", None)
"""
A two-part middleware which modifies request.COOKIES and adds a set and delete method.
`set` matches django.http.HttpResponse.set_cookie
`delete` matches django.http.HttpResponse.delete_cookie
MIDDLEWARE_CLASSES = (
'django_cookies.CookiePreHandlerMiddleware',
...
'django_cookies.CookiePostHandlerMiddleware',