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 / gist:1618119
Created January 16, 2012 00:00
Using Sentry from Heroku outside of Heroku
# create a dummy heroku app
heroku create --stack cedar
# add sentry
heroku addons:add sentry
# fetch your config
heroku config | grep SENTRY_DSN
# configure your application via http://getsentry.com/guide/
@dcramer
dcramer / heapqueue.py
Last active December 11, 2015 04:09
Refined Heap Queue for Python (including capped and max heap implementation)
import heapq
from threading import Lock
class HeapQueue(object):
def __init__(self, values=None, maxsize=None, reversed=False):
"""
Create a new heap queue.
- ``maxsize`` will create a capped queue.
@dcramer
dcramer / gist:5078280
Last active December 14, 2015 11:19
New Sentry Buffers
When an update comes into the system we fire off something like the following:
>>> app.buffer.incr(
>>> Group, # model class,
>>> {'times_seen': 1}, # counters
>>> {'id': group.id}, # filter restrictions, sometimes a composite key
>>> {'last_seen': now}, # metadata to update when buffer is processed
>>> )
This would get stored in a hash key as following:
@dcramer
dcramer / gist:5146800
Last active December 14, 2015 20:49
Code Review Quality/Performance Indicators

Questions to answer:

  • Is it a productivity hit?
  • What happens when only new hires are required to do code review?
  • How bad at large patches?
  • What about lack of automated tests?
  • Does a lot of back and forth (e.g. comments) indicate problems?
  • Does assigning more people (or less) to reviews improve anything?
  • How does a person spending more time committing (vs reviewing) affect the team?
import django.db
import collections
all_models = django.db.models.get_models()
def find_deps(models):
""" return a dict of {model : [all dependent models] """
deps = collections.defaultdict(set)
name_to_model = {}
for model in models:
@eric
eric / README.md
Last active December 21, 2015 20:39
Steps to get Sentry working over SSL on the JVM

Sentry and the JVM

Unfortunately Java's built-in cacerts do not include StartCom SSL root certificates.

Because of this, you must tell java to trust these certificates.

The easiest way I've found to do it is as follows:

1. Make a copy of the JRE cacerts

@jrichardlai
jrichardlai / ErrorManager.java
Last active February 7, 2018 20:44
Bugsnag integration with React Native
import android.util.Base64;
import android.util.Log;
import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.MetaData;
import com.bugsnag.android.Severity;
import com.facebook.react.bridge.*;
import java.io.File;
import java.io.InputStream;
@jdmaturen
jdmaturen / ExponentiallyDecayingSample.py
Created April 6, 2011 01:45
expontentially decaying sample algorithm w/ redis
import logging
from math import exp
from random import random
from time import sleep
from time import time
from uuid import uuid1
from redis.exceptions import WatchError
@cannikin
cannikin / deploy.rb
Last active October 22, 2018 09:02
Notify Sentry of a new release via Capistrano
# This task will notify Sentry via their API[1] that you have deployed
# a new release. It uses the release timestamp as the `version`
# (like 20151113182847) and the git ref as the optional `ref` value.
#
# This task requires several environment variables be set (or just
# hardcode the values in here if you like living on the edge):
#
# ENV['SENTRY_API_ENDPOINT'] : API endpoint, https://app.getsentry.com
# ENV['SENTRY_ORG'] : the organization for this app
# ENV['SENTRY_PROJECT'] : the project for this app
@mattrobenolt
mattrobenolt / cramermath.py
Created February 28, 2013 02:23
David Cramer math
"""
cramermath
~~~~~~~~~~
Usage:
>>> import cramermath
>>> cramermath.log(10)
0.014728067495500818
"""