Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Marisic dotnetchris

View GitHub Profile
@dotnetchris
dotnetchris / GitForWindowsSetup.md
Last active Feb 5, 2021 — forked from dmangiarelli/GitForWindowsSetup.md
How to setup Git for Windows
View GitForWindowsSetup.md

How to setup Git for Windows

Improve developer's experience inside powershell, adding useful commands like Add-PathVariable. This is optional but recommended to minimize confirmation of every single action you invoke.

First let's update powershell itself (elevated):

iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
@dotnetchris
dotnetchris / 0_reuse_code.js
Created Aug 14, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dotnetchris
dotnetchris / EnsureModelStateIsValid.cs
Last active Jun 27, 2019
AspNetCore.Mvc action filter for ensuring validation of both model state and all action parameters as a precondition to a MVC action
View EnsureModelStateIsValid.cs
/// <summary>
/// This action filter ensures ModelState.IsValid is true as a precondition to entry into the MVC action
/// </summary>
/// <remarks>
/// This class also validates all action parameters unlike the default behavior of ModelState.IsValid
/// </remarks>
/// <see cref="https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/" />
public class EnsureModelStateIsValid : ActionFilterAttribute
{
private static readonly ConcurrentDictionary<MethodInfo, ParameterInfo[]> MethodCache
@dotnetchris
dotnetchris / Base58.cs
Last active Oct 9, 2020
Base58 is case SENSITIVE alphanumeric ELIMINATING: 0 (zero), I (uppercase), O (uppercase), l (lowercase)
View Base58.cs
/// <summary>
/// Base58 is case SENSITIVE alphanumeric ELIMINATING: 0 (zero) I (uppercase), O (upppercase), l (lowercase)
/// This reduction of characters eliminates the majority of human typoposition errors
/// </summary>
public class Base58
{
private static readonly BaseN base58 = new BaseN("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"); //base58
public static string Encode(long @long) => base58.Encode(@long);
@dotnetchris
dotnetchris / OrdinalIgnoreCaseString.cs
Last active Aug 30, 2016
Allows you to treat strings as case insensitive
View OrdinalIgnoreCaseString.cs
struct OrdinalIgnoreCaseString : IEquatable<OrdinalIgnoreCaseString>, IEquatable<string> {
string _str;
public OrdinalIgnoreCaseString(string str) {
_str = str;
}
public static implicit operator OrdinalIgnoreCaseString(string str) {
return new OrdinalIgnoreCaseString(str);
}
View jquery-observe.js
(function(d) {
d.Observe = {}
})(jQuery);
(function(d, q) {
var r = function(e, f) {
f || (f = e, e = window.document);
var m = [];
d(f).each(function() {
for (var l = [], g = d(this), h = g.parent(); h.length && !g.is(e); h = h.parent()) {
var f = g.get(0).tagName.toLowerCase();
View My Git aliases
[alias]
co = checkout
ci = commit
branches = branch
syncdev = "!git fetch origin; git merge origin/development"
up-c = checkout -f
View 1 - Map Arguments to Properties.cs
// Runnable from Linqpad 5
// Must install the Sigil nuget package and include the Sigil namespace
void Main()
{
var createSample = GetMapperDelegate();
// try it out
createSample(23, "Hello").Dump();
}
@dotnetchris
dotnetchris / PageDown Headings that support H1-H4
Created Sep 30, 2014
PageDown Headings that support H1-H4
View PageDown Headings that support H1-H4
//replace this method
commandProto.doHeading = function (chunk, postProcessing) {
// Remove leading/trailing whitespace and reduce internal spaces to single spaces.
chunk.selection = chunk.selection.replace(/\s+/g, " ");
chunk.selection = chunk.selection.replace(/(^\s+|\s+$)/g, "");
// If we clicked the button with no selected text, we just
// make a level 2 hash header around some default text.
if (!chunk.selection) {
chunk.startTag = "#### "; /* rewrite to start at H4 instead */
View StyleRelativePathTransform
public class StyleRelativePathTransform : IBundleTransform
{
private const string UrlPattern = @"url\s*\(\s*([""']?)([^:)]+)\1\s*\)";
private static readonly Regex UrlRegex = new Regex(UrlPattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
public void Process(BundleContext context, BundleResponse response)
{
var mergedCss = new StringBuilder();