Skip to content

Instantly share code, notes, and snippets.

@zaus
zaus / bkmklt-replace-in-selected-text.js
Last active August 4, 2022 11:20
Bookmarklet - Replace in Selected Text
(function() {
function getSelectionText() {
// https://stackoverflow.com/questions/5379120/get-the-highlighted-selected-text
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
@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 / 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 / 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 / compObj.js
Last active January 18, 2016 16:36
Simple javascript comparison of two objects with console logging/warning when different
/**
* Compare versions of objects and warn of differences
* @param {object} v1 variant 1
* @param {object} v2 variant 2
* @param {bool} stringify optionally (if provided and `true`) stringify the variant parameters when dumping
* @param {string} root [internal use] nested key placeholder
* @example <caption>Example comparing two things:</caption>
* // should result in warnings for 'foo' and 'somebool'
* compObj({foo: "bar", id: 123, somebool: true}, {bar: "foo", id: 123, somebool: 'true'});
* @returns {void} nothing -- see console logging
void Main()
{
var headers = new System.Net.WebHeaderCollection();
headers.Add("xxx", "yyy");
headers.Add("zzz", "f&&ff");
headers.Add("xxx", "ttt");
headers.Add("yyy", "33,3");
headers.Dump("raw");
headers.ToString().Dump("string'd");
@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 */
using System.IO;
// modified from RestSharp unit tests https://github.com/restsharp/RestSharp/blob/master/RestSharp.IntegrationTests/Helpers/SimpleServer.cs
namespace UnitTesting
{
using System;
using System.Net;
using System.Security;
using System.Threading;
@zaus
zaus / enumerable.partition.md
Last active August 29, 2015 14:22
Demonstrating potential side effects (multiple evaluation) due to fast partitioning method from Stack Overflow answer http://stackoverflow.com/a/13745058/1037948

Explanation

After using the suggested Partition solution on a set of data that had calculations applied to each element before being enumerated (see scenarios below), I noticed the application took much longer. Investigated via tests.cs and discovered that each item will be evaluated twice. See differences in sideeffect in results.

Original Scenario

var items = database.Fetch(filter).ToList();
var calculatedStuff = items.Select(item => new CalculatedItem(item));
// other stuff
var file = new SomeFileHelperThing("filename");
@zaus
zaus / Sign-In-Up-Transition.markdown
Created March 10, 2015 14:07
Sign In/Up Transition