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 / 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 / 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 / gist:6898062
Created October 9, 2013 08:29
dynamic transact-sql contingency table implementing http://stackoverflow.com/a/10404455 in a generic manner
create procedure dbo.dynamic_simple_contingency_table_query
@withExpression nvarchar(max) -- ^ optional with CTE expression
, @selectStatement nvarchar(max) -- ^ select statement, should return at least three columns, whose name matches following parameters
, @row_column_key nvarchar(max) -- ^ column name which identifies row keys (result will have as many distinct rows as found here)
, @column_column_key nvarchar(max) -- ^ column name which identifies column keys (result will have as many distinct values as found here)
, @fact_column_key nvarchar(max) -- ^ column name which contains facts
as
begin
declare @sql nvarchar(max)
set @sql = @withExpression
@smoothdeveloper
smoothdeveloper / SimpleUnionCaseInfoReflection.fs
Created February 11, 2015 23:05
F# simple UnionCase info reflection helper
open Microsoft.FSharp.Reflection
module SimpleUnionCaseInfoReflection =
// will crash if 'T contains members which aren't only tags
let Construct<'T> (caseInfo: UnionCaseInfo) = FSharpValue.MakeUnion(caseInfo, [||]) :?> 'T
let GetUnionCaseInfoAndInstance<'T> (caseInfo: UnionCaseInfo) = (caseInfo, Construct<'T> caseInfo)
let AllCases<'T> =
@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 / 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 / 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 }