Skip to content

Instantly share code, notes, and snippets.

View 1stvamp's full-sized avatar
:shipit:

Wes Mason 1stvamp

:shipit:
View GitHub Profile
@1stvamp
1stvamp / gist:102767
Created April 27, 2009 22:05
getNextFirstFriday() - Handy function for 2600 meeting websites
<?php
// 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
1stvamp / gist:133886
Created June 22, 2009 09:24
Get a table level lock using PEAR::DB_DataObject
<?php
// 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
1stvamp / modal_jquery.ui_dialog_close_on_overlay_click.js
Created October 9, 2009 14:30
jQuery.UI modal dialog background-click-closing
/*
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
$('#dialog').dialog('close');
});
@1stvamp
1stvamp / django-jsonify-decorator.py
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
1stvamp / lock_all_screens.sh
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
#!/bin/bash
# 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
<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 http://wordpress.org/latest.tar.gz | 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
try:
import json
except ImportError:
import simplejson as json
pprint(json.load(file(argv[1])))
@1stvamp
1stvamp / gist:961769
Created May 8, 2011 22:39
Swap unity for gnome3 shell
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
1stvamp / django_session_from_get.py
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
1stvamp / git_branch_and_version_in_prompt.sh
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.
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
GRAY="\[\033[1;30m\]"
LIGHT_BLUE="\[\033[1;34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_OFF="\[\e[0m\]"
LAST_GIT_DIR="!"
function prompt_func() {
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '