Skip to content

Instantly share code, notes, and snippets.

View rexcfnghk's full-sized avatar

Rex Ng rexcfnghk

  • Hong Kong
  • 08:38 (UTC +08:00)
View GitHub Profile
@rexcfnghk
rexcfnghk / RemoveUnderscoreForeignKeyNamingConvention.cs
Last active March 8, 2019 15:06
Naming convention for Entity Framework to remove underscores in foreign key names in many-to-many relationships, improved upon SO answer: http://stackoverflow.com/a/18245172/465056
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace EFTest.Entities.Conventions
{
public class RemoveUnderscoreForeignKeyNamingConvention : IStoreModelConvention<AssociationType>
{
public void Apply(AssociationType item, DbModel model)
@rexcfnghk
rexcfnghk / index.html
Created June 23, 2015 08:02
Shortest valid HTML
<!DOCTYPE html><meta charset="utf-8"><title>a</title>
@rexcfnghk
rexcfnghk / KeyValuePair`2.cs
Last active August 29, 2015 14:25
KeyValuePair implementation using C♯ 6 features
using System;
public struct KeyValuePair<TKey, TValue> : IEquatable<KeyValuePair<TKey, TValue>>
{
public KeyValuePair(TKey key, TValue value)
{
Key = key;
Value = value;
}
@rexcfnghk
rexcfnghk / ByteConverter.cs
Last active July 11, 2016 15:57
Convert a string to bytes
public static class StringEncodingUtilities
{
public static IEnumerable<string> GetBytes(this string input, Encoding encoding)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
if (encoding == null)
// int -> 'a -> unit
printfn "Current index: %i Current element: %A"
// the function parameter has the signature int -> char -> unit
List.iteri (printfn "Current index: %i Current element: %A") ['a'..'e']
// The lambda still has the signature of int -> char -> unit
List.iteri (fun i -> printfn "Current index: %i Current element: %A" (i + 1)) ['a'..'e']
// int -> int -> int
let add x y = x + y
// int -> (int -> int)
let add x = (+) x
// (int -> int -> int)
let add = (+)
// (int -> int)
let addOne = (+) 1
// Analogous to the above
let addOne x = 1 + x
// Analogous to the above as well
let addOne x = (+) 1 x
// Eta-reduction of the above
val addOne: int -> int
val List.iteri: (int -> 'a -> unit) -> 'a list -> unit