Skip to content

Instantly share code, notes, and snippets.

View cameronmaske's full-sized avatar

Cameron Maske cameronmaske

View GitHub Profile
@cameronmaske
cameronmaske / encode.py
Last active February 5, 2024 19:16
base64 that actually encodes URL safe (no '=' nonsense)
"""
base64's `urlsafe_b64encode` uses '=' as padding.
These are not URL safe when used in URL paramaters.
Functions below work around this to strip/add back in padding.
See:
https://docs.python.org/2/library/base64.html
https://mail.python.org/pipermail/python-bugs-list/2007-February/037195.html
"""
@cameronmaske
cameronmaske / celery-monitor.py
Created October 27, 2014 02:55
Monitor celery queue backlog and concurrency with Librarto.
from myproject.config import celery_app # Change this.
import requests
import librato
import time
import os
LIBRATO_USERNAME = ""
LIBRATO_API_TOKEN = ""
RABBIT_MQ_API_URL "http://localhost:15672/api/"
RABBIT_MQ_USERNAME = ""
from tests import TestCase
def TestTasks(TestCase):
signals = False
def before(self):
self.model = Bla()
def after(self):
print("done")
@cameronmaske
cameronmaske / Dockerfile
Created July 11, 2014 13:33
PhantomJS + Python (For Selenium)
FROM orchardup/python:2.7
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y libpng12-dev libsvga1-dev libjpeg8-dev libfreetype6-dev libjasper-dev fontconfig
# Install PhantomJS
RUN mkdir /opt/phantomjs-1.9.2
RUN apt-get install -y wget
RUN wget -O /tmp/phantomjs-1.9.2.tar.gz https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
# encoding: utf-8
from __future__ import unicode_literals
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select
class Scraper():
def __init__(self):

Keybase proof

I hereby claim:

  • I am cameronmaske on github.
  • I am cameronmaske (https://keybase.io/cameronmaske) on keybase.
  • I have a public key whose fingerprint is 08D0 2E91 2D9C 17EC 8873 E9F1 16AF 160A 264C 8ECB

To claim this, I am signing this object:

@cameronmaske
cameronmaske / tracer.py
Created March 6, 2014 18:08
Really useful for debugging functions, particularly in django's manage.py shell
import sys
def tracer(frame, event, arg):
if event != 'call':
return
co = frame.f_code
func_name = co.co_name
if func_name == 'write':
# Ignore write() calls from print statements
return
function nestCollection(model, attributeName, nestedCollection) {
//setup nested references
for (var i = 0; i < nestedCollection.length; i++) {
model.attributes[attributeName][i] = nestedCollection.at(i).attributes;
}
//create empty arrays if none
nestedCollection.bind('add', function (initiative) {
if (!model.get(attributeName)) {
model.attributes[attributeName] = [];