Skip to content

Instantly share code, notes, and snippets.

View ear1grey's full-sized avatar

Rich Boakes ear1grey

View GitHub Profile
@ear1grey
ear1grey / gist:1372741
Created November 17, 2011 08:59
Example UoP
switch ($_GET['filter']) {
case 0:
// do stuff;
break;
case "none":
// do otherStuff;
break;
}
// case 0: triggers even when $_GET['filter'] evaluates to "none"
@ear1grey
ear1grey / gp_imp_mod.php
Created April 24, 2012 10:28
Mod to G+ Importer Plugin
if (isset($item->url)) {
$post_content .= "\n\n<a href='".$item->url."'>Comment on Google+</a>";
}
@ear1grey
ear1grey / weekly_date.js
Created August 3, 2012 16:26
A tiny utility for creating a json array of dates 1 week apart
/*
A tiny utility for creating a json array of dates.
I need this for creating year-long timetables where after an initial start
we have a few weeks off for christmas, then easter, and these weeks differ
each year, so the 'switches' make it easy to include weeks (signified by a 1)
or exclude weeks (a 0)
Note that monts start at 0 not 1 :-)
@ear1grey
ear1grey / shrinky.js
Created August 8, 2012 11:21
Shrink text of a particular class relative to how far scrolled a page is.
(function shrinky() {
var q = document.querySelectorAll(".shrink");
window.addEventListener(
"scroll",
function scroll () {
var i, z = 100-(Math.min(window.pageYOffset,100)/2);
for(i=0; i<q.length; i++) {
q[i].style.fontSize = z+"%";
@ear1grey
ear1grey / 2012_soc_units.json
Created September 27, 2012 19:34
soc.port.ac.uk unit codes in json
{
"U21277-12YR": {
"ucode" : "U22344",
"name" : "Web Research",
"scode" : "WebRes"
},
"U22344-12YR": {
"ucode" : "U22344",
"name" : "Business Systems Analysis & Design",
"scode" : "BUSAD"
@ear1grey
ear1grey / teapot.pov
Created January 27, 2013 11:10
The Utah Teapot, with height adjusted to look like the real physical teapot.
// This scene of the utah teapot requires no additional files. It creates a
// picture of an elongated teapot (so that the original physical teapots
// dimensions are honoured, and places this crockery in a plain white
// environment.
//
// Utah Teapot using Bezier patches was adapted by Alexander Enzmann from
// the original model by Martin Newell.
// Scene created by Rich Boakes - http://boakes.org/teapot
#declare Flat_Enough = 0.00001;
@ear1grey
ear1grey / gist:5343332
Last active December 15, 2015 23:49 — forked from anonymous/gist:5340810
This is a slight restructuring which removes one of the HTTP calls (the null one) and moves the callback code within the addItem function, forming a closure.
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
request_type = new XMLHttpRequest();
}
return request_type;
@ear1grey
ear1grey / Dumb CSS Speed Test
Created October 15, 2013 14:45
I thought it would be interesting to see how fast (or not) some CSS selectors really are. Perhaps a framework for capturing this data and visualising it in some way (by browser / version maybe) would be useful. I tried two different ways of setting the stylesheet, one in a loop, and the other using a timeout to ensure that the UI gets a chance t…
<!doctype html>
<title>Dumb CSS Speed Test</title>
<style id="x">
</style>
<nav>
<ul>
<li>1
<ul>
<li class="q">1</li>
<li class="q">2</li>
@ear1grey
ear1grey / Scope Example 1
Created October 24, 2013 12:29
A scope example for sharing...
//varscope
var x1 = 3;
for (var y1=x1;y1>0; y1--) {
var x1 = y1;
console.log(x1);
console.log(y1);
}
console.log(x1);
console.log(y1);
@ear1grey
ear1grey / scrape_students.js
Created February 22, 2014 22:44
Scrape the list of students on a unit from the staff portal at Uni of Portsmouth, as JSON.
(function() {
var i, y, result = [], x = document.querySelectorAll("input[type=checkbox]");
for (i in x) {
y = x[i].defaultValue;
if (y) {
var r = {}
r.orig = y;
r.email = y.split(",")[0].trim();
r.name = y.split(",")[1].trim();
r.jupiter = r.email.substr(2).replace('@myport.ac.uk', '');