Skip to content

Instantly share code, notes, and snippets.

View 7sharp9's full-sized avatar

Dave Thomas 7sharp9

  • Moirae Software Engineering Ltd
  • UK
  • X @7sharp9_
View GitHub Profile
@7sharp9
7sharp9 / ActivePatterns.fs
Created November 20, 2018 21:35
Language Essentials Active Patterns
namespace ClassLibrary1
open System
module SingleCase =
//definition
let (|UpperCase|) (x:string) = x.ToUpper()
//PM usage
match "foo" with
@7sharp9
7sharp9 / tech001.fs
Created November 2, 2018 20:41
Introduction to quotations
open System
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.ExprShape
open Microsoft.FSharp.Quotations.DerivedPatterns
let qliteral =
<@
let addAndMultiply a b =
@7sharp9
7sharp9 / gist:8421623
Created January 14, 2014 16:55
average of 10 runs of an fsharp script
for i in {1..10}; do time fsharp hello world.fsx; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'
@7sharp9
7sharp9 / tokenizer.fs
Last active January 2, 2016 23:49
tokenizer snippets
let idents tokens =
//reverse the tokens
let tokens = tokens |> Array.rev |> List.ofArray
let rec loop tokens result =
match tokens with
| [] -> result
| (name, token: TokenInformation) :: tail ->
match token.TokenName with
| "IDENT" -> loop tail (name :: result)
| "DOT" -> loop tail result
@7sharp9
7sharp9 / arrays.fs
Created October 13, 2013 23:08
Array declarations:
let things = [|"One";"Two";"Three"|]
let things2 = [|"One"
"Two"
"Three"|]
let things3 = [|
"One"
"Two"
"Three"
@7sharp9
7sharp9 / BasicExample.fs
Last active December 22, 2015 20:59
An Blank screen Xna App
namespace BasicExample
open Microsoft.Xna.Framework
type Basic() as x =
inherit Game()
let graphics = new GraphicsDeviceManager(x)
override x.Draw (gameTime) = x.GraphicsDevice.Clear(Color.CornflowerBlue)
@7sharp9
7sharp9 / file.cs
Last active December 17, 2015 16:59
Example of record construction syntax for multiple constructors
[ProjectFileTypeDefinition(Name)]
public class HtmlProjectFileType : KnownProjectFileType
{
public new const string Name = "HTML";
public const string HTML_EXTENSION = ".html";
public const string HTM_EXTENSION = ".htm";
public new static readonly HtmlProjectFileType Instance;
private HtmlProjectFileType() : base(Name, "Html", new[] {HTML_EXTENSION, HTM_EXTENSION}) { }
module compilertesting.Main
open System
open System.IO
open System.Text
open Microsoft.FSharp.Compiler.SimpleSourceCodeServices
[<EntryPoint>]
let main args =
[<Activity (Label = "HelloBarometer", MainLauncher = true)>]
type MainActivity () =
inherit Activity ()
let calculateAltitudeInFeet hPAs =
let pstd = 1013.25
(1.0 - Math.Pow((hPAs/pstd), 0.190284)) * 145366.45
let mainLabel = ref Unchecked.defaultof<_>
@7sharp9
7sharp9 / XsThemeHelp.fs
Created March 29, 2013 09:20
A few helpers around Colours in Xamarin Studio, these will become extensions of the Types eventually: let myGdkColour = myCairoColour |> CairoColor.toGdk
let colourStyles = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(MonoDevelop.Ide.IdeApp.Preferences.ColorScheme)
let keywordColour = colourStyle.GetForeground (colourStyle.KeywordProperty)
let cairoToHsl (c:Cairo.Color) = HslColor.op_Implicit(c)
let gdkToHsl (c:Gdk.Color) = HslColor.op_Implicit(c)
let hslToCairo (c:HslColor) : Cairo.Color = HslColor.op_Implicit(c)
let hslToGdk (c:HslColor) : Gdk.Color = HslColor.op_Implicit(c)
let cairoToGdk = cairoToHsl >> hslToGdk