Skip to content

Instantly share code, notes, and snippets.

View sayurin's full-sized avatar

Kurata Sayuri sayurin

  • Japan
  • 13:11 (UTC +09:00)
View GitHub Profile
@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
@sayurin
sayurin / GifDumper.fs
Created August 9, 2013 23:23
とりあえずGIFの情報をダンプするだけ。 情報の整合性はチェックしてません。 Extensionsは最低限しか実装してないからまだ不足がある。
open System
open System.IO
let dumpGif (bytes : byte[]) =
let i = ref 0
let byte () =
let byte = bytes.[!i]
incr i
int byte
let uint16 () =
@sayurin
sayurin / JsonSerializer.fs
Last active December 21, 2015 18:39
型安全?なJsonパーサ
module Sayuri.JsonSerializer
open System
open System.Collections.Generic
open System.Globalization
open System.Text
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
type JsonType =
| JsonNull
| JsonBoolean of bool
@sayurin
sayurin / CsPoh.cs
Last active December 30, 2015 11:18
ブログ記事 http://sayurin.blogspot.com/2013/12/c.html 新人女子プログラマの書いたコードを直すだけの簡単なお仕事です!|paizaオンラインハッカソンVol.1 https://paiza.jp/poh/ec-campaign
using System;
using System.Runtime.InteropServices;
static class CsPoh {
static int Calculate(byte[] buffer, byte[] prices) {
int ii = 0, oi = 0, temp;
var itemCount = 0;
while ((temp = buffer[ii++] - '0') >= 0)
itemCount = itemCount * 10 + temp;
@sayurin
sayurin / gist:7836635
Created December 7, 2013 02:38
あんまり速くなかった…
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ output extension=".cs" #>
using System.Reflection;
class UnsafePoh {
static readonly byte[] bytes = new byte[]{
<#= string.Join(Environment.NewLine, File.ReadAllBytes(Host.ResolvePath("Unsafe.dll")).Select((b, i) => new { b, i }).GroupBy(a => a.i / 16, a => string.Format("0x{0:X2}, ", a.b), (_, g) => string.Concat(g))) #>
#ifdef _MSC_VER
#define IO_H "io.h"
#define _CRT_NONSTDC_NO_WARNINGS
#define __attribute__(X)
#else
#define IO_H "unistd.h"
#define __pragma(X)
#define __declspec(X)
#define __fastcall
#endif
namespace Sayuri
open System
open System.Net
open System.Security.Cryptography
open System.Text
type ParameterType =
| ProtocolString of string
| QueryString of string
| BodyString of string
#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