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 / 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 / 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 / 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 / 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
<?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 / 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}!";
@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 / 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 / relative_time.php
Created February 11, 2011 12:37
Calculate the amount of time between two dates/timestamps in PHP. Return the result as a nicely formatted string or an array of data.
<?php
/**
* Get the relative time between two timestamps.
*
* @access public
* @param integer|string $time The date or timestamp that represents the time we're comparing to.
* @param integer|string $comparison_time [optional] The date or timestamp we want comparisons to be relative to. Defaults to the current timestamp.
* @param boolean $return_array [optional] Whether to return the relative time as an array of components rather than a string. Default value is FALSE.
* @return string Returns the amount of time between the two timestamps as a string or an array if $return_array is TRUE.
@rowanmanning
rowanmanning / my-sugars.sh
Created December 3, 2010 10:36
My Favourite Espresso Sugars
current_dir=`pwd`;
cd ~/Library/Application\ Support/Espresso/Sugars/;
echo "Installing Sugars:";
if [ ! -d ./CSS3.sugar ]; then
echo "Installing CSS3.sugar...";
git clone -q git://github.com/minimalweb/CSS3.sugar.git ./CSS3.sugar;
else
echo "CSS3.sugar already installed, attempting update...";