Skip to content

Instantly share code, notes, and snippets.

@zaus
zaus / forms-3rdparty-migrate.php
Last active August 29, 2015 13:58
Forms-3rdparty Migrate Hack -- quick "plugin" to upgrade from CF7-3rdparty to http://wordpress.org/plugins/forms-3rdparty-integration/, or migrate settings across sites.
<?php
/*
Plugin Name: Forms: 3rd-Party Migrate
Plugin URI: https://github.com/zaus/forms-3rdparty-migrate
Description: Export/Import settings for Forms-3rdparty, or migrate to/from CF7-3rdparty
Author: zaus
Version: 0.3.2
Author URI: http://drzaus.com
*/
@zaus
zaus / copied-js.md
Last active August 29, 2015 14:00
Testing Syntax Highlighting Error

// Disable Context Menu document.oncontextmenu = function () { return false };

// Disable dragging of HTML elements document.ondragstart = function () { return false };

@zaus
zaus / F1-Main.cs
Last active August 29, 2015 14:04
Partitioning performance comparisons -- via http://stackoverflow.com/a/13745058/1037948. Essentially runs each scenario 10000 times wrapped in a timer and compares the elapsed times.
void Main()
{
test(100, 9);
test(1000, 9);
test(100, 25);
test(10000, 100);
}
// Define other methods and classes here
void test(int populationSize, int segmentSize) {
@zaus
zaus / Sign-In-Up-Transition.markdown
Created March 10, 2015 14:07
Sign In/Up Transition
@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");
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 / Haacked.StringLib.ZausFormatter.cs
Created September 21, 2012 18:37
C# Named token replacement as an alternative to the numerical tokens of String.Format - yet another attempt at performance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// via original discussion http://haacked.com/archive/2009/01/14/named-formats-redux.aspx
namespace Haacked.StringLib {
/// <summary>
/// Extension string methods for named token replacement
@zaus
zaus / Haacked.StringLib.TestSetup.cs
Created September 21, 2012 18:57
Randomly create a formatting string mask for use in testing Haacked.StringLib operations, and associated tests
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AtifAzis.Extensions;
/// for http://haacked.com/archive/2009/01/14/named-formats-redux.aspx and https://gist.github.com/3763138
namespace Tests.Haacked.StringLib {
@zaus
zaus / SublevelFilterTest.cs
Created October 18, 2012 15:09
C# Linq Sublevel Filtering - Only return 1st-level with matching 2nd-level items, but resultset only contains matching 2nd-level items
public class LinqSubsetTests {
/// example class
public class Foo {
public long ID { get; set; }
public int Filterable { get; set; }
public string Name { get; set; }
public IEnumerable<Bar> Children { get; set; }
@zaus
zaus / SublevelFilterTest_Order.cs
Created October 19, 2012 13:32 — forked from zaus/SublevelFilterTest.cs
C# Linq Sublevel Filtering - Only return 1st-level with matching 2nd-level items, but resultset only contains matching 2nd-level items; more "practical" example with Order/LineItem relationship
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Playground.Tests {
public class OrderSubsetTests {
#region -------------- classes ----------------