Skip to content

Instantly share code, notes, and snippets.

View 1stvamp's full-sized avatar

Wes Mason 1stvamp

View GitHub Profile
1stvamp / gist:102767
Created April 27, 2009 22:05
getNextFirstFriday() - Handy function for 2600 meeting websites
View gist:102767
// Handy function for 2600 meeting websites
* Return a unix timestamp for next "first Friday of the month", e.g.
* either the first Friday of the current month or if that date has already passed
* the first friday of the next month
* @return int unix timestamp
function getNextFirstFriday() {
1stvamp / gist:133886
Created June 22, 2009 09:24
Get a table level lock using PEAR::DB_DataObject
View gist:133886
// How to lock a table using PEAR's DB_DataObject in a semi-OO way,
// note this still relies on the DB-dependant LOCK/UNLOCK syntax,
// change for the relevent RDBMS
// Lock
// You can also specify other options such as READ and the priority below
// see RDBMS docs, in this case MySQL
$object->getDatabaseConnection()->query('LOCK TABLES ' . $object->tableName() . ' WRITE');
// Unlock
1stvamp / modal_jquery.ui_dialog_close_on_overlay_click.js
Created October 9, 2009 14:30
jQuery.UI modal dialog background-click-closing
View modal_jquery.ui_dialog_close_on_overlay_click.js
Close a jQuery.UI modal dialog when the background overlay is clicked on,
ala most standard modal javascript overlays.
$('.ui-widget-overlay').click(function() {
// Where #dialog below should be a selector for the dialog you want to close
1stvamp /
Created February 11, 2010 15:18
Pylons-esque jsonify decorator for django views
from django.core import serializers
from django.http import HttpResponse
from django.utils import simplejson
from django.db.models import Model
def jsonify(fn, *args, **kwargs):
""" Decorator that serializes the output of a function, most likely
a view, as JSON, and returns the JSON in a HttpResponse.
Inspired by Pylon's jsonify controller decorator.
1stvamp /
Created March 12, 2010 13:39
Lock both the current host and a remote (or multiple) host at the same time, useful for working with multiple machines using synergy
# Replace <local_user> with your local username, <remote_user> with your username on <remote_host> etc.
# You'll need an SSH, <private_key>, setup with the remote host to not prompt for a password
# (either passphraseless or with ssh-agent running)
ssh -i /home/<local_user>/.ssh/<private_key> <remote_user>@<remote_host> "export DISPLAY=:0 && gnome-screensaver-command --lock"
gnome-screensaver-command --lock
View phing-upgrade-wordpress
<target name="wordpress.upgrade">
<property name="tmp" value="/tmp" />
<property name="src" value="${tmp}/wordpress" />
<delete dir="${src}" includeemptydirs="true" failonerror="true" />
<exec dir="${tmp}" command="curl -s | tar -xz" />
<delete dir="wp-admin" includeemptydirs="true" failonerror="true" />
<delete dir="wp-includes" includeemptydirs="true" failonerror="true" />
<move file="wp-config.php" tofile="wp-config.php.bak" overwrite="true"/>
#!/usr/bin/env python
from sys import argv
from pprint import pprint
import json
except ImportError:
import simplejson as json
1stvamp / gist:961769
Created May 8, 2011 22:39
Swap unity for gnome3 shell
View gist:961769
sudo add-apt-repository ppa:gnome3-team/gnome3
# Remember to change your apt priorities so that the gnome3 PPA takes
# precedence over Canonical
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install gnome-shell gnome3-session
sudo apt-get remove unity
sudo vim /usr/share/xsessions/gnome.desktop
# change --session=ubuntu for --session=gnome
sudo shutdown -r now
1stvamp /
Created July 19, 2011 14:57
Re-init Django session from GET value
"""Sometimes you just want to load your session based on a GET value,
without having an entire middleware installed to do it everytime, e.g.
just do it quickly in a view.
def test_view(request):
# Assuming session key sent as 'sessionid' value in querystring
request.session = request.session.__class__(session_key=request.GET['sessionid'])
1stvamp /
Created October 13, 2011 15:26 — forked from bassdread/Version Display
Display git branch and version in your prompt
# Show current git branch or SVN subfolder in prompt.
function prompt_func() {
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '