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 / README.md
Created August 21, 2023 22:15
Unshittify Reddit Images

Unshittify Reddit Images

This reverts the shitty wrapper that Reddit forces on you when you try to view images on their website. This is done via a bookmarklet (see URL below).

Create a new bookmark, copy/paste this code into it and then whenever you visit an i.redd.it image link and get redirected, this will fix the page so that it's just the image. Saving you from the varous bugs/issues induced by their platform (such as the header or footer overlapping the image itself when you attempt to zoom in on the image).

javascript:(function()%7B(()%3D%3E%7Bconst%20t%3Dnew%20URL(location.href).searchParams.get(%22url%22)%3Bif(!t)return%3Bconst%20e%3Dnew%20Image%3Bfunction%20i(t)%7Bvoid%200%3D%3D%3Dt%26%26(t%3D%22initial%22!%3D%3De.style.maxWidth)%2Ce.style.maxWidth%3Dt%3F%22initial%22%3A%22100%25%22%7De.setAttribute(%22src%22%2Ct)%2Ce.addEventListener(%22click%22%2C(()%3D%3Ei()))%2Ci(!0)%2Cdocument.body.innerHTML%3D%22%22%2Cdocument.body.appendChild(e)%7D)()%3
@patricknelson
patricknelson / README.md
Last active November 12, 2022 22:34
Full Screen Bookmark / Bookmarklet

Full Screen Bookmark / Bookmarklet

Can't go to full screen easily? On a website and hate their customized version of a video player and just wish you could use the one built into your device or browser? It turns out there's a solution: In many cases, you can actually bypass this by simply taking the <video> element on the page and forcing it to go to full screen immediately with a single press using a simple bookmark (or, a bookmarklet to be precise).

Instructions

Create a bookmark, call it Full screen and copy/paste the following into the URL field:

javascript:(function()%7Bvar fsvs %3D document.getElementsByTagName('video')%3Bfor(i%3D0%3B i < fsvs.length%3B i%2B%2B) %7Bvar vid %3D fsvs%5Bi%5D%3Bwindow.fsv %3D window.fsv %7C%7C vid%3Bvar playing %3D !!(vid.currentTime > 0 %26%26 !vid.paused %26%26 !vid.ended %26%26 vid.readyState > 2)%3Bif (playing) %7Bwindow.fsv %3D vid%3Bbreak%3B%7D%7Dif (window.fsv) window.fsv.webkitEnterFullscreen()%7D)()
@patricknelson
patricknelson / memcache-get-keys.php
Last active October 1, 2021 18:24
List all keys in older Memcache PHP extension
<?php
/**
* Goes through all configured memcached slabs on the provided pre-configured Memcache object
*
* IMPORTANT: This is for the older and more limited https://pecl.php.net/package/memcache (no "d" suffix) and
* NOT for https://pecl.php.net/package/memcached (has the "d" suffix)!
*
* Inspired by (and modified from): https://coderwall.com/p/imot3w/php-memcache-list-keys
*
@patricknelson
patricknelson / .bash_profile
Last active December 14, 2020 10:05
My personal .bash_profile script 🎉
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# Launches ssh-pageant.exe (instead of ssh-agent) to connect to PuTTY's pageant.exe, an SSH key management process for Windows.
if [ -x /usr/bin/ssh-pageant ]; then
eval $(/usr/bin/ssh-pageant -r -a "/tmp/.ssh-pageant-$USERNAME")
@patricknelson
patricknelson / README.md
Last active March 12, 2020 07:14
PHP function to split arrays up into chunks to do work on (basically pagination for callbacks).

doChunks()

Very simple but useful PHP function for performing work on large arrays of information. Basically, it's like pagination for callbacks. For example, this can be used for performing bulk database INSERT operations (instead of inserting each item individually). See below for a quick real world example.

Example Usage

@patricknelson
patricknelson / - Using Xdebug in Docker.md
Last active October 15, 2023 19:59
Using Xdebug in Docker (works with PhpStorm)

Using Xdebug in Docker

Getting setup and running with Xdebug in a docker container these days is now fairly simple and is composed of two main steps:

  1. Ensure you've got XDebug installed and enabled in your PHP docker image, for example:
    # Installing Xdebug with PHP 7.3 images:
    RUN pecl install xdebug \
      && docker-php-ext-enable xdebug
@patricknelson
patricknelson / silverstripe-versioned-helpers.php
Last active December 29, 2018 02:05
Helper functions to cleanly alter versioned objects in SilverStripe
<?php
/**
* Helper functions to cleanly alter versioned objects in SilverStripe.
*
* Usage:
*
* whileDraft(function() {
* $page = Page::get()->byId(123);
* // ... with great power comes great responsibility...
* });
@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
@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"
<?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();