Skip to content

Instantly share code, notes, and snippets.

@mausch
mausch / style.css
Created December 29, 2010 03:36
F# Web Snippets styles http://tomasp.net/fswebsnippets/
pre.fssnip
{
background:#f0f0f0;
font-family:consolas, monaco,'Lucida Console',monospace;
font-size:80%;
padding:10px;
margin:10px 5px 10px 5px;
position:relative;
}
var currentTip = null;
var currentTipElement = null;
function hideTip(evt, name, unique)
{
var el = document.getElementById(name);
el.style.display = "none";
currentTip = null;
}
@mausch
mausch / mathparser.fs
Created December 30, 2010 22:52
basic math exp parser
// http://stackoverflow.com/questions/4559399/can-parser-combinators-be-made-efficient
open System
open FParsec.Primitives
open FParsec.CharParsers
//let inline (<*>) f a = f >>= fun f' -> a >>= fun a' -> preturn (f' a')
//let inline lift f a = a |>> f
//let inline lift2 f a b = preturn f <*> a <*> b
let inline (<%) x y = y >>% x // (lift << (fun a b -> a)) x y
let inline ( *>) x y = x >>. y // lift2 (fun _ z -> z) x y
let editContact cmgr =
getQueryString "id"
|> Result.map (Option.bind Int32.tryParse)
|> Result.map (Option.bind (fun i ->
match Contact.GetById i cmgr with
| Tx.Commit c -> c
| _ -> None))
|> Result.map (Option.map (fun c ->
let editForm = contactFormlet c |> renderToXml
let view = contactEditOkView editForm
@mausch
mausch / gist:1406649
Created November 29, 2011 21:38
Miiitch's code
module ParserHelpers
open System
open Fissum.Linq.Wiql
/// Intercepts parsing error
let internal handleParsingError (ctxt: Microsoft.FSharp.Text.Parsing.ParseErrorContext<_>)=
failwith ctxt.Message
/// Trims the field name from lexer input
@mausch
mausch / gist:1444338
Created December 7, 2011 19:54
Representation of F# "polymorphic values"
pepe.fs:
let a = None
let b = Some 2
compiles to:
[CompilationMapping(SourceConstructFlags.Module)]
public static class Pepe
{
[CompilationMapping(SourceConstructFlags.Value)]
type Fmap = Fmap with
static member (?<-) (_, _Functor:Fmap, x:option<_> ) = fun f -> Option.map f x
static member (?<-) (_, _Functor:Fmap, g:_->_ ) = (>>) g
let inline fmap f x = (() ? (Fmap) <- x) f
Then in a separate assembly:
type Fmap with
static member (?<-) (_, _Functor:Fmap, x:list<_> ) = fun f -> List.map f x
I'm getting this message when logging in:
"Account Blocked! (#MA104) Please contact customer support"
I read in a forum that this was due to inactivity. Please consider explaining the reason when logging in instead of a cryptic message with no information.
Payoneer should send a message of reliability, but this is the exact opposite message. I'm already looking for alternatives to Payoneer...
@mausch
mausch / RegexExtensions.fs
Created January 2, 2012 22:29 — forked from anonymous/RegexExtensions.fs
F# regex active patterns proposal #2 for fsharpx
namespace Extensions
open System.Text.RegularExpressions
///Regex extensions
module Regex =
let replaceWithAcc folder state input (rx: Regex) =
let acc = ref state
let evaluator (m: Match) =
let newState, result = folder !acc m
acc := newState
@mausch
mausch / gitremoteaddall.sh
Created February 17, 2012 03:19
Adds all github forks in the network for a particular repository
mainrepo="mausch/solrnet"
urls=$(curl -s "https://api.github.com/repos/$mainrepo/forks" | grep git_url | sed -re 's/.*: "(.*)",/\1/')
for url in $urls; do
remote=$(echo $url | cut -d/ -f4)
git remote add $remote $url
done