Skip to content

Instantly share code, notes, and snippets.

View jphalip's full-sized avatar

Julien Phalip jphalip

View GitHub Profile
@jphalip
jphalip / gist:c13c1c5fba7f9a6a16ce
Last active April 5, 2019 11:34
Locust debugging
from locust import HttpLocust, TaskSet, task
from locust import events
class UserBehavior(TaskSet):
@task
def google(self):
self.client.get("/")
@jphalip
jphalip / gist:a83cc1d2a3455a915ba5
Last active August 29, 2015 14:02
Example using the WebTest client for Django tests
from django.test import TestCase
from django_webtest import WebTest
"""
WebTest rocks. You should check it out:
http://webtest.readthedocs.org/en/latest/
https://pypi.python.org/pypi/django-webtest
"""

Keybase proof

I hereby claim:

  • I am jphalip on github.
  • I am julienphalip (https://keybase.io/julienphalip) on keybase.
  • I have a public key whose fingerprint is 2D00 16F9 CC71 853B 0A39 70A5 41F0 C351 4608 56BC

To claim this, I am signing this object:

@jphalip
jphalip / gist:9101900
Created February 19, 2014 21:23
Suggested patch for restless
diff --git a/restless/dj.py b/restless/dj.py
index 9af449d..d963699 100644
--- a/restless/dj.py
+++ b/restless/dj.py
@@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
-from .exceptions import NotFound
+from .exceptions import NotFound, Unauthorized
@jphalip
jphalip / poweroff.py
Last active October 18, 2021 21:54
A Python script I wrote to quickly shut down Vagrant/VirtualBox VMs. See also the associated blog post: https://www.julienphalip.com/blog/fast-shutdown-of-development-vagrantvirtualbox/
#!/usr/bin/env python
import argparse
import re
import os
import subprocess
try:
import json
except ImportError:
import simplejson as json
@jphalip
jphalip / goto.sh
Created July 10, 2013 16:10
Bash & zshell script for quickly accessing Python packages installed in the current virtualenv. Allows for tab completion. Associated blog post: http://julienphalip.com/post/55092823910/a-script-to-quickly-access-the-source-of-installed
# Author: Julien Phalip
# License: BSD
# Description: Change the current directory to the path of the given Python package.
function goto {
cd `python -c "import pkgutil; print(pkgutil.get_loader('$1').filename)"`
}
function _top_level_packages {
python -c "import pkgutil; print('\n'.join([name for loader, name, ispkg in sorted(pkgutil.iter_modules()) if ispkg]))"
@jphalip
jphalip / gist:4614527
Last active December 11, 2015 14:29
Bash script for a Chef recipe to install PIL with Zlib and Freetype support in a Vagrant Ubuntu 32bit box. I wish PIL offered a cleaner way of doing this other than having to modify its setup.py.
%w{libjpeg-dev libfreetype6-dev}.each do |pkg|
package pkg do
action :install
end
end
bash "Install PIL from source" do
user vagrant
group vagrant
code <<-EOH
@jphalip
jphalip / gist:2865381
Created June 3, 2012 23:16
Patch for Django ticket #18379
diff --git a/django/views/debug.py b/django/views/debug.py
index 7bdf0d2..d95cd62 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -155,9 +155,20 @@ class SafeExceptionReporterFilter(ExceptionReporterFilter):
Replaces the values of variables marked as sensitive with
stars (*********).
"""
- func_name = tb_frame.f_code.co_name
- func = tb_frame.f_globals.get(func_name)
@jphalip
jphalip / gist:2849931
Created June 1, 2012 07:31
Some issues I'm having installing a bundle on
------------------------------------------------------------------------
zip-test.py:
import zipfile
zf = zipfile.ZipFile('django-compressor-1.1.2.pybundle', 'r')
zf.debug=3
------------------------------------------------------------------------
$ python zip-test.py
@jphalip
jphalip / gist:1341392
Created November 5, 2011 10:58
More Selenium tests for the Django admin
class AdminInlinesSeleniumTests(SeleniumTestCase):
fixtures = ['admin-views-users.xml']
urls = "regressiontests.admin_inlines.urls"
def admin_login(self, username, password):
"""
Helper function to log into the admin.
"""
self.selenium.open('/admin/')
self.selenium.type('username', username)