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 / StringPerfomance.cs
Last active December 15, 2015 10:29
A sample program for string performance measurement
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace StringPerfomanceTest
{
internal class Program
{
@posaunehm
posaunehm / GetDefault.cs
Created March 25, 2013 01:48
Type型を受け取ってそれのデフォルト値を返す。結局Activator.CreateInstanceかよ、というのがはあるけれど。 参照:http://stackoverflow.com/questions/325426/programmatic-equivalent-of-defaulttype
public static object GetDefault(Type type)
{
if(type.IsValueType)
{
return Activator.CreateInstance(type);
}
return null;
}
@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
@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 / 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 / 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 / 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 / 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 / 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">