This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// thing that hold state | |
public interface ISwitchableBehaviourState<TThingToAlter> | |
{ | |
void RegisterThingToAlterWithReversibleAction(TThingToAlter thingToAlter, Func<TThingToAlter, Action<TThingToAlter>> reversibleAction); | |
} | |
// thing that will be manipulated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 -> "" |
OlderNewer