Skip to content

Instantly share code, notes, and snippets.

View Olical's full-sized avatar
🧙‍♂️
(magic)

Oliver Caldwell Olical

🧙‍♂️
(magic)
View GitHub Profile
@Olical
Olical / spark.min.js
Created May 3, 2011 11:00
Yet another pre release for Spark v3.0.0
/*
Spark JavaScript Library v3.0.0
http://sparkjs.co.uk/
Copyright 2011, Oliver Caldwell
Dual licensed under the MIT or GPL Version 2 licenses.
http://sparkjs.co.uk/licence.html
*/
var Spark=function(){function a(){}a.prototype.extend=function(b,c){a.prototype[b]=c;if(typeof c==="object")c.instance=this};a.prototype.clone=function(){return new a};return new a}();if(typeof window.$==="undefined")var $=function(a,b){return Spark.find(a,b)};
Spark.extend("ready",function(a){function b(){c.find(document).data("domReady",!0);a()}var c=this.clone();c.find(document).data("domReady")?a():window.addEventListener?document.addEventListener("DOMContentLoaded",b,!1):function(){var a=document.createElement("document:ready");try{a.doScroll("left"),b()}catch(c){setTimeout(arguments.callee,0)}}()});
@Olical
Olical / render.php
Created May 19, 2011 20:09
Minecraft skin renderer
<?php
function flip(&$img)
{
$size_x = imagesx($img);
$size_y = imagesy($img);
$temp = imagecreatetruecolor($size_x, $size_y);
$x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y);
return $temp;
}
@Olical
Olical / compiled.js
Created June 1, 2011 20:53
Playing with Google closure
var h=void 0,i=null,n,o=this;function p(){}
function aa(a){var b=typeof a;if(b=="object")if(a){if(a instanceof Array)return"array";else if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if(c=="[object Window]")return"object";if(c=="[object Array]"||typeof a.length=="number"&&typeof a.splice!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("splice"))return"array";if(c=="[object Function]"||typeof a.call!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if(b=="function"&&typeof a.call=="undefined")return"object";return b}function q(a){return aa(a)=="array"}function ba(a){var b=aa(a);return b=="array"||b=="object"&&typeof a.length=="number"}function r(a){return typeof a=="string"}function s(a){return aa(a)=="function"}function ca(a){a=aa(a);return a=="object"||a=="array"||a=="function"}function t(a){return a[da]||(a[da]=++ea)}var da="closure_uid_"+Math.floor(Math.random()*214748
@Olical
Olical / create.js
Created June 3, 2011 16:10
Adds the create functionallity to Objects in JavaScript. From Douglas Crockford
if(typeof Object.create!=="function")Object.create=function(b){function a(){}a.prototype=b;return new a};
@Olical
Olical / supress-dollar.js
Created June 6, 2011 09:35
Stops Mootools throwing errors when it can not find an element via id
(function(){var a=document.id;document.id=function(b,c,d){return a(b,c,d)||new Element("p")}})();
@Olical
Olical / git-auto-complete.sh
Created June 17, 2011 15:34
Git branch / tag/ remote / command terminal completion. Drop it into your bash profile
_complete_git() {
if [ -d .git ]; then
branches=`git branch -a | cut -c 3-`
tags=`git tag`
remotes=`git remote`
commands="add bisect branch checkout clone commit diff fetch grep init log merge mv pull push rebase reset rm show status tag stash pop"
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${branches} ${tags} ${remotes} ${commands}" -- ${cur}) )
fi
}
@Olical
Olical / sed.sh
Created June 30, 2011 15:09
Multiline find and replace with sed
ifconfig eth0 | sed -n "s/.*HWaddr \([0-9A-Za-z:]*\).*/\1/p"
@Olical
Olical / in-string.sh
Created June 30, 2011 16:00
Check if a string contains another string using a regular expression in bash
string='My string';
if [[ $string =~ .*My.* ]]
then
echo "It's there!"
fi
@Olical
Olical / find-and-exec.sh
Created July 14, 2011 14:18
An example of find and exec
find . -type f -name ._* -exec git rm {} \;
@Olical
Olical / linkify.php
Created July 26, 2011 15:21
Converts a plain old tweet to a fancy one with links all over the place.
<?php
/**
* Adds links to tweets
*
* @param string $tweet The raw tweet
* @return string The tweet with links
*/
function linkify($tweet)
{