Skip to content

Instantly share code, notes, and snippets.

View smoothdeveloper's full-sized avatar

Gauthier Segay smoothdeveloper

View GitHub Profile
@smoothdeveloper
smoothdeveloper / gist:0c5c0f6bbdad8b3b18af
Last active August 29, 2015 13:56
Npgsql datatable serializer
private void serializeDataTable(NpgsqlCopySerializer serializer, DataTable datatable, string[] columnNamesInFixedOrder)
{
var serializeRow = new List<Action<DataRow>>();
var serializeByType = new Dictionary<Type, Action<object>>();
serializeByType[typeof (bool)] = (o => { if (o == null) serializer.AddNull(); else serializer.AddBool((bool)o); });
serializeByType[typeof (string)] = (o => { if (o == null) serializer.AddNull(); else serializer.AddString((string)o); });
serializeByType[typeof (DateTime)] = (o => { if (o == null) serializer.AddNull(); else serializer.AddDateTime((DateTime)o); });
serializeByType[typeof(byte)] = (o => { if (o == null) serializer.AddNull(); else serializer.AddInt32((byte)o); });
serializeByType[typeof (int)] = (o => { if (o == null) serializer.AddNull(); else serializer.AddInt32((int)o); });
@smoothdeveloper
smoothdeveloper / gist:9357bfb8260dea1cf2a0
Created November 4, 2014 18:07
Winforms / Cursor position in control
static Point Negate(this Point point)
{
return new Point(-point.X, -point.Y);
}
static Point CursorPositionWithinControl(this Control control)
{
var cursorPosition = Cursor.Position;
var offset = control.PointToScreen(Point.Empty);
cursorPosition.Offset(offset.Negate());
@smoothdeveloper
smoothdeveloper / LatchedActionsQueue.cs
Last active August 29, 2015 14:10
LatchedActionsQueue.cs
public class LatchedActionsQueue {
private List<KeyValuePair<object, Action>> actionsQueue = new List<KeyValuePair<object, Action>>();
public void Enlist(Action action) {
enlist(action, action);
}
public void Enlist<T1>(Action<T1> action, T1 p1) {
enlist(action, () => action(p1));
@smoothdeveloper
smoothdeveloper / extract_all_bitmap_resources_from_all_assemblies_in_folder.fsx
Last active August 29, 2015 14:15
Extract all bitmap resources from all assemblies in folder
// annoyed with resources embedded in resources in assemblies?
// extract all images from all assemblies in a folder
// see call commented at the end
#r "System.Drawing"
#r "System.Windows.Forms"
open System.Collections
open System.Drawing
open System.Linq
open System.IO
open System.Resources
@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 -> ""
// thing that hold state
public interface ISwitchableBehaviourState<TThingToAlter>
{
void RegisterThingToAlterWithReversibleAction(TThingToAlter thingToAlter, Func<TThingToAlter, Action<TThingToAlter>> reversibleAction);
}
// thing that will be manipulated
module Main where
-- http://www.f13g.com/%A5%D7%A5%ED%A5%B0%A5%E9%A5%DF%A5%F3%A5%B0/Haskell/GLUT/#content_1_7
import System.Random
import Graphics.Gloss
import Graphics.Gloss.Interface.Pure.Simulate
data Particle
= Particle { position :: Point
module Main where
import Data.Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Text.Encoding (decodeUtf8)
import Text.Blaze.Html (Html, preEscapedToHtml)
lazyToStrictBS :: LBS.ByteString -> BS.ByteString
lazyToStrictBS x = BS.concat $ LBS.toChunks x
@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"
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 }