Skip to content

Instantly share code, notes, and snippets.

@zaus
zaus / debug-me.php
Last active February 12, 2016 22:19
Simple WP debug helper "plugin"
<?php
/*
Plugin Name: Dev Debug Me
Plugin URI: https://codex.wordpress.org/Debugging_in_WordPress
Description: Just some developer includes for debugging. Not actually a plugin; activate to test log writing.
Author: zaus
Version: 0.1
Author URI: https://gist.github.com/zaus/35c1deb8ead5baa6fc40
*/
@zaus
zaus / =ChromeDevToolsSnippets.md
Last active August 6, 2016 18:14
Chrome DevTools Snippets (because it doesn't save when you clear your user data...)
@zaus
zaus / gist:71a7a89bc3bec0d8ea2faaa287c20c82
Last active September 22, 2016 16:26 — forked from marksteve/gist:877210
Monokai Notepad2 Color Scheme /mod
[Default Text]
FileNameExtensions=txt; text; wtx; log; asc; doc
Default Style=font:DejaVu Sans Mono; size:10; fore:#F8F8F2; back:#000000
Margins and Line Numbers=size:-2; fore:#BCBCBC; back:#3B3A32
Matching Braces=size:+1; bold; fore:#000000; back:#FD971F
Matching Braces Error=size:+1; bold; fore:#F8F8F0; back:#F92672
Control Characters (Font)=size:-1
Indentation Guide (Color)=fore:#A0A0A0
Selected Text (Colors)=fore:#F8F8F2; back:#49483E; eolfilled
Whitespace (Colors, Size 0-5)=fore:#AA2B00
@zaus
zaus / enviro-switch.php
Created December 11, 2015 21:06
wp-config DEBUG
switch($_SERVER['HTTP_HOST']) {
case 'wp.sandbox:81':
define('DB_NAME', 'YOURDB');/** The name of the database for WordPress */
define('DB_USER', 'YOURUSER');/** MySQL database username */
define('DB_PASSWORD', 'YOURPASS');/** MySQL database password */
define('DB_HOST', 'localhost');/** MySQL hostname */ // may need to use actual computer ip in some cases
break;
default:
define('DB_NAME', 'YOURDB');/** The name of the database for WordPress */
define('DB_USER', 'YOURUSER');/** MySQL database username */
@zaus
zaus / Test-Collection-Contains.linq.cs
Last active June 30, 2017 16:22
Comparing Collection.Contains for various sets of data
void Main()
{
// https://stackoverflow.com/questions/150750/hashset-vs-list-performance/13089134?noredirect=1#comment76605526_13089134
test(10, 5, 10, true);
test(20);
test(50);
test(100);
test(1000);
@zaus
zaus / $.stripClass.js
Created September 27, 2013 20:31
jQuery.removeClass companion -- strips out matching segments
$.fn.stripClass = function (partialMatch, endOrBegin) {
/// <summary>
/// The way removeClass should have been implemented -- accepts a partialMatch (like "btn-") to search on and remove
/// </summary>
/// <param name="partialMatch">the class partial to match against, like "btn-" to match "btn-danger btn-active" but not "btn"</param>
/// <param name="endOrBegin">omit for beginning match; provide a 'truthy' value to only find classes ending with match</param>
/// <returns type=""></returns>
var x = new RegExp((!endOrBegin ? "\\b" : "\\S+") + partialMatch + "\\S*", 'g');
// http://stackoverflow.com/a/2644364/1037948
/// <summary>
/// PGP round-trip encryption -- http://blogs.microsoft.co.il/kim/2009/01/23/pgp-zip-encrypted-files-with-c/#comment-611002
/// </summary>
public class PGPEncryptDecrypt
{
/**
* A simple routine that opens a key ring file and loads the first available key suitable for
* encryption.
*
* @param in
@zaus
zaus / DelayedRenderExtensions.cs
Created September 27, 2013 18:06
RenderSections in PartialViews -- delayed rendering of any HTML content. See SO answer: http://stackoverflow.com/a/18790222/1037948
public static class HtmlRenderExtensions {
/// <summary>
/// Delegate script/resource/etc injection until the end of the page
/// <para>@via http://stackoverflow.com/a/14127332/1037948 and http://jadnb.wordpress.com/2011/02/16/rendering-scripts-from-partial-views-at-the-end-in-mvc/ </para>
/// </summary>
private class DelayedInjectionBlock : IDisposable {
/// <summary>
/// Unique internal storage key
/// </summary>
@zaus
zaus / ConfigurableJsMinify.cs
Last active January 10, 2020 02:16
How to create a custom BundleTransform in .NET MVC4, specifically for the purposes of not renaming variables. Since I could not find this after an hour of concentrated interweb searching...
using System.IO;
using Microsoft.Ajax.Utilities;
/// <summary>
/// Minify javascript files with externally overridable configuration settings.
/// </summary>
public class ConfigurableJsMinify : StandardFileBundleTransform {
protected bool includeFilenamesInOutput;
@zaus
zaus / WpPluginUpgradeBase.php
Last active October 2, 2020 17:10
Wordpress Activation/Upgrade Hook Helper
<?php
if(!class_exists('WpPluginUpgradeBase')) :
abstract class WpPluginUpgradeBase {
function __construct() {
add_action( 'admin_init', array(&$this, 'load_plugin') );
}