Skip to content

Instantly share code, notes, and snippets.

View imerchant's full-sized avatar

Imran Merchant imerchant

View GitHub Profile
@imerchant
imerchant / OptionTypeConverter.fs
Created April 25, 2016 19:16
Json.NET Type Convertor for F# Option<_> support
module OptionTypeConverter
open System
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
// http://gorodinski.com/blog/2013/01/05/json-dot-net-type-converters-for-f-option-list-tuple/
type OptionTypeConverter() =
inherit JsonConverter()
@imerchant
imerchant / Program.fs
Created April 25, 2016 20:47
Use of Json.NET OptionTypeConverter and NullValueHandling in F#
open System
open Newtonsoft.Json
open OptionTypeConverter
let jsonSettings = JsonSerializerSettings()
jsonSettings.NullValueHandling <- NullValueHandling.Ignore
jsonSettings.Converters.Add(OptionTypeConverter())
let serialize obj = JsonConvert.SerializeObject obj
let serialize' obj = JsonConvert.SerializeObject(obj, jsonSettings)
open System
type Message =
| Default
| Custom of string
type Person = {
name : string
age : int
}
let person name age = {name = name; age = age }
@imerchant
imerchant / Comparer.cs
Created July 11, 2016 05:21
implmentation of IEqualityComparer<> with Func<> inputs for overrides
public class Comparer<T> : IEqualityComparer<T>
{
private readonly Func<T, int> _getHashCode;
private readonly Func<T, T, bool> _equals;
public Comparer(Func<T, T, bool> equals) : this(equals, null)
{
}
public Comparer(Func<T, int> getHashCode) : this(null, getHashCode)
$fonts = (New-Object -ComObject Shell.Application).Namespace(0x14)
gci *.ttf | %{ $fonts.CopyHere($_.fullname) }
@imerchant
imerchant / ContentType.cs
Created September 26, 2017 14:02
Strongly typed enumeration
public class ContentType : Enumeration<int, ContentType>
{
public static readonly ContentType Json = new ContentType(1, "Json", "application/json");
public static readonly ContentType Pdf = new ContentType(2, "PDF", "application/pdf");
public static readonly ContentType Text = new ContentType(3, "Text", "text/plain");
public string HeaderValue { get; private set; }
private ContentType(int key, string displayName, string headerValue) : base(key, displayName)
{
Password hacking: How many possible numbers exist to hack a password with the rules below, and what are they?
1. Composed of the digits 1-9
2. 2-9 digits in length
3. Digits do not repeat
4. Digits are in ascending order
Output should include a full list of possible password strings and the total count.
Good examples
29
234