Skip to content

Instantly share code, notes, and snippets.

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

Patrick Nelson patricknelson

Pushing 1's and 0's.
View GitHub Profile
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!
patricknelson / framework.php
Last active August 29, 2015 14:21
Access SilverStripe framework outside of typical page controller. Rapid prototyping.
* 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,
* @since 2015-01-06
patricknelson / example.php
Created July 22, 2015 20:43 — forked from scottsb/example.php
Hack to handle multiple Exception types with a single block
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 /
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 "$@"
command cd "$@"
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;
// This has moved to:
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.
* 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) {
class Injector extends Nestception {
// ... rest of class...
public static function unnestTemp($callable) {
// Retain current instance so we can revert back to it momentarily.
$revertTo = self::inst();
patricknelson / Quaternion.shader
Last active May 11, 2023 15:49 — forked from nkint/pointTowards.vertex
Shader functions to facilitate rotation of vertex around point with a quaternion (Unity / HLSL / Cg)
// Full shader example demonstrating how to use a quaterionion to rotate a vertex around a specific point. Note that this is just a plain
// vanilla unlit shader which includes the necessary functions (see section below) and example code in the vertex shader.
// Forked from
// Converted from GLSL to Cg. For help with that, see
// quaternion code from
// rotation from
Shader "Unlit/Quaternion"
patricknelson / OverrideControllerMaterial.cs
Last active May 15, 2021 22:08
Override the material and texture of default SteamVR HTC Vive controllers in Unity.
using UnityEngine;
using Valve.VR;
/// <summary>
/// Override the material and texture of the HTC Vive controllers, with your own material after SteamVR has loaded and
/// applied the original material. This is useful to help preserve interactions in the model itself.
/// NOTE: This is only compatible with the default HTC vive controllers (see UpdateControllerMaterial() below).
/// Modified by Patrick Nelson / chunk_split ( from original "OverrideControllerTexture" class