Skip to content

Instantly share code, notes, and snippets.

select
count(*)
from
special_topic_company
inner join
special_topic on special_topic.id = special_topic_company.special_topic_id
where
special_topic_company.company_root_id is null
and
special_topic_company.name
public List<String> convertInputStreamToString(InputStream is) {
List<String> ret = Collections.emptyList();
try {
ret = IOUtils.readLines(is);
} catch (IOException e) {
e.printStackTrace();
}
return ret;
}
def levenshtein_distance(s, t)
t.chars.with_index.inject(0..s.size) do |r, (a, z)|
z += 1
[z] + s.chars.zip(r.each_cons(2)).map do |b, (x, y)|
z = [y + 1, z + 1, x + (a == b ? 0 : 1)].min
end
end.last
end
@yoppi
yoppi / update.rb
Created August 2, 2011 09:57 — forked from troter/update
update any repositories.
#!/usr/bin/env ruby
# -*- coding:utf-8 -*-
require 'pathname'
module VCSCommand
@@vcs_update_table = {
'.git' => 'git pull',
'.hg' => 'hg pull -u',
'.svn' => 'svn up',
@yoppi
yoppi / enum.rb
Created August 10, 2011 14:38
Java/C# like Valued Enum implementation in Ruby
# coding: utf-8
module Enum
def initialize(key, no, value)
@key = key
@no = no
@value = value
end
attr_reader :key, :no, :value
@yoppi
yoppi / jp
Created September 3, 2011 14:02
句読点を切り替えるコマンド(shell script version)
#!/usr/bin/env sh
# https://gist.github.com/1191177 in Ruby origin.
while read input
do
if [[ $input =~ (、|。) ]]; then
echo $input | sed -e s/、/,/g | sed -e s/。/./g
else
echo $input | sed -e s/,/、/g | sed -e s/./。/g
fi
@yoppi
yoppi / spy.rb
Created October 4, 2011 02:37
Test Spy with ruby
def some_action
#...
do_logging(object)
#...
end
def do_logging
@logger.info("test")
end
@yoppi
yoppi / a.pl
Created October 4, 2011 08:26
my %t;
while (<>) {
my ($key, $value) = split;
if (not $t{$key}) {
$t{$key} = ();
}
push @{$t{$key}}, $value;
}
foreach $key (keys %t) {
print "$key \n";
@yoppi
yoppi / convert.sh
Created October 5, 2011 05:58
Sjis text to rst
ls -ltr | awk '{print $9}' | while read meeting
do
echo $meeting | xargs nkf -w -Lu > ${meeting%.txt}.rst
done
@yoppi
yoppi / jyanken.rb
Created November 2, 2011 04:12
Janken!
rock=->_{_=="scissors"};scissors=->_{_=="paper"};paper=->_{_=="rock"};->a,b{if a==b;puts"Draw.";elsif eval(a).call(b);puts"Left win.";else puts"Right win.";end}.call(*ARGV)