Skip to content

Instantly share code, notes, and snippets.

View Pub Standards date widget
<?php
function getMiddleDay($day, $month, $year) {
$thisMonth = mktime(0, 0, 0, $month, 0, $year);
$daysInMonth = date('t', $thisMonth);
$middleTimestamp = mktime(0, 0, 0, $month, floor($daysInMonth/2), $year);
$potentials = array();
foreach (array(2,3) as $i) {
View iCal feed of Pub Standards events for the next 12 months. Ugly as hell, but then iCal is.
<?php
date_default_timezone_set('Europe/London');
function getMiddleDay($day, $month, $year) {
$thisMonth = mktime(0, 0, 0, $month, 0, $year);
$daysInMonth = date('t', $thisMonth);
$middleTimestamp = mktime(0, 0, 0, $month, floor($daysInMonth/2), $year);
View gchart-pie.py
#!/usr/bin/python
import sys
labels = []
values = []
for line in sys.stdin:
bits = line.strip().split(' ')
value = bits.pop(0)
label = ' '.join(bits)
View this_is_a_bit_more_readable.rb
def just_one_kind_of_response?(item, controller)
case controller
when 'actions'
if item.comments.blank? || item.suggestions.blank?
return true
end
when 'thoughts'
if item.comments.blank? || item.suggestions.blank?
@Jonty
Jonty / readtag.c
Created Oct 18, 2010
Read a single tag UID using libnfc.
View readtag.c
#include <nfc/nfc.h>
#include <nfc/nfc-messages.h>
int main ()
{
nfc_device_t *nfcDev;
nfcDev = nfc_connect(NULL);
if (nfcDev == NULL) {
printf("Cannot connect to the RFID reader.\n");
@Jonty
Jonty / install_xkcd_urlhandler.sh
Created Nov 19, 2010
An xkcd://318 URL handler (For Linux)
View install_xkcd_urlhandler.sh
#!/bin/sh
# An xkcd://318 URL handler, for linux types.
echo -n "#!/bin/sh\nexec xdg-open \`echo \"\$@\" | sed -e 's/xkcd:\//http:\/\/xkcd.com/'\`" > $HOME/.xkcdhandler
chmod +x $HOME/.xkcdhandler
gconftool-2 -t string -s /desktop/gnome/url-handlers/xkcd/command "$HOME/.xkcdhandler %s"
gconftool-2 -t bool -s /desktop/gnome/url-handlers/xkcd/needs_terminal false
gconftool-2 -t bool -s /desktop/gnome/url-handlers/xkcd/enabled true
@Jonty
Jonty / .mutt-mailcap
Created Feb 11, 2011
Temporarily uploads email attachments from mutt to a web-accessible remote directory for viewing.
View .mutt-mailcap
image/*; ~/.showinbrowser.sh %s
application/*; ~/.showinbrowser.sh %s
audio/*; ~/.showinbrowser.sh %s
text/*; ~/.showinbrowser.sh %s
@Jonty
Jonty / add_github_irc_hooks.py
Created Nov 14, 2012
Add an IRC announce hook to every repo in a Github organisation
View add_github_irc_hooks.py
from github import Github # https://github.com/jacquev6/PyGithub
g = Github("USER", "PASSWORD")
repos = g.get_organization('ORGNAME').get_repos()
for repo in repos:
repo.create_hook(
"irc",
{
View kittinz.sh
brew install mplayer && mplayer "http://livestream-f.akamaihd.net/398160_1594566_3e41227e_1_678@41915?v=2.10.3&fp=MAC%2011,5,31,2&r=HPMHI&g=MYFXUTYHSWLA"
@Jonty
Jonty / gist:5237871
Created Mar 25, 2013
Beanstalkd command runner example
View gist:5237871
import os
import beanstalkc
beanstalk = beanstalkc.Connection(host='localhost', port=14711)
while True:
job = beanstalk.reserve()
print "Running %s" % job.body
os.system(job.body)
job.delete()