Skip to content

Instantly share code, notes, and snippets.

View sayurin's full-sized avatar

Kurata Sayuri sayurin

  • Japan
  • 06:51 (UTC +09:00)
View GitHub Profile
#r "System.Drawing.dll"
#r "System.Windows.Forms.dll"
open System.Drawing
open System.Windows.Forms
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault false
let form = new Form(ClientSize = Size(284, 261), Text = "ダイアログジェネレーター")
let caption = new TextBox(Location = Point(13, 13), Size = Size(259, 19), Anchor = (AnchorStyles.Top ||| AnchorStyles.Left ||| AnchorStyles.Right))
let text = new TextBox(Location = Point(13, 39), Size = Size(259, 133), Anchor = (AnchorStyles.Top ||| AnchorStyles.Left ||| AnchorStyles.Right), Multiline = true)
let combo = new ComboBox(Location = Point(13, 181), Size = Size(121, 20), DropDownStyle = ComboBoxStyle.DropDownList, FormattingEnabled = true)
@sayurin
sayurin / merge.fsx
Created February 17, 2014 23:35
韓国ROの分割されたログイン背景を結合する
#r "System.Drawing.dll"
open System.Drawing
System.IO.Directory.EnumerateFiles "."
|> Seq.choose (fun path ->
let m = System.Text.RegularExpressions.Regex.Match(path, @"([^\\]+)(\d)-(\d)\.")
if not m.Success then None else
Some(m.Groups.[1].Value, int m.Groups.[3].Value, int m.Groups.[2].Value, new Bitmap(path)))
|> Seq.groupBy (fun (k, _, _, _) -> k)
|> Seq.iter (fun (k, seq) ->
let x, y = Seq.fold (fun (x0, y0) (_, x1, y1, _) -> (max x0 x1, max y0 y1)) (0, 0) seq
#nowarn "9"
open System.Runtime.InteropServices
[<Struct; StructLayout(LayoutKind.Explicit)>]
type s =
[<DefaultValue; FieldOffset 0>]
val mutable y : uint32
[<DefaultValue; FieldOffset 0>]
val mutable x1 : byte
@sayurin
sayurin / TextBox2.cs
Created March 4, 2014 05:12
WinFormsのTextBoxでfocusを失う時にIMEへの入力文字を確定させる
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Sayuri.Windows.Forms {
class TextBox2 : TextBox {
[DllImport("Imm32.dll")]
static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("Imm32.dll")]
static extern bool ImmGetOpenStatus(IntPtr hIMC);
open System.Text.RegularExpressions
let parse1 line =
// TODO: 先頭から解析できる範囲だけであり終端チェックはされていない
let matches = Regex.Matches(line, @"(?:^|\G,)(?<key>[^=,]+)=(?<val>[^=,]+)")
Array.init matches.Count (fun i -> matches.[i].Groups.["key"].Value, matches.[i].Groups.["val"].Value)
let parse2 line =
// TODO: 要素数0が認められない
let m = Regex.Match(line, "^(?<key1>[^=,]+)=(?<val1>[^=,]+)(?:,(?<key>[^=,]+)=(?<val>[^=,]+))*$")
#include <type_traits>
template<typename Interface>
struct vtable{
typedef typename std::remove_pointer_t<decltype(Interface::lpVtbl)> type;
};
template<typename Interface>
using vtable_t = typename Vtable<Interface>::type;
@sayurin
sayurin / SocketExtensions.fs
Last active August 29, 2015 14:12
Socket Extension Methods for F# async.
module Sayuri.Net.SocketExtensions
open System
open System.Net
open System.Net.Sockets
#if NET4
type private ConcurrentBag<'T> = System.Collections.Concurrent.ConcurrentBag<'T>
#else
type private ConcurrentBag<'T>() =
let bag = System.Collections.Generic.Stack<'T>()
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
using Sayuri.IO;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
using IDataObject = System.Runtime.InteropServices.ComTypes.IDataObject;
@sayurin
sayurin / POptiPNG.fs
Last active December 16, 2015 04:19
POptiPNG; Parallel OptiPNG, it invoke OptiPNG with parallel and manage processes.
open System
open System.Diagnostics
open System.IO
open System.Reflection
open System.Threading
let count = Environment.ProcessorCount
let optipng = "\"" + Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "optipng") + "\""
let prefix = "-silent -o5 "
let cmdLen = 32768 - 1(* \0 *) - String.length optipng - 1(* SP *) - String.length prefix
@sayurin
sayurin / Json.fs
Last active December 17, 2015 21:49
Json Serializer. this can serialize F# record type.
module Sayuri.Json
open Microsoft.FSharp.Reflection
open System
open System.Collections
open System.Collections.Generic
open System.IO
open System.Linq.Expressions
open System.Reflection
open System.Runtime.Serialization