Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / $.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 / DelayedRenderExtensions.cs
Created September 27, 2013 18:06
RenderSections in PartialViews -- delayed rendering of any HTML content. See SO answer: http://stackoverflow.com/a/18790222/1037948
public static class HtmlRenderExtensions {
/// <summary>
/// Delegate script/resource/etc injection until the end of the page
/// <para>@via http://stackoverflow.com/a/14127332/1037948 and http://jadnb.wordpress.com/2011/02/16/rendering-scripts-from-partial-views-at-the-end-in-mvc/ </para>
/// </summary>
private class DelayedInjectionBlock : IDisposable {
/// <summary>
/// Unique internal storage key
/// </summary>
@zaus
zaus / text-input-love.html
Last active December 20, 2015 20:49
A CodePen by Michael Arestad. Text input love - I wanted to play with some input styles that don't rely on hover, don't add clutter, show the label at all times, and show placeholder text when it is actually relevant.
<div class="row">
<p>Click every input.</p>
</div>
<div class="row">
<span>
<input class="basic-slide" id="name" type="text" placeholder="Your best name" /><label for="name">Name</label>
</span>
<span>
<input class="basic-slide" id="email" type="text" placeholder="Your favorite email" /><label for="email">Email</label>
</span>
@zaus
zaus / index.html
Created June 20, 2013 13:12
Nice complementary colors. A #CodePen by JB Price.
<div class="box red"></div>
<div class="box orange"></div>
<div class="box yellow"></div>
<div class="box green"></div>
<div class="box teal"></div>
<div class="box blue"></div>
<div class="box purple"></div>
<div class="box pink"></div>
@zaus
zaus / jquery.removeClassWhere.js
Created March 22, 2013 13:30
The missing jQuery function to easily remove classes matching a filter -- combines `$el.removeClass` and `$.grep`.
$.fn.removeClassWhere = function (filter) {
/// <summary>
/// Remove classes matching a filter fn(class, index_in_list) -- combines .removeClass and .grep
/// <example>$('.things').removeClassWhere(function (cl) { return -1 != cl.indexOf(matches); });</example>
/// </summary>
return $(this).removeClass(function (i, classes) {
return $.grep(classes.split(' '), filter).join(' ');
});
};//-- fn removeClassWhere
@zaus
zaus / parse-hash-bang-arguments-in-javascript.js
Last active December 15, 2015 04:29 — forked from miohtama/parse-hash-bang-arguments-in-javascript.js
Parse "hashbang" `#!` arguments like url query-string. [original source](https://gist.github.com/miohtama/1570295)
/**
* Parse hash bang parameters from a URL as key value object.
* For repeated parameters the last parameter is effective.
* If = syntax is not used the value is set to null.
* #!x&y=3 -> { x:null, y:3 }
* @param url URL to parse or null if window.location is used
* @return Object of key -> value mappings.
* @source https://gist.github.com/zaus/5201739
*/
function hashbang(url, i, hash) {