Skip to content

Instantly share code, notes, and snippets.

View OnorioCatenacci's full-sized avatar

Onorio Catenacci OnorioCatenacci

View GitHub Profile
@OnorioCatenacci
OnorioCatenacci / SmallJSONDemo.fs
Created July 16, 2010 00:42
F# fragment for JSON Serialize/Deserialize
(* Borrowed very liberally from
https://blogs.msdn.com/b/jomo_fisher/archive/2010/03/06/neat-samples-f-freebase-and-dgml.aspx
and
http://cs.hubfs.net/forums/permalink/11096/11096/ShowThread.aspx#11096
Many thanks to both those posters for giving me 99% of the starting code
@OnorioCatenacci
OnorioCatenacci / ReturnRandomString.fs
Created December 9, 2010 12:58
Return a random string from an array of strings
// Copy/paste this into the FSI to see what it does.
open System
let a = [|"a";"b";"c";"d"|]
let randstring (arr:string[]) =
let r = new Random()
arr.[r.Next(arr.Length)]
let resultstring = randstring a;;
@OnorioCatenacci
OnorioCatenacci / UnitsOfMeasure2.fs
Created August 1, 2011 15:51
F# Units of Measure and Interfaces
module measures
type ILinear =
interface
end
[<Measure>] type inch =
@OnorioCatenacci
OnorioCatenacci / FilterTextFile.fsx
Created October 24, 2011 01:19
A quick and dirty F# Shell Script to filter a text file for all lines which match a certain string
(*
* Filter a specified file into a second file
* Onorio Catenacci
* 21 October 2011
*)
#r "System.dll"
open System.IO
//Remember:
@OnorioCatenacci
OnorioCatenacci / ExecFsx.ps1
Created November 11, 2011 20:11
Quick Powershell Script For Running Fsharp Shell Scripts
#11 November 2011
#ExecFsx.ps1
#Onorio Catenacci
#Insure we get all the error checking from Powershell itself that we can
set-strictmode -version latest
#Set this to point at the location of fsi.exe on your machine.
set-variable -name fsi -value """$env:ProgramFiles\Microsoft F#\v4.0\fsi.exe""" -option constant
#This is where I put all of my .fsx files. Change this to your favorite location
@OnorioCatenacci
OnorioCatenacci / StartST2.fsx
Created February 29, 2012 16:18
Start Sublime Text 2 With Git Plugin
#nowarn "62"
//Note this is running on Win7 x64 but git is 32 bit.
let pathEnvVar = "Path"
let gitBin = @"\Program Files (x86)\Git\bin"
let st2Bin = @"\Program Files\Sublime Text 2"
let currentPath = System.Environment.GetEnvironmentVariable(pathEnvVar)
let modifiedPath = gitBin ^ ";" ^ st2Bin ^ ";" ^ currentPath
System.Environment.SetEnvironmentVariable (pathEnvVar,modifiedPath)
@OnorioCatenacci
OnorioCatenacci / githelpers.ps1
Created April 8, 2013 16:00
Everyday Git Aliases For Powershell (Github For Windows)
#Adjust these values for your own installation.
Set-Variable -Name defaultDirectory -option Readonly -value "c:/mydev"
Set-Variable -Name defaultRepository -option Readonly -value "myrepo"
Set-Variable -Name defaultBranch -option Readonly -value "workbranch"
#Per "Everyday git-aliases", do a rebase as opposed to a merge
function gpurr($repository=$defaultRepository, $branch=$defaultBranch)
{
& 'git' pull --rebase $repository $branch
}
@OnorioCatenacci
OnorioCatenacci / CheckForConn.fs
Last active December 18, 2015 10:39
F# Code To Check For Connection Type With Xamarin.Android
open Android.App
open Android.Content
open Android.Net
let IsConnectionAvailable (app:Activity) connTypeToCheckFor =
let n = app.GetSystemService(Context.ConnectivityService)
let cm =
match n with
@OnorioCatenacci
OnorioCatenacci / DigitScript.fsx
Last active December 4, 2022 08:25
Machine Learning Dojo
// This F# dojo is directly inspired by the
// Digit Recognizer competition from Kaggle.com:
// http://www.kaggle.com/c/digit-recognizer
// The datasets below are simply shorter versions of
// the training dataset from Kaggle.
// The goal of the dojo will be to
// create a classifier that uses training data
// to recognize hand-written digits, and
// evaluate the quality of our classifier
@OnorioCatenacci
OnorioCatenacci / fortunecookie.fsx
Created October 10, 2013 12:56
Connect F# To Access Via Odbc
open System
open System.Data.Odbc
open System.Windows.Forms
let connectToAccess filename =
let connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;FileDSN=" + filename + ";User Id=admin;Password=;"
new OdbcConnection(connectionString)
let connectToDb() =