Skip to content

Instantly share code, notes, and snippets.

View pplante's full-sized avatar
🐶

phil plante pplante

🐶
View GitHub Profile
# Automatically activate Git projects' virtual environments based on the
# directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd {
# Check that this is a Git repo
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`
if [ $? == 0 ]; then
# Find the repo root and check for virtualenv name override
GIT_DIR=`\cd $GIT_DIR; pwd`
PROJECT_ROOT=`dirname "$GIT_DIR"`
<a class="btn">My Button</a>
from tastypie import fields
from tastypie.bundle import Bundle
class FastDehydratableForeignKey(fields.ForeignKey):
def dehydrate(self, bundle):
if isinstance(bundle, Bundle):
other_resource = self.to_class()
if hasattr(other_resource, '_meta') and other_resource._meta.object_class:
fk_field = bundle.obj._meta.get_field(self.attribute)
@pplante
pplante / post-receive.sh
Created October 22, 2012 04:28 — forked from stas/post-receive.sh
Heroku like deployment git hooks
#!/bin/bash
# (Re)spawn the application
function spawn () {
local ps_name=$1
local spawn_cmd=$2
local pids=`ps -C $ps_name -o pid=`
if [ ${#pids} -ne 0 ]
then
echo "Sending TERM to $pids..."
@pplante
pplante / robolectric-library-resource-loading.java
Created August 28, 2012 20:23
Robolectric does not support loading resources from an Android Library project such as ActionBarSherlock of FlyInMenu, so this patch allows you to specify a library project to load resources in tests.
// In ResourceLoader.java I added the following method:
//
public void loadLibraryProjectResources(File libraryProjectRoot) throws Exception {
File systemResourceDir = getSystemResourceDir(getPathToAndroidResources());
File localValueResourceDir = getValueResourceDir(libraryProjectRoot);
File systemValueResourceDir = getValueResourceDir(systemResourceDir);
loadStringResources(localValueResourceDir, systemValueResourceDir);
loadPluralsResources(localValueResourceDir, systemValueResourceDir);
loadValueResources(localValueResourceDir, systemValueResourceDir);
@pplante
pplante / areyoufuckingkiddingme.java
Created June 27, 2012 19:57
fixes a stupid bug with lwjgl on osx when the user presses cmd+q in fullscreen the app hangs causing you to restart OSX.
// see: http://www.java-gaming.org/index.php?topic=23640.0
Application.getApplication().setQuitHandler(new QuitHandler() {
@Override
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
Gdx.app.exit();
}
});
@pplante
pplante / MemoryTrackingAssetManager.java
Created May 12, 2012 22:32
This is a custom wrapper around the AssetManager in LibGDX providing the ability to track how much texture memory is allocated.
/*
Copyright (c) 2012. HappyDroids LLC <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTIO
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenAccessor;
import com.unhappyrobot.entities.GameObject;
public class GameObjectAccessor implements TweenAccessor<GameObject> {
static {
Tween.registerAccessor(GameObject.class, new GameObjectAccessor());
}
public static final int POSITION = 1;
@pplante
pplante / python-expectations-selenium.py
Created October 4, 2011 08:21
I wasn't happy with the existing selenium integrations for django, so I wrote one that is compatible with my python-expectations library. Here is a sample test that logs into admin, then checks for my username in the header.
class ApplicationViewTests(SeleniumTestCase):
def test_django_test_server_is_running(self):
self.login()
with self.navigate_to('/admin') as page:
expect(page).to_have_selector('#user-tools')
expect(page.find('#user-tools')).to_contain_text('Welcome, pplante.')
def login(self, username=None, password=None):
@pplante
pplante / jquery.ajaxq.js
Created July 26, 2011 03:54
jQuery AjaxQ(ueue)
// Copyright (C) 2011 Philip Plante <@pplante>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in