Skip to content

Instantly share code, notes, and snippets.

View takahashilabo's full-sized avatar

Keiichi Takahashi takahashilabo

View GitHub Profile
@takahashilabo
takahashilabo / abc.sh
Last active August 29, 2015 14:02
count the number of alphabets of a file
#!/bin/bash
while read -s -n 1 char
do
echo $char
done < $1 | sort | uniq | wc -l | awk '{print $1}'
@takahashilabo
takahashilabo / gist:5411365
Last active December 16, 2015 09:09
count the number of words in a string
class String
def count_the_number_of_words_in_a_string(word, pos = 0, num = 0)
pos = self.index(word, pos)
return num if pos == nil
count_the_number_of_words_in_a_string(word, pos + 1, num + 1)
end
end
@takahashilabo
takahashilabo / gist:5411358
Last active December 16, 2015 09:09
count the number of words in a string
class String
def count_the_number_of_words_in_a_string(word)
return self.split(/#{word}/).size - 1
end
end
@takahashilabo
takahashilabo / gist:4367170
Created December 24, 2012 02:26
長さ制限つきのQueue
#長さ制限つきのQueue
class Q
attr_accessor :q
def initialize(size)
@q = []
@size = size
end