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 / LinqPad.MyExtensions.cs
Last active Nov 21, 2019
Linqpad Extensions - `.Title()`, `.DumpFormat(tokens)`, `.Perf(task)`, `.Vs(tasks)`
View LinqPad.MyExtensions.cs
/// <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 / FormRepo.js
Last active Nov 13, 2019
Preserve form values across page loads -- i.e. persistent forms. Uses `localStorage` to persist, `jQuery` for utilities.
View FormRepo.js
var FormRepo = function (namespace) {
/// <summary>Persistent form values, saves to localStorage</summary>
/// <param name="namespace" type="String">the namespace to store values in localStorage</param>
// should also protect per page, since we could have the same forms in various places
this.N = namespace + '.' + window.location.pathname;
};
$.extend(FormRepo.prototype, {
namespace: function (key) {
return this.N + '.' + key;
@zaus
zaus / DelayedRenderExtensions.cs
Created Sep 27, 2013
RenderSections in PartialViews -- delayed rendering of any HTML content. See SO answer: http://stackoverflow.com/a/18790222/1037948
View DelayedRenderExtensions.cs
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 / demo-output-GetPropertyName.linqpad.cs
Last active Feb 22, 2019
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".
View demo-output-GetPropertyName.linqpad.cs
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;
View PGPEncryptDecrypt.cs
/// <summary>
/// PGP round-trip encryption -- http://blogs.microsoft.co.il/kim/2009/01/23/pgp-zip-encrypted-files-with-c/#comment-611002
/// </summary>
public class PGPEncryptDecrypt
{
/**
* A simple routine that opens a key ring file and loads the first available key suitable for
* encryption.
*
* @param in
@zaus
zaus / ConfigurableJsMinify.cs
Last active Oct 20, 2018
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...
View ConfigurableJsMinify.cs
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 / 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 / $.stripClass.js
Created Sep 27, 2013
jQuery.removeClass companion -- strips out matching segments
View $.stripClass.js
$.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 / +enumerate files method comparisons.md
Last active Nov 22, 2017
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
View +enumerate files method comparisons.md
@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);
You can’t perform that action at this time.