Skip to content

Instantly share code, notes, and snippets.

@kjnilsson
kjnilsson / handy.fs
Last active April 6, 2018 17:49
my current favourite handy fsharp helpers
//invaluable for all those Choice<'a, exn> flows
let exnf f = Printf.ksprintf (fun s -> exn s) f
//combine paths
let (</>) x y = System.IO.Path.Combine(x, y)
//allows you to pattern match on values in the current scope rather than just literals
let (|Eq|_|) expected value =
if expected = value then Some ()
else None
@aymanosman
aymanosman / fizzbuzz.hs
Last active August 29, 2015 14:09
fizzbuzz.hs
import Data.Maybe
import Data.Monoid
import Control.Applicative
-- Mostly stolen from an answer found posted on reddit.
-- This formulation achieves a high level of modularity and clarity.
-- It is modular with respect to adding more numbers to fizz and buzz against,
-- and captures the idea of `show`ing the number by default elegantly.
t m s n = if mod n m == 0 then Just s else Nothing
-- instance Applicative ((->) a) where (<*>) f g x = f x (g x)
@folsen
folsen / Main.hs
Created March 1, 2013 14:21
JSON backend using Happstack
{-# LANGUAGE DeriveDataTypeable, OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Lazy.Char8 as L
import Control.Monad.IO.Class (liftIO)
import Control.Monad (msum, mzero)
import Data.Data (Data, Typeable)
import Data.Maybe (fromJust)
import Data.Aeson
@mythz
mythz / AuthorService.cs
Created February 10, 2012 07:36
1 class in ServiceStack
/*
With no other C# or config other than OrmLite DB config in AppHost below - this web service provides all the screenshots attached, out-of-the-box, for free.
container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(ConfigUtils.GetConnectionString("AppDb"), //ConnectionString in Web.Config
SqlServerOrmLiteDialectProvider.Instance) {
ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current) });
-- Code-first Simplicity at Great Speed - http://www.servicestack.net/benchmarks/
@gregoryyoung
gregoryyoung / gist:1500720
Created December 20, 2011 08:00
Greg's Stop Loss Kata
Greg's Stop Loss Kata
Testing is very hard when time is involved ...
A trailing stop loss is a term used in financial trading. For a very in depth explanation you can read here http://www.investopedia.com/articles/trading/03/080603.asp and http://en.wikipedia.org/wiki/Order_(exchange)#Stop_orders
However we do not need a huge amount of background in order to do the kata as we are going to limit the problem a bit.
The general idea is that when you buy into a stock at a price say $10. You want it to automatically get sold if the stock goes below $9 (-$1). If we use the term "trailing" that means that id the price goes up to $11 then the sell point becomes $10.
@madrobby
madrobby / i18n.coffee
Created November 14, 2011 15:45
Backbone i18n with CoffeeScript
# before this file is loaded, a locale should be set:
#
# In a browser environment, you can use:
# ```<script>__locale='en';</script>```
#
# In a server environment (specifically node.js):
# ```global.__locale = 'en';```
# normalize in-app locale string to "en" or "de-AT"
parts = @__locale.split('-')