Skip to content

Instantly share code, notes, and snippets.

@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
@zaus
zaus / ExtensionMethods.cs
Created October 8, 2013 13:37
Comparing results of Nested Property/Field extraction via Reflection or Expression Tree; testing in LinqPad -- from http://stackoverflow.com/questions/536932/how-to-create-expression-tree-lambda-for-a-deep-property-from-a-string
public static class ObjectExtensions {
public static object ReflectValue(this object o, string path) {
// http://stackoverflow.com/a/4474015/1037948
return path.Split('.').Aggregate(o, (current, component) => {
var property = current.GetType().GetProperty(component);
if(null == property) {
var field = current.GetType().GetField(component);
if(null == field) return null;
return field.GetValue(current);
}
@zaus
zaus / demo-output-GetPropertyName.linqpad.cs
Last active October 2, 2021 20:20
From StackOverflow discussion http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression/17220748#17220748 -- demonstrating the behavior of various solutions via LinqPad to answer questions in the comments. Usage: LinqPad as "C# Program".
void Main()
{
// from comment discussion http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression/17220748#17220748
Expression<Func<O, int>> exprId = o => o.Id;
Expression<Func<O, string>> exprName = o => o.Name;
Expression<Func<O, int[]>> exprItems = o => o.Items;
Expression<Func<O, int>> exprItemsLength = o => o.Items.Length;
Expression<Func<O, Subclass>> exprChild = o => o.Child;
Expression<Func<O, string>> exprChildName = o => o.Child.Name;
@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 / +enumerate files method comparisons.md
Last active April 6, 2021 11:56
EnumerateFiles filtering on multiple extensions -- performance comparison of various methods. From discussion at http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters
@zaus
zaus / Platform-game-engine.markdown
Created December 12, 2013 16:27
A Pen by suffick.

Platform game engine

A simple platform game engine, the map is customisable and scriptable. Refer to the comments in the "map" variable for instructions.

I plan to expand the engine in the future, the ability to use images for tiles and the player is one thing that I have in mind. Any suggestions are welcome.

A Pen by suffick on CodePen.

License.

@zaus
zaus / Random-Maze-Generator.markdown
Created December 18, 2013 14:42
A Pen by Gabriel Valfridsson.

Random Maze Generator

Generating a maze with a simple algorithm

  1. Find available directions
  2. pick one at random
  3. if no available directions, backtrack to last position loop step 1 to 3 until back at start location

A Pen by Gabriel Valfridsson on CodePen.

@zaus
zaus / LinqPad.MyExtensions.cs
Last active February 20, 2021 15:42
Linqpad Extensions - `.Title()`, `.DumpFormat(tokens)`, `.Perf(task)`, `.Vs(tasks)`
/// <summary>Silly convenience initializer for creating Vs tasks with a dictionary;
/// can use <code>new Perf { { "task1", n => whatever }, {"task2", n => bar}...}.Vs()</code>
/// <para>see http://stackoverflow.com/a/14000325/1037948 </para>
/// </summary>
/// <remarks>Doesn't automatically call <see cref="Vs"/> because...</remarks>
public class Perf : Dictionary<string, Action<int>> {}
/// <summary>Silly convenience initializer for creating Vs tasks with a dictionary that can also provides some output;
/// can use <code>new Perf&lt;T&gt; { { "task1", n => whatever }, {"task2", n => bar}...}.Vs()</code>
/// <para>see http://stackoverflow.com/a/14000325/1037948 </para>
@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
*/