Skip to content

Instantly share code, notes, and snippets.

View readevalprint's full-sized avatar
🤠
code is life

Tim readevalprint

🤠
code is life
View GitHub Profile
import sys, shutil, os, tempfile
from cStringIO import StringIO
TIMEOUT = 5
# SANDBOX_BIN = '/usr/bin/pypy-sandbox'
SANDBOX_BIN = '/home/ubuntu/pypy/pypy/goal/pypy-c' # update this for you
sys.path = [ '/home/ubuntu/pypy'] + sys.path
<html>
<title>Hi</title>
<body>
he he he
</body>
</html>
@readevalprint
readevalprint / index.html
Created May 5, 2011 04:29
The minimalist versions of django. One file. Read more at readevalprint.com/mini-django
<html>
<head>
<title>Hey {{name|default:"there"}}!</title>
</head>
<body>
It's a lovely day, eh {{name|default:"chap"}}?
</body>
</html>
@readevalprint
readevalprint / index.html
Created September 6, 2011 01:37
anya's page
<!DOCTYPE html>
<html>
<head>
<title> anyas page </title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(function(){
$("a").click(function(){
alert("clicked");
return false;
@readevalprint
readevalprint / test_templates.py
Created September 8, 2011 17:16
html comments to stop links
class ArticlePreviewTests(TestCaseBase):
#.....
def test_comments_no_linkify(self):
d = _create_document(title='Template:Foo')
revision(document=d,
is_approved=True,
is_ready_for_localization=True,
save=True,
@readevalprint
readevalprint / diff.py
Created September 23, 2011 04:48
Django instance Diff - Now it's the bestestest.
#!/usr/bin/env python
# By Tim Watts
# From http://readevalprint.com/blog/more-better-django-changed-instance-diff.html
# Updated on 9/22/2011 - Added Many2Many to supported fields
# Updated on 9/23/2011 - Fixed Many2Many fields
class Missing:
pass
import hashlib
import datetime
import urllib
# TODO: Create a thin wrapper to use settings.SECRET_KEY
def create(secret, **kwargs):
"""Create a signed, timestamped single use nonce from the given kwargs"""
m = hashlib.md5()
@readevalprint
readevalprint / django-sudo.py
Created December 14, 2011 19:49
Log in as a user in Django
from django.shortcuts import get_object_or_404
from django.contrib.auth import SESSION_KEY
from django import http
from django.contrib.auth.models import User
from django.contrib.auth.decorators import user_passes_test
@user_passes_test(lambda u: u.is_staff)
def su(request, username, redirect_url='/'):
su_user = get_object_or_404(User, username=username)
if su_user.is_active:
def _remap_date_counts(**kwargs):
"""Remap the query result.
From: [{'count': 2085, 'month': 11, 'year': 2010},...]
To: {'<label>': 2085, 'date': '2010-11-01'}
"""
for label, qs in kwargs.iteritems():
yield dict((date(x['year'], x['month'], 1), {label: x['count']})
for x in qs)
@readevalprint
readevalprint / login_to_mozillians.py
Created May 1, 2012 22:01
Simple Webdriver & BrowserID login example for Mozillians
#!/usr/bin/env python
# To run this make sure you have selenium and bidpom
# pip install -U selenium
# git clone git://github.com/davehunt/bidpom.git
from selenium import webdriver
from bidpom.browser_id import BrowserID
browser = webdriver.Firefox()
browser.get('http://mozillians.allizom.org')