Skip to content

Instantly share code, notes, and snippets.

View Thorium's full-sized avatar

Tuomas Hietanen Thorium

View GitHub Profile
@Thorium
Thorium / gist:1972378
Last active October 1, 2015 10:08
Simple Reactive Extensions Example
// Rx 1.0:
//#r "System.CoreEx" //for interactive and scripts
//#r "System.Reactive.dll"
//open System
//open System.Collections.Generic
//Rx 2.1:
#r "System.ComponentModel.Composition.dll"
#r "../packages/Rx-Interfaces.2.1.30214.0/lib/Net45/System.Reactive.Interfaces.dll"
#r "../packages/Rx-Core.2.1.30214.0/lib/Net45/System.Reactive.Core.dll"
@Thorium
Thorium / gist:1972380
Created March 4, 2012 10:52
Team Foundation Server: Check Out a file
//#r "Microsoft.TeamFoundation.Client"
//#r "Microsoft.TeamFoundation.VersionControl.Client"
//#r "Microsoft.TeamFoundation.VersionControl.Common"
open Microsoft.TeamFoundation.Client
open Microsoft.TeamFoundation.VersionControl.Client
let tfsCheckOut filename =
let workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo filename
let workspace = RegisteredTfsConnections.GetProjectCollections().First()
|> TfsTeamProjectCollectionFactory.GetTeamProjectCollection
@Thorium
Thorium / gist:2416591
Created April 18, 2012 21:11 — forked from mattpodwysocki/gist:165605
IObservable<T> is close to Async<T>, so why not: F# obs { ... } as async { ... }
#I @"C:\Tools\System.Reactive"
#r "System.Core.dll"
#r "System.Reactive.dll"
type observable<'a> = System.Collections.Generic.IObservable<'a>
type observer<'a> = System.Collections.Generic.IObserver<'a>
module Observable =
open System
open System.Linq
@Thorium
Thorium / gist:2416610
Created April 18, 2012 21:15
Simple NumericLiteral example
(*
You can use numeric literals, constant expressions and operator overloading to make your own arithmetics. Useful in DSL languages.
With NumericLiterals, you can use any of Q, R, Z, I, N, G.
Basic syntax: [Number][Letter] will forward the call to the type NumericLiteral[Letter] to FromInt32 [Number] (or FromInt64 or FromString...)
*)
//-----------------------------------------------------
//First example:
module NumericLiteralN =
@Thorium
Thorium / gist:2416622
Created April 18, 2012 21:17
F# 3.0 - EntityFramework Type Provider usage with Northwind DB
//A small sample how to use F# 3.0 Entity Framework (EF) Type Provider. Visual Studio 11 Beta (and Northwind sample database) needed.
(*
#r "System.Data.Entity.dll"
#r "FSharp.Data.TypeProviders.dll"
*)
open System
open Microsoft.FSharp.Data.TypeProviders
module Queries =
@Thorium
Thorium / NullableBuilder.fs
Created April 19, 2012 17:21
Computational expressions / monad / builder example: Nullable
module BuilderExample
open System
//Example: nullable { ... } with combining functionality
type NullableBuilder() =
let hasValue (a:Nullable<'a>) = a.HasValue
member t.Return(x) = Nullable(x)
member t.Bind(x, rest) =
match hasValue x with
@Thorium
Thorium / gist:2473882
Created April 23, 2012 21:07 — forked from forki/gist:1400378
Poor mans type classes
// Mimic type classes with additional param
type 'a Num = {
zero: 'a
add: 'a -> 'a -> 'a
mult: 'a -> 'a -> 'a
fromInteger: int -> 'a }
let intNum = {
zero = 0
@Thorium
Thorium / gist:4989024
Created February 19, 2013 19:28
Example of state of the art C#: EntityFramework done right... :-)
// This shows how you can:
// 1) Code from top-down, give high level picture first and then go to details
// 2) Define LINQ outside EF-context and still convert it to SQL:
// - Don't hammer the database!
// 3) Have small independend classes (/parts)
// 4) Have state-less code with no global/class-variables outside entities
// 5) Easy to test:
// - Integration test with EF-DbContext.
// - LINQ logics unit tests without DbContext (with unit tests InternalsVisibleToAttribute).
@Thorium
Thorium / gist:5001162
Created February 21, 2013 01:21
Agent that can upgrade its functionality on the fly. (F# MailboxProcessor containing function in the loop...)
// Erlang-style message-passing:
// Agent that can upgrade its functionality on the fly.
// Note: static typing, this agent can't upgrade its state data type (so better to use obj or custom interface)...
// Also this runs only in localhost...
// So this is more a technical demo than something useful
open System
type Methods<'state, 'x, 'reply> =
| Upgrade of
@Thorium
Thorium / gist:5181342
Created March 17, 2013 12:40
Making QR-code image having contact information (VCard) with Google Chart API. If you scan this image with mobile phone, you can directly add new person to your contacts.
open System
open System.IO
open System.Net
open System.Drawing
let ImageSize = 300
let fetchImage (url : Uri) =
let req = WebRequest.Create (url) :?> HttpWebRequest
use stream = req.GetResponse().GetResponseStream()