Skip to content

Instantly share code, notes, and snippets.

View mishrsud's full-sized avatar
🎯
Focusing

Sudhanshu Mishra mishrsud

🎯
Focusing
View GitHub Profile

Summary

Describes the Typesafe enum pattern, i.e. a way for a class to behave as an enumeration yet be strongly typed such that casting something to that class throws an exception.

Use Case

E.g. When receiving a request parameter from a ASP.NET Web API, if a field is of type enum, by default an invlid value will bind as an out of range integer It takes some plumbing to let the binding throw an exception that can be translated as a bad request response to the caller. A type safe enum provides safety in such scenarios.

References

Jimmy Bogard

#Summary How to merge with unrelated histories from a remote.

Step 1

git pull origin master --allow-unrelated-histories

Step 2

@mishrsud
mishrsud / Make-excutable-shellScript.md
Last active June 12, 2017 11:43
How-to: Make a shell script executable and run as root

How-to: Make a shell script as executable and run as root

1. Create a file in a directory of choice

$ vi script-file.sh

2. Edit/Insert contents

  • To paste from clipboard, enter edit mode by clicking "I" (insert mode)

Summary

This document addresses scenarios such as below:

  1. You branched as branch-123 from develop on a repository
  2. To get your changes tested along with some other branch-345, you merged branch-345 into yours
  3. When the time came to review your branch-123 against develop, there are changes from branch-345 as well (which isn't yet merged to develop)
  4. Hence, you need to remove commits from branch-345 to have the PR show only the diff between branch-123 and develop

Solution

Assume the git log looks like the following

.NET Core 2.0 SDK Preview 1 Support in Visual Studio for Mac

This document covers the steps required in order to use build and run .NET Core 2.0 and .NET Standard 2.0 projects with Visual Studio for Mac.

Existing project templates target .NET Core 1.1

If only the .NET Core 2.0 SDK is installed then the projects will fail to run due to the 1.1 runtime being unavailable. To target .NET Core 2.0 the TargetFramework in the project will need to be edited to target netcoreapp2.0 or netstandard2.0. Alternatively the dotnet cli installed with the .NET Core 2.0 SDK can be used to create the project with the correct dependencies and target framework.

.NET Core App 2.0 Project

@mishrsud
mishrsud / CSharpLambdaWithClosure.md
Last active March 20, 2017 23:32
ReSharper Access to modified Closure Warning

Summary

Gist of what a modified closure looks like and when one must be careful when using a closure that access an outer scope that may be modified

Example

// A self-contained lambda. Not a closure.
Action printOne = () => { Console.WriteLine("one"); };

// A closure - a lambda that captures a variable from an outer scope.
@mishrsud
mishrsud / CORSandCAS.md
Created March 16, 2017 00:05
CORS, CAS, AJAX, JavaScript and Browser issues explained

Summary

CORS or Cross Origin Resource Sharing is a way to allow cross domain requests to be serviced by the browser. It was implemented by browser vendors as a response to requests to let client side script make webservice calls across domains. Point to note is that it is the called webservice that has to allow CORS by adding appropriate headers to the response: Access-Control-Allow-Origin Access-Control-Allow-Headers Access-Control-Allow-Methods

Terms

  1. CAS: Central Authentication Service - aka Single Sign on
  2. CORS: Cross Origin Resource Sharing
@mishrsud
mishrsud / SQL-join-cheat-sheet.md
Last active January 15, 2025 17:23
SQL Joins Cheat Sheet
@mishrsud
mishrsud / UnhandledExceptionLoggingSetup
Last active February 21, 2017 23:18 — forked from gkinsman/new_gist_file
UnhandledExceptionLogger
public static class UnhandledExceptionLogger
{
public static void Install()
{
var log = Log.ForContext(typeof(UnhandledExceptionLogger));
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
log.Fatal(e.ExceptionObject as Exception, "Unhandled exception caught at AppDomain boundary (terminating: {IsTerminating})", e.IsTerminating);
};