Skip to content

Instantly share code, notes, and snippets.

View rowanmanning's full-sized avatar
📢
honk

Rowan Manning rowanmanning

📢
honk
View GitHub Profile
@rowanmanning
rowanmanning / foreach-references.php
Created March 29, 2011 09:08
A much cleaner way of writing PHP foreach loops
<?php
// I've been doing this
foreach ($array as $key => $value) {
$array[$key] = $modified_value;
}
// rather than this
foreach ($array as &$value) {
$value = $modified_value;
@rowanmanning
rowanmanning / class-concept.php
Created June 1, 2011 14:34
Concept for a PHP String class
<?php
//============================================================
// CONSTANTS
// direction (for strpos etc)
String::FORWARD;
String::REVERSE;
// case
String::CASE_LOWER;
@rowanmanning
rowanmanning / shorthand-ternary.php
Created June 21, 2011 13:51
PHP 5.3's shortened ternary operator
<?php
function hello($arg = 'World') {
// sanitize arguments
$arg = $arg ?: 'World';
// return message
return "Hello {$arg}!";
<?php
// looking for the spoiler image mentioned in https://twitter.com/notch/status/84361767962161152
$letters = array_merge(range('a', 'z'), range('A', 'Z'));
foreach ($letters as $letter) {
$image = 'http://i.imgur.com/IKc7' . $letter . '.png';
print '<img src="' . $image . '" alt="Is is this one?" style="display: block; margin: 0 0 20px 0"/>';
}
@rowanmanning
rowanmanning / playing.coffee
Created October 26, 2011 21:18
Just learning a bit of CoffeeScript
# represents a person
class Person
# properties
name: null
alive: true
stomach: 0
bladder: 0
@rowanmanning
rowanmanning / package.json.js
Created December 18, 2011 15:11
Familiarising myself with npm's package.json specification
{
//-----------------------------------------------------------
// Important information
// Name and version are required and together are treated as
// a unique identifier for a particular build. Name
// [http://npmjs.org/doc/json.html#name] and version
// [http://npmjs.org/doc/json.html#version] are strings.
"name": "mypackage",
"version": "0.1",
@rowanmanning
rowanmanning / git-pull-push-aliases.sh
Created January 13, 2012 10:38
Git aliases: pull = '-', push = '=', pull+push = '-='. Not using `alias` because I couldn't work out how to make it accept '-' and '='. Tested on Mac OS X 10.7
tmp_prefix="/usr/local/bin/"
echo "git pull;" > $tmp_prefix-;
echo "git push;" > $tmp_prefix=;
echo "git pull && git push;" > $tmp_prefix-=;
chmod 755 $tmp_prefix- $tmp_prefix= $tmp_prefix-=;
@rowanmanning
rowanmanning / README.md
Created January 27, 2012 10:39
Useful Git aliases - run these commands

Pretty log format

Graph with author and commit hash:

git config --global alias.plog 'log --graph --pretty=format:\"%C(yellow)%h%x20%C(green)%an%x20%Creset%s\"'

Standup

@rowanmanning
rowanmanning / example.less
Created June 16, 2012 18:06
LESS Hackery
// Allows specifying default variables in LESS
// Some really sneaky shit that will shoot me in the foot if
// LESS changes too much...
@--lol: ~`"" + ( root._less = root._less || this )`;
@--lol: ~`"" + ( root.getLessVar = function (name) { return root._less[name] ? root._less[name].toJS() : '' } )`;
@--lol: ~`"" + ( root.getLessVarDefault = function (name, def) { return root.getLessVar(name) !== '' ? root.getLessVar(name) : root.getLessVar(def) } )`;
// Example:
@rowanmanning
rowanmanning / instructions.md
Created October 25, 2012 13:31
Git Autocompletion On Mac OS X

Git Autocompletion On Mac OS X

(based on this post which I don't like because they tell you to add a bash file to your home directory)

Run the following commands to begin:

cd /usr/local/bin && curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL