Skip to content

Instantly share code, notes, and snippets.

@reidev275
reidev275 / Reducing Code Friction
Last active August 29, 2015 14:16
Reducing Code Friction - A developer's journey from OO to FP
Learning a new paradigm is one of the more difficult things to do in software development.
So why would an object oriented developer of 10 years suddenly decide to make the drastic switch to functional programming?
In this talk I'll show you why I started looking for other ways of writing software and why the switch wasn't as sudden or as drastic as it may seem.
We'll start our journey with C#, discussing SOLID principals and the use of IoC containers.
Then we'll move to JavaScript to see first class functions and closures.
Next we'll visit the exciting distributed world of Elixir on the Erlang VM.
We'll finish up with F#, seeing type providers, discriminated unions, and maybe even a certain 5 letter M word.
@reidev275
reidev275 / MasterPageUtils.cs
Created March 17, 2015 20:01
Helpful function if you're dealing with varying levels of nested masterpages on a site.
public class MasterPageUtils
{
public static T Get<T>(MasterPage page) where T : class
{
if (page == null) return null;
if (page is T) return page as T;
return Get<T>(page.Master);
}
}
@reidev275
reidev275 / search.js
Created March 26, 2015 15:49
perform search function
function performSearch(query, items) {
if (query === '') return [];
var q = query.toLowerCase();
return items.map(function(x) {
var lower = x.toLowerCase();
return {
value: x,
matches: strategies.map(function(strategy) {
return strategy(q, lower);
}).filter(function(strategy) {
select * from [entity] e
OUTER APPLY
(SELECT TOP 1 [status], [date]
from [entitystatus] es (nolock)
where es.lookupid = e.Id
ORDER BY es.[Date] desc) as es
@reidev275
reidev275 / Interop.fs
Last active October 21, 2016 23:41
ROP Result Discriminated Union interop with C#
// the two-track type
type Result<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
type ResultInterop<'TSuccess, 'TFailure> = {
IsSuccess : bool
Success : 'TSuccess
Failure : 'TFailure
}
let (|RegexMatch|_|) pattern input =
let m = Regex.Match(input,pattern)
if (m.Success) then Some m else None
@reidev275
reidev275 / SeqGroupBy.fsx
Last active August 29, 2015 14:21
Turns a flat Seq into a Seq of grouped elements and a list of non distinct data
type FlatStructure = {
Id : int
Description : string
TagId : int
}
type Post = {
Id : int
Description : string
Tags : seq<int>
//DataAccess.fs
module DataAccess
open FSharp.Data
type Create =
SqlCommandProvider<
"INSERT INTO Locations(City, State) values(@city, @state)",
"name=local">
let createLocation city state =
@reidev275
reidev275 / WebApiConfig.cs
Created July 15, 2015 15:17
Web Api Config to deserialize F# types in a C# web api project
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
@reidev275
reidev275 / PasswordHasher.cs
Last active August 29, 2015 14:26
Password hashing
public interface IPasswordHasher
{
string GetSalt();
string GetHash(string password, string salt);
}
public class PasswordHasher : IPasswordHasher
{
public string GetSalt()
{