Skip to content

Instantly share code, notes, and snippets.

@garvin
garvin / focused_thing_outliner.user.js
Created March 25, 2025 16:30
Focused-thing outliner
// ==UserScript==
// @name Focused-thing outliner
// @namespace http://garvinggarvin.com/monkies
// @description Outline/highlight the focused thingy.
// @match *://*.mbsbooks.com/*
// @match *://*.cgarvin.com/*
// @match *://bookstore.mbsdirect.net/*
// @match *://bncvirtual.com/*
// @exclude *://*.mbsbooks.com/misi-test/dashboard/modules/webauth/*
// @exclude *://*.mbsbooks.com/misi/dashboard/modules/webauth/*
@garvin
garvin / tumbblkbg.js
Created December 29, 2021 17:19
Black bg chat text for baby
// ==UserScript==
// @name Black bg chat text for baby
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Black bg chat text
// @author Gravin
// @match https://www.tumblr.com/*
// @icon https://www.google.com/s2/favicons?domain=tumblr.com
// @grant none
// ==/UserScript==
@garvin
garvin / modernizr.positionfixed.js
Last active March 20, 2018 21:47 — forked from bobslaede/modernizr.positionfixed.js
Modernizr position fixed check
;(function(Modernizr, window) {
Modernizr.addTest('positionfixed', function () {
var test = document.createElement('div'),
control = test.cloneNode(false),
fake = false,
root = document.body || (function () {
fake = true;
return document.documentElement.appendChild(document.createElement('body'));
}());
@garvin
garvin / millitime.php
Last active February 8, 2018 17:46
Function to generate a timestamp (in # of milliseconds)
/**
* Generate a timestamp (in # of milliseconds)
*
* @return string
*/
function millitime() {
$microtime = microtime();
$comps = explode(' ', $microtime);
// Note: Using a string here to prevent loss of precision
@garvin
garvin / github_test.user.js
Created November 22, 2017 16:26
Github-hosted user script test
// ==UserScript==
// @name Github-hosted user script test
// @namespace http://garvinggarvin.com/monkies
// @include http://*
// @include https://*
// @version 1
// ==/UserScript==
console.log('i am working yes');
@garvin
garvin / output_array_as_table.php
Last active March 6, 2017 22:04
Quick & dirty output-an[-associative?]-array as a <table> function
/**
* Given an array, return its contents as a <table>
*
* @param mixed $r
* @return string If $r is an array, returns HTML of a <table> representing its contents.
* If $r is a string, returns that string with HTML entities converted.
* If $r is not a string or array, returns var_export($r, true) with HTML entities converted.
*/
function output_array_as_table($r) {
// function for doing some entitifying of strings
@garvin
garvin / is_associative_array.php
Last active May 14, 2018 20:38
Quick & dirty is-array-associative test
/**
* Test whether/not $array is associative
*
* Got annoyed when I saw a coworker using the accepted answer at http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential?page=1&tab=active#tab-top
* It seems overly complicated, and fails if the linear array's keys aren't contiguous (as do several other solutions I found).
*
* Sample test arrays:
* ----------------------------------------
*
* $empty_array = array ( );
@garvin
garvin / uniqueId.js
Created March 31, 2016 21:44
Quick & dirty unique ID generator
/**
* Creates a string that can be used for dynamic id attributes
* Example: "id-so7567s1pcpojemi"
* @returns {string}
*/
var uniqueId = function() {
return 'id-' + Math.random().toString(36).substr(2, 16);
};
@garvin
garvin / string_funcs.php
Last active September 10, 2015 17:21
Useful string functions
/**
* Useful string functions
*/
/**
* Replace any whitespace character or sequence of whitespace characters into a single space
*
* @param string $str
* @return string $str with any sequence of whitespace collapsed into a single space
*/
@garvin
garvin / simplexml_to_array.php
Last active September 10, 2015 17:11
Two functions to convert an XML document to an array using SimpleXML.
<?php
/**
* Convert a SimpleXMLElement to an associative array.
*
* Note: ignores attributes.
*
* @param SimpleXMLElement $sxe A SimpleXMLElement.
* @param array $repeating_elements A array of names of elements that repeat. Optional.
* @return mixed Returns null when the element is empty/doesn't exist.