Skip to content

Instantly share code, notes, and snippets.

zaus

Block or report user

Report or block zaus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zaus
zaus / bkmklt-replace-in-selected-text.js
Last active Oct 3, 2018
Bookmarklet - Replace in Selected Text
View bkmklt-replace-in-selected-text.js
(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 Jun 30, 2017
Comparing Collection.Contains for various sets of data
View Test-Collection-Contains.linq.cs
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 Sep 22, 2016 — forked from marksteve/gist:877210
Monokai Notepad2 Color Scheme /mod
View gist:71a7a89bc3bec0d8ea2faaa287c20c82
[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 Feb 12, 2016
Simple WP debug helper "plugin"
View debug-me.php
<?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 Jan 18, 2016
Simple javascript comparison of two objects with console logging/warning when different
View compObj.js
/**
* 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
View header-loop-perf.cs
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");
View enviro-switch.php
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 */
View SimpleServer.cs
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 Aug 29, 2015
Demonstrating potential side effects (multiple evaluation) due to fast partitioning method from Stack Overflow answer http://stackoverflow.com/a/13745058/1037948
View enumerable.partition.md

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");
View Sign-In-Up-Transition.markdown
You can’t perform that action at this time.