Skip to content

Instantly share code, notes, and snippets.

View smoothdeveloper's full-sized avatar

Gauthier Segay smoothdeveloper

View GitHub Profile
@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 / 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 / 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 / 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 / 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: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
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
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
// thing that hold state
public interface ISwitchableBehaviourState<TThingToAlter>
{
void RegisterThingToAlterWithReversibleAction(TThingToAlter thingToAlter, Func<TThingToAlter, Action<TThingToAlter>> reversibleAction);
}
// thing that will be manipulated