Skip to content

Instantly share code, notes, and snippets.

@zaus
zaus / forms-3rdparty-migrate.php
Last active Aug 29, 2015
Forms-3rdparty Migrate Hack -- quick "plugin" to upgrade from CF7-3rdparty to http://wordpress.org/plugins/forms-3rdparty-integration/, or migrate settings across sites.
View forms-3rdparty-migrate.php
<?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 Aug 29, 2015
Testing Syntax Highlighting Error
View copied-js.md

// 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 Aug 29, 2015
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.
View F1-Main.cs
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) {
View Sign-In-Up-Transition.markdown
@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 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 / Haacked.StringLib.ZausFormatter.cs
Created Sep 21, 2012
C# Named token replacement as an alternative to the numerical tokens of String.Format - yet another attempt at performance
View Haacked.StringLib.ZausFormatter.cs
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 Sep 21, 2012
Randomly create a formatting string mask for use in testing Haacked.StringLib operations, and associated tests
View Haacked.StringLib.TestSetup.cs
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 Oct 18, 2012
C# Linq Sublevel Filtering - Only return 1st-level with matching 2nd-level items, but resultset only contains matching 2nd-level items
View SublevelFilterTest.cs
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 Oct 19, 2012 — 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
View SublevelFilterTest_Order.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Playground.Tests {
public class OrderSubsetTests {
#region -------------- classes ----------------
You can’t perform that action at this time.