Skip to content

Instantly share code, notes, and snippets.

View komamitsu's full-sized avatar

Mitsunori Komatsu komamitsu

View GitHub Profile
@komamitsu
komamitsu / HOge.scala
Created May 13, 2012 13:53
Trait as Stackable modifications
// Either is OK.
// abstract Base { def say(word: String) }
trait Base { def say(word: String) }
class Hoge extends Base { def say(word: String) = println(word) }
trait Smile extends Base { abstract override def say(word: String) = super.say(word + " :)") }
trait Hello extends Base { abstract override def say(word: String) = super.say("Hello " + word) }
@komamitsu
komamitsu / perm.ml
Created May 23, 2012 16:44
2 permutations in OCaml
let ($) f g = f g
let rec perm xs n l total =
if n <= 0 then l::total
else begin
List.flatten $
List.map (fun c -> perm xs (n - 1) (c::l) total) xs
end
let rec perm2 xs n =
@komamitsu
komamitsu / A.scala
Created June 2, 2012 09:54
[Scala] hashCode impl test
package com.komamitsu.hashcodetest
/**
* @author komamitsu
*/
case class Foo(id: Int)
case class Bar(id: Int)
class Hoge(foo: Foo, bar: Bar) {
override def hashCode : Int = foo.## + bar.##
}
#include <stdio.h>
#include <string.h>
static void p(int xs[], int s, int e) {
int i;
printf("[");
for (i = s; i <= e; i++) {
printf("%d ", xs[i]);
}
class BmStringSearch
def initialize(target)
@target = target
@skip = {}
i = target.size - 1
target.each_char do |x|
@skip[x] = i
i -= 1
end
end
def sort(xs, st, en)
pivot = xs[st]
s, e = st + 1, en
loop do
while (s <= en && xs[s] < pivot)
s += 1
end
while (e > st && pivot < xs[e])
let pickout xs index =
let (_, opt, rest) =
List.fold_left
(fun (i, opt, rest) x ->
if i = index then (i + 1, Some x, rest)
else (i + 1, opt, x::rest)) (0, None, []) xs
in
match opt with
| None -> failwith "not found"
| Some x -> (x, rest)
void bench() {
StringBuilder buf = new StringBuilder();
for (int i = 0; i<100000; i++)
buf.append("0123456789あいうえおaiueo");
String s = buf.toString();
byte[] bytes = s.getBytes();
char[] chars = s.toCharArray();
long start = 0;
<?xml version="1.0"?>
<root>
<item>
<name>Komamitsu's setting</name>
<identifier>private.komamitsu</identifier>
<autogen>__KeyToKey__ KeyCode::COMMAND_R, KeyCode::VK_JIS_TOGGLE_EISUU_KANA</autogen>
<autogen>__KeyToKey__ KeyCode::JIS_EISUU, KeyCode::CONTROL_L</autogen>
<autogen>__KeyToKey__ KeyCode::JIS_KANA, KeyCode::ESCAPE</autogen>
</item>
</root>
@komamitsu
komamitsu / User.h
Created April 19, 2013 09:55
Objective-C small sample codes
#import "Foundation/Foundation.h"
@interface User : NSObject
- (NSString*)hello:(NSString*)msg;
@property(copy) NSString *name;
@property int age;
@end