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 / 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);
@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 / 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 / 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 / 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: https://github.com/patricknelson/dubtrack-tweaks
@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) {
<?php
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
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 https://gist.github.com/nkint/7449c893fb7d6b5fa83118b8474d7dcb
// Converted from GLSL to Cg. For help with that, see https://alastaira.wordpress.com/2015/08/07/unity-shadertoys-a-k-a-converting-glsl-shaders-to-cghlsl/
//
// quaternion code from https://github.com/stackgl/gl-quat
// rotation from https://twistedpairdevelopment.wordpress.com/2013/02/11/rotating-a-vector-by-a-quaternion-in-glsl/
Shader "Unlit/Quaternion"
@patricknelson
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 (pat@catchyour.com) from original "OverrideControllerTexture" class