Skip to content

Instantly share code, notes, and snippets.

View patricknelson's full-sized avatar
:shipit:
Pushing 1's and 0's.

Patrick Nelson patricknelson

:shipit:
Pushing 1's and 0's.
View GitHub Profile
@patricknelson
patricknelson / silverstripe-exceptions.php
Last active April 14, 2016 00:28
Example of how you can ensure you have programmatic encapsulation and capture of all SilverStripe generated errors.
<?php
/**
* SilverStripe doesn't typically use exceptions, but we may still need a programmatic method of encapsulating code
* and catching errors. Here we can wrap code in a callback which will trigger an exception instead of user_error()'s.
*
* @param callable $closure
* @throws Exception
*/
function withExceptions(callable $closure) {
// This has moved to: https://github.com/patricknelson/dubtrack-tweaks
@patricknelson
patricknelson / randomColor.js
Created October 16, 2015 21:58
Generate random hex color, for fun.
function randColor() {
var color = "#";
for(var i = 1; i <= 3; i++ ) {
var num = Math.round(Math.random() * 255);
color += num.toString(16);
}
return color;
}
@patricknelson
patricknelson / cd-git.sh
Created September 29, 2015 14:45
When you're too stupid to realize you need to "git checkout [branch]" and not "cd" into it.
cd() {
if [ -d .git ] && [ ! -d $@ ]; then
git checkout "$@"
else
command cd "$@"
fi
}
@patricknelson
patricknelson / example.php
Created July 22, 2015 20:43 — forked from scottsb/example.php
Hack to handle multiple Exception types with a single block
<?php
class Foo extends Exception {}
class Bar extends Foo {} // Bar is a technically different but Foo-like exception.
class Baz extends Exception {}
try {
throw new Foo();
} catch (Foo $e) {
echo 'Case 1';
} catch (Baz $e) {
@patricknelson
patricknelson / framework.php
Last active August 29, 2015 14:21
Access SilverStripe framework outside of typical page controller. Rapid prototyping.
<?php
/**
* Include this file if you wish to tie into the SilverStripe framework to test your code in a separate workbench area
* without having to build a page controller, data object and then go through the full request cycle. This is good for
* rapid prototyping before rolling out any sort of final code. NOTE: This *is* suitable for use in the command line as
* well.
*
* @author Patrick Nelson, pat@catchyour.com
* @since 2015-01-06
@patricknelson
patricknelson / Allow Scale (Mobile browser bookmarklet)
Last active August 29, 2015 14:20
Allows you to take back control from the sweaty greedy clasp of those restricting website overlords... and git yer zoom on!
javascript:document.querySelector(%22meta%5Bname=viewport%5D%22).setAttribute(%22content%22,%20%22%22);