Skip to content

Instantly share code, notes, and snippets.

@yukitos
yukitos / gist:10523927
Last active August 29, 2015 13:59
MSBuild snippet to build TypeScript sourcemap files in F# MVC 5 project.
<PropertyGroup>
<!-- snip -->
<TypeScriptToolsVersion>1.0</TypeScriptToolsVersion>
</PropertyGroup>
<Target Name="BeforeBuild">
<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="&lt;dependentAssembly&gt;([\s]+.)&lt;assemblyIdentity name=&quot;FSharp\.Core&quot; publicKeyToken=&quot;b03f5f7f11d50a3a&quot; culture=&quot;neutral&quot; \/&gt;([\s\S]+?)&lt;\/dependentAssembly&gt;" RegexOptionList="IgnoreCase|Singleline" Replacement="&lt;dependentAssembly&gt;&#xD;&#xA; &lt;assemblyIdentity name=&quot;FSharp.Core&quot; publicKeyToken=&quot;b03f5f7f11d50a3a&quot; culture=&quot;neutral&quot; /&gt;&#xD;&#xA; &lt;bindingRedirect oldVersion=&quot;0.0.0.0-$(TargetFSharpCoreVersion)&quot; newVersion=&quot;$(TargetFSharpCoreVersion)&quot;/&gt;&#xD;&#xA; &lt;/dependentAssembly&gt;" Files="web.config" />
<ItemGroup>
<TSFiles Include="@(None);@(TypeScriptCompile)" Condition=" '%(Extension)' == '.ts' " />
</ItemGroup>
<Exec Command="&quot;$(PROGRAMFI
@yukitos
yukitos / gist:f6dfccf18b087860da4a
Last active August 29, 2015 14:01
Make seven, times and five functions where seven(times(five())) == 35.
function makeNum(n, f) {
if (f == null) { return n; }
else { return f(n); }
}
function five(f) {
return makeNum(5, f);
}
function seven(f) {
return makeNum(7, f);
}
@yukitos
yukitos / gist:2f58bef03887d2cf4ac0
Last active August 29, 2015 14:02
Use Event.filter and receive event's sender object
open System.Windows.Forms
// Copied from: http://social.msdn.microsoft.com/Forums/ja-JP/d5f23c87-b8d5-4c95-9293-3239f70caf94/f-first-class-events-and-cli-standards?forum=fsharpgeneral
type FunctionWrapper<'args>(f:obj -> 'args -> unit) =
member x.Invoke(sender:obj, args) =
f sender args
module Event =
let filter (pred:'args->bool) (ev:IEvent<'del,'args>) =
@yukitos
yukitos / gist:b75971276c1e17ad9ab6
Last active August 29, 2015 14:02
Derived attribute type lost base type's attributes in F#
open System
open System.Reflection
[<AttributeUsage(AttributeTargets.All, AllowMultiple = true)>]
type MyAttribute() =
inherit Attribute()
// MyAttributeを継承しているのでAllowMultipleがtrueになっているはず。。。
type MyDerivedAttribute() =
inherit MyAttribute()
@yukitos
yukitos / gist:fb9bcb2a090ee51d8fcb
Last active August 29, 2015 14:02
Get ProductCode value from a specific msi file.
var msi = new ActiveXObject("WindowsInstaller.Installer");
var msiOpenDatabaseModeReadOnly = 0;
var db = msi.OpenDatabase("test.msi", msiOpenDatabaseModeReadOnly);
var view = db.OpenView("SELECT * FROM Property WHERE Property = 'ProductCode'");
view.Execute();
for (var r = view.Fetch(); r != null; r = view.Fetch()) {
WScript.Echo(r.StringData(1) + "=" + r.StringData(2));
}
view.Close();
@yukitos
yukitos / gist:7e417f082b083c0fea72
Created June 25, 2014 06:42
Set GridViewColumn's text color red if binding 'Result' property equals 'Error'.
<!-- (snip) -->
<GridViewColumn Header="Result" DisplayMemberBinding="{Binding Result}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
@yukitos
yukitos / gist:b1d0c01c449455926f6e
Created July 17, 2014 10:13
Easy Datetime.Min/Max implementation.
internal static class DateTimeUtil
{
public static DateTime Min(params DateTime[] values)
{
if (values == null)
throw new ArgumentNullException("values");
var comparer = new DateTimeComparer();
Array.Sort<DateTime>(values, comparer);
return values[0];
let values = [ 1;2;3;2;3;1 ]
let f y x =
if x = y then Choice2Of2 1
else if x < y then Choice1Of2 2
else Choice2Of2 3
let ``all values are Choice1Of2`` =
values
|> List.map (f 4)
let sequence1 =
@yukitos
yukitos / gist:4db499ede35c8ad82863
Last active August 29, 2015 14:05
FsCheck function to generate Japanese characters.
namespace FsCheck.Ext
module Test =
open System
open FsCheck
open FsCheck.Arb
type JapaneseChar = char
let japaneseChar (s: string) : JapaneseChar =
### Keybase proof
I hereby claim:
* I am yukitos on github.
* I am yukitos (https://keybase.io/yukitos) on keybase.
* I have a public key whose fingerprint is 2257 CD30 012D 6739 B948 271A 6BBD 7DCE 7766 C7DE
To claim this, I am signing this object: