Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:

Wes Mason 1stvamp

:shipit:
View GitHub Profile
@1stvamp
1stvamp / gist:102767
Created Apr 27, 2009
getNextFirstFriday() - Handy function for 2600 meeting websites
View gist:102767
<?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 Jun 22, 2009
Get a table level lock using PEAR::DB_DataObject
View gist:133886
<?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 Oct 9, 2009
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
$('#dialog').dialog('close');
});
@1stvamp
1stvamp / django-jsonify-decorator.py
Created Feb 11, 2010
Pylons-esque jsonify decorator for django views
View django-jsonify-decorator.py
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 Mar 12, 2010
Lock both the current host and a remote (or multiple) host at the same time, useful for working with multiple machines using synergy
View lock_all_screens.sh
#!/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
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 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"/>
View readable_json.py
#!/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
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
1stvamp / django_session_from_get.py
Created Jul 19, 2011
Re-init Django session from GET value
View django_session_from_get.py
"""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 Oct 13, 2011 — forked from bassdread/Version Display
Display git branch and version in your prompt
View git_branch_and_version_in_prompt.sh
# 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\]\$ '