Skip to content

Instantly share code, notes, and snippets.

View posaunehm's full-sized avatar

Hiroshi Maekawa (a.k.a. Posaune) posaunehm

View GitHub Profile
@posaunehm
posaunehm / gist:4223213
Created December 6, 2012 09:24
Convert file charset using nkf
for file in *.txt; do nkf -w $file > tmp; mv -f tmp $file ;done
@posaunehm
posaunehm / なんとか頑張るテスト.fs
Created December 7, 2012 14:26
for F# advent calender 2012
// C#のオブジェクトを作る
let sut () =
let vm = new VendingMachine(new StandardMoneyAcceptor())
vm.SetDrinkSpecification([new PriceSpecification("Cola",110); new PriceSpecification("Soda",150)])
vm
// 受け取ったオブジェクトに操作を行い、操作後のオブジェクトを返却する。
let insert_money amount (vm:VendingMachine) =
printMethod amount
amount |> List.iter vm.InsertMoney
@posaunehm
posaunehm / gist:4233749
Created December 7, 2012 14:57
半分くらいヘルパメソッドになっているNaturalSpecコード。
let initially vm =
printMethod ()
vm
let total_amount amount (vm:VendingMachine) =
printMethod amount
vm.TotalAmount = amount
let insert_money amount (vm:VendingMachine) =
printMethod amount
@posaunehm
posaunehm / IrofPF.xaml
Created December 9, 2012 14:44
irof-san implemented WPF.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
x:Class="IroPf.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<Storyboard x:Key="speaking" AutoReverse="True" RepeatBehavior="Forever">
@posaunehm
posaunehm / gist:4661427
Last active December 11, 2015 21:18
Show winform dialog with timeout (as extension method) Maybe useful for test code (ex: UI smoke test)
public static void ShowDialog(this Form dlg, int timeout)
{
dlg.Shown += (sender, args) => Task.Factory.StartNew(
() => Thread.Sleep(timeout)).ContinueWith(
_ => dlg.Close(),TaskScheduler.FromCurrentSynchronizationContext());
dlg.ShowDialog();
}
@posaunehm
posaunehm / BitmapToBitmapSource.cs
Created February 3, 2013 10:08
An extension method to convert WinForm Bitmap to WPF BitmapSource
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public static BitmapSource ToWPFBitmap(this System.Drawing.Bitmap bitmap)
{
var hBitmap = bitmap.GetHbitmap();
BitmapSource source;
try
{
@posaunehm
posaunehm / WinFormBitmapConverter.cs
Created February 4, 2013 23:31
A value converter between bitmap and bitmapsource Inspired by http://www.codeproject.com/Articles/104929/Bitmap-to-BitmapSource and Matt's comment in the article.
public class WinFormBitmapConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var bitmap = value as Bitmap;
if (bitmap == null)
{
return null;
}
@posaunehm
posaunehm / BitmapToBitmapSourceExtention.cs
Created February 8, 2013 15:54
Typical implementation for conversion between winform Bitmap and WPF BitmapSource
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public static BitmapSource ToWPFBitmap(this System.Drawing.Bitmap bitmap)
{
var hBitmap = bitmap.GetHbitmap();
BitmapSource source;
try
{
@posaunehm
posaunehm / youroom_xauth.rb
Created February 24, 2013 16:19
get youroom timeline using xauth.
# -*- coding: utf-8 -*-
require 'rubygems'
require 'oauth'
require 'JSON'
user = 'user'
pass = 'pass'
key = 'consumer_key'
@posaunehm
posaunehm / youroom2string.rb
Last active December 14, 2015 07:19
youroom2string ruby script.name.rb userid pass roomID threadID
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'rubygems'
require 'oauth'
require "rexml/document"
class YouroomContent
def initialize (content, author, created_at, children)
@content = content