Skip to content

Instantly share code, notes, and snippets.

View mythz's full-sized avatar

Demis Bellot mythz

View GitHub Profile
@mythz
mythz / basic-fsharp-gtk-demo.fs
Created September 15, 2011 05:16
Basic F# demo using Mono Gtk#
let btnUp = new Button("Increment", Visible=true)
let btnDown = new Button("Decrement", Visible=true)
let lbl = new Label(Text=" Count: 0", Visible=true)
Event.merge
(btnUp.Clicked |> Event.map (fun _ -> +1))
(btnDown.Clicked |> Event.map (fun _ -> -1))
|> Event.scan (+) 0
|> Event.map (sprintf " Count: %d")
|> Event.add (fun s -> lbl.Text <- s)
@mythz
mythz / twitter.fsx
Created September 20, 2011 07:47
Async download and parse twitter user into a typed record with F#
#r "ServiceStack.Text.dll"
open System.Net
open System.IO
open ServiceStack.Text
type System.Net.WebRequest with
member x.GetResponseAsync() =
Async.FromBeginEnd(x.BeginGetResponse, x.EndGetResponse)
@mythz
mythz / FSharpStack.fs
Created September 21, 2011 07:01
Standalone HelloWorld F# WebServices on Mono w/ HttpListener
(* Stand-alone HelloWorld ServiceStack Web Service with F# on Mono/Windows using HttpListener
INFO: and C#/ASP.NET HelloWorld example at: http://servicestack.net/ServiceStack.Hello/
Instructions:
1) download https://github.com/ServiceStack/ServiceStack/downloads
2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll FSharpStack.fs
3) sudo mono FSharpStack.exe
*)
open System
@mythz
mythz / FTweetStack.fs
Created September 21, 2011 08:27
Stand-alone ServiceStack Twitter API with F# on Mono/Windows using HttpListener
(* Stand-alone Twitter API ServiceStack Web Service with F# on Mono/Windows using HttpListener
Instructions:
1) download https://github.com/ServiceStack/ServiceStack/downloads
2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll FTweetStack.fs
3) sudo mono FTweetStack.exe
*)
open System
open System.IO
@mythz
mythz / taxOfUs.fs
Created September 22, 2011 21:26
Calculate a tax rates using F#
let taxOf salary taxRates =
((0m,0)::taxRates, taxRates)
||> Seq.zip
|> Seq.map(fun ((_, prevBand),(rate, band)) -> (prevBand, rate, band))
|> Seq.sumBy(fun (prevBand, rate, band) ->
match salary with
| x when x < prevBand -> 0m
| x when x > band -> decimal(band - prevBand) * rate
| x -> decimal(x - prevBand) * rate
)
@mythz
mythz / FastIsraelTaxCalculator.cs
Created September 24, 2011 04:19
Calculate Israel's fast with C#
using System;
namespace FastIsraelTaxCalculator
{
class MainClass
{
static readonly string[] DefaultAmounts = new[] { "5000", "5800", "9000", "15000", "50000" };
public static void Main (string[] args)
{
@mythz
mythz / FTweetStack.fs
Last active September 27, 2015 08:38
Twitter async web services with F# and ServiceStack running on Windows/OSX/Linux
(* Stand-alone Twitter API ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener
Instructions:
1) download https://github.com/ServiceStack/ServiceStack/downloads
2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll FTweetStack.fs
3) sudo mono FTweetStack.exe
*)
open System
open ServiceStack.ServiceHost
@mythz
mythz / FoldedIsraelTaxRates.fs
Created September 27, 2011 04:54
Simon Cousins Israel Tax Solution in F#
(* http://www.simontylercousins.netsolution to http://ayende.com/blog/108545/the-tax-calculation-challenge *)
let taxes salary =
let rates = [
40230.0m,0.45m;
21240.0m,0.33m;
14070.0m,0.3m;
8660.0m,0.23m;
5070.0m,0.14m;
0.0m,0.1m]
@mythz
mythz / Hello.fs
Created September 28, 2011 06:36
Stand-alone Hello World ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener
(* Stand-alone Hello World ServiceStack Web Service with F# on Mono/OSX hosted by HttpListener
Instructions:
1) download https://github.com/ServiceStack/ServiceStack/downloads
2) fsharpc -r:ServiceStack.Common.dll -r:ServiceStack.Interfaces.dll -r:ServiceStack.Text.dll -r:ServiceStack.dll Hello.fs
3) sudo mono Hello.exe
Read More: For the benefits of a ServiceStack Hello World Service see: http://www.servicestack.net/ServiceStack.Hello/
*)
@mythz
mythz / Global.asax
Created September 28, 2011 10:14
Hello World ServiceStack ASP.NET Web Service in F#
<%@ Application Inherits="HelloFSharp.Global" %>