Skip to content

Instantly share code, notes, and snippets.

View smoothdeveloper's full-sized avatar

Gauthier Segay smoothdeveloper

View GitHub Profile
@smoothdeveloper
smoothdeveloper / export.chart.to.image.fsx
Created March 1, 2024 10:50
DevExpress XtraCharts: How to: Export a Chart to Image
// Dev Express documentation is lacking F# interactive samples
// https://docs.devexpress.com/WindowsForms/2508/controls-and-libraries/chart-control/examples/producing-output/how-to-export-a-chart-to-image
#r @"paket: nuget DevExpress.XtraCharts.v21.1"
open System.IO
open System.Windows.Forms
open DevExpress.XtraCharts
let pieChart = ChartControl(Width=1600,Height=1000)
let series =
new Series(
@smoothdeveloper
smoothdeveloper / byref.samples.fs
Created April 5, 2020 17:33
Samples from Matt Ellis "Writing Allocation Free Code in C#" talk
// replicating same techniques as
// https://youtu.be/1ZJ8ROVS5gk?t=1435
[<Struct>]
type Point =
val mutable X : int
val mutable Y : int
new(x, y) = { X = x; Y = y }
type Enemy(location: Point) =
@smoothdeveloper
smoothdeveloper / sqlconnection.statistics.fs
Created July 19, 2019 13:04
a bit of F# code handling sql connection statistics
open System
open System.Data.SqlClient
type EntryType =
| BuffersReceived
| BuffersSent
| BytesSent
| ConnectionTime
| CursorOpens
| IduCount
@smoothdeveloper
smoothdeveloper / ironfunctions.test.fs
Created December 7, 2016 18:35
IronFunctions help Seif Lotfy
// code converted for http://seif.codes/playing-with-net-dotnet-and-ironfunctions/
// https://twitter.com/SeifLotfy/status/805901527659540480
open System
open System.IO
open System.Security.Cryptography
open System.Text
let downloadRemoteImageFile (url: string) =
let request = url |> System.Net.WebRequest.CreateHttp
@smoothdeveloper
smoothdeveloper / create.table.based.on.existing.schema.sql
Created July 26, 2016 19:37
create table based on existing table schema
declare
@templateSchemaName nvarchar(max)
, @templateTableName nvarchar(max)
, @newSchemaName nvarchar(max)
, @newTableName nvarchar(max)
with columninfo as (
select
t.name table_name
, c.name column_name
open System
open System.Data
module DataTableMaker =
type ColumnMaker<'t> = { Name: string; Type: Type; GetValue: 't -> obj }
let makeColumn name (f: _ -> 'c) =
{ Name = name; Type = typeof<'c>; GetValue = f >> box }
@smoothdeveloper
smoothdeveloper / CsvDistinctValuesProvider.fs
Created June 21, 2016 13:36
CsvDistinctValuesProvider
namespace MyTypeProviders
open System
open System.IO
open System.Reflection
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open CsvHelper
open System.Collections.Generic
open Microsoft.FSharp.Quotations
@smoothdeveloper
smoothdeveloper / package.devexpress.fsx
Created February 11, 2016 04:49
Package devexpress assemblies as nuget packages
#r "../../../../packages/Mono.Cecil/lib/net40/Mono.Cecil.dll"
#r "../../../../packages/QuickGraph/lib/net4/QuickGraph.dll"
#r "../../../../packages/FAKE/tools/FakeLib.dll"
open Mono.Cecil
open System.IO
open QuickGraph
open System.Linq
open System.Reflection
let folder = @"C:\testing\DevExpress 15.2\Components\Bin\Framework"
@smoothdeveloper
smoothdeveloper / generate_add_and_drop_all_constraints.sql
Created February 27, 2015 13:22
SqlServer: Generate alter add / drop for all type of constraints (foreign key, unique and check)
with
unique_constraint_infos (schemaname, tablename, constraintname, columnname)
as (
select
quotename(tc.table_schema)
, quotename(tc.table_name)
, quotename(tc.constraint_name)
, quotename(cc.column_name)
from
information_schema.table_constraints tc
@smoothdeveloper
smoothdeveloper / format-timespan.fsx
Created February 27, 2015 02:17
System.TimeSpan user-friendly formatting
open System
type Part = Days of int
| Hours of int
| Minutes of int
| Seconds of int
| Milliseconds of int
let bigPartString p =
match p with
| Days 0 -> ""