Skip to content

Instantly share code, notes, and snippets.

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

Wes Mason 1stvamp

:shipit:
View GitHub Profile
plugins_repos:
- https://github.com/juju/plugins.git
- https://github.com/bloodearnest/plugins.git#juju-local-dns
- https://github.com/bloodearnest/plugins.git#juju-add-local-env
@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'])