Skip to content

Instantly share code, notes, and snippets.

@ritalin
ritalin / HomebrewAdminTest.rb
Created October 4, 2011 14:22
Homwbrew on the web
require 'rubygems'
require 'sinatra'
require "stringio"
$LOAD_PATH.push "/usr/local/Library/Homebrew"
require "global"
require "cmd/list"
@ritalin
ritalin / fizzbuzz.fsx
Created November 20, 2011 08:10
Fizzbuzz By Computation Expression
// builder
let fb_return = fun v ->
match v with
| (x, "") -> x.ToString()
| (_, s) -> s
type FizzBuzzBuilder() =
member this.Return v = fb_return v
let fizzbuzz = FizzBuzzBuilder()
@ritalin
ritalin / TraitExt.php
Created December 5, 2011 15:24
Object Instance-time Trait Application.
<?php
use Symfony\Component\ClassLoader\UniversalClassLoader;
class TraitExt {
public static $clsLoader;
public static function withTraits($class, array $traits) {
$cache = self::classLoader()->getNamespaceFallbacks();
if (empty($cache)) {
self::registerCacheDir($_SERVER["TMPDIR"] . DIRECTORY_SEPARATOR . "trait_ext_cache");
@ritalin
ritalin / Program.cs
Created February 14, 2012 17:01
Rx test for mono
private static void TestStart() {
var disposer = Observable
.Start(() => {
System.Threading.Thread.Sleep(3000);
return 110;
})
.Subscribe(
i => Console.WriteLine(string.Format("OnNext: {0}", i)),
() => Console.WriteLine("Completed TestStart")
@ritalin
ritalin / Program.cs
Created February 15, 2012 18:21
Delay Test on Reactive mono
// Mono JIT compiler version 2.10.6 (tarball Fri Sep 16 00:13:06 EDT 2011)
// Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
// TLS: normal
// SIGSEGV: normal
// Notification: kqueue
// Architecture: x86
// Disabled: none
// Misc: debugger softdebug
// LLVM: yes(2.9svn-mono)
// GC: Included Boehm (with typed GC)
@ritalin
ritalin / BlankPage.xaml
Created March 26, 2012 04:02 — forked from anonymous/BlankPage.xaml
For metro style app, unable to use attachable property defined by other assembly.
<!--
<Page
x:Class="APTest.App.BlankPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:APTest.App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:fw="clr-namespace:AP.Framework;assembly=AP.Framework"
@ritalin
ritalin / LimittedStringExtensions.cs
Created April 6, 2012 08:04
Limitted String for .NET
namespace Sample {
public static class LimittedStringExtensions {
public string LimmitedString(this string inSelf, int inMaxLen) {
if (inSelf.Length > inMaxLen) {
throw new Exception("長すぎwwwワロタwww");
}
return inSelf;
}
}
@ritalin
ritalin / dupstr.fs
Created April 10, 2012 16:10
Maximum Duplication String Problem for F#
//
// Maximum Duplication String Problem for F#
//
let dupstr s =
// generate suffix list
let tails (s:string) =
let rec tailsimpl (s:string) i list =
match i with
| -1 -> list
@ritalin
ritalin / PropertyCategoryMapper.cs
Created April 19, 2012 04:04 — forked from anonymous/PropertyTagMapper.cs
A helper class to extract property-names of ViewModel for MVVM.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Samples {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class PropertyCategoryAttribute : System.Attribute {
public PropertyCategoryAttribute(Type inTagType) {
this.Tag = inTagType;
@ritalin
ritalin / gist:2425645
Created April 20, 2012 03:18
A Helper method converting AggregateException to the internal exception for NUnit
// In CUI test runner, to use await syntax at the test code is involved skipping test.
// So It nessesary to wait using Task#Wait() method.
// In Assert#Throws method for NUnit, threfore, expected exception is not thrown but AggregateException.
// Following method is conversion AggregateException to the internal exception.
private TestDelegate ResolveAggregateException(Action inTestAction) {
return () => {
try {
inTestAction();
}
catch (AggregateException ex) {