Skip to content

Instantly share code, notes, and snippets.

@nagat01
nagat01 / gist:1008514
Created June 5, 2011 00:05
F# : Regex.IsMatch example
open System
open System.Text.RegularExpressions
// http://msdn.microsoft.com/en-us/library/ms228595(v=vs.80).aspx#Y300
let regexIsMatchSample lines pattern =
// for line in
List.iteri(fun i line ->
if Regex.IsMatch(line,pattern,RegexOptions.IgnoreCase) then
printfn"%3d : %s" i line) lines
regexIsMatchSample
module GetHomeTimeline
open System
open System.IO
open System.Text
open System.Net
open System.Web.Script.Serialization
open FSharp.Data.Json
open FSharp.Data.Json.Extensions
// This program executes 6502_functional_test.bin from https://github.com/Klaus2m5/6502_65C02_functional_tests
// It successes almost all the tests and fails the tests for decimal mode.
open System.IO
open System
open System.Collections.Generic
let hasBit i v = v &&& (1uy <<< i) <> 0uy
type Addr = Accumulator | Implied | Immediate of uint8 | Bus of int
type Addressing = Acc | Impl | Sharp | Rel | Zpg | ZpgX | ZpgY | Abs | AbsX | AbsY | Ind | XInd | IndY
@nagat01
nagat01 / gist:1004102
Created June 2, 2011 08:12
F# static variable,static constructor,destructor
// TODO: Test2's destructor does not work
open System
open System.IO
open System.Net
type Test2() =
// static variable
[<DefaultValue>]
static val mutable private i:int
// static constructor
let Size : Int = 40
var cells = [Array<Bool>]()
func min(a:Int, b:Int) -> Int {
if a > b {return b } else { return a }
}
func max(a:Int, b:Int) -> Int {
if a > b { return a } else { return b }
}
@nagat01
nagat01 / gist:1046321
Created June 25, 2011 09:42
Windows form application of stopwatch in 30 lines of code in F#
open System
open System.Drawing
open System.Windows.Forms
let mutable startTime = new DateTime()
let timerLabel = new Label(Text="0",Location=Point(0,0))
let startButton = new Button(Text="Start",Location=Point(0,24))
let stopButton = new Button(Text="Stop",Location=Point(0,48))
let clearButton = new Button(Text="Clear",Location=Point(0,72))
@nagat01
nagat01 / clorets.fs
Created March 30, 2012 22:00
F# html and javascript generator
open System
type Html =
| Tag of string * Html list
| Attribute of string * string
| Content of string
override __.ToString() =
match __ with
| Tag (tag,htmls) ->
let mutable attributes = ""
@nagat01
nagat01 / C# to F# 2.fs
Created June 2, 2011 09:50
My training.Translating C# code to F#.
(*
My training.Translating C# code to F#.
http://www.fincher.org/tips/Languages/csharp.shtml
*)
open System
open System.IO
open System.Net
module WinTab
open System
open System.Runtime.InteropServices
open System.Text
// types
type EWTICategoryIndex =
| WTI_INTERFACE = 1
| WTI_STATUS = 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;