Skip to content

Instantly share code, notes, and snippets.

View takahashilabo's full-sized avatar

Keiichi Takahashi takahashilabo

View GitHub Profile
@takahashilabo
takahashilabo / gist:4367170
Created December 24, 2012 02:26
長さ制限つきのQueue
#長さ制限つきのQueue
class Q
attr_accessor :q
def initialize(size)
@q = []
@size = size
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: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 / 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 / findNoTextPdf.sh
Last active August 29, 2015 14:02
This shell script file for finding the pdf files which probably include no OCRed text.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: findNoTextPdf.sh path"
exit 1
fi
find $1 -type f -name "*.pdf" | while read myfile
do
pdftotext -l 1 "$myfile" tmp
status=`hexdump -ve '1/1 "%.2x"' tmp | head -c 2`
/*
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
@takahashilabo
takahashilabo / outlietext.pde
Created April 30, 2016 02:30
drawOutlineText method for Processing
void setup() {
size(800,400);
}
void draw() {
background(0, 255, 255);
float y = 0;
for (int i = 1; i <= 5; i++) {
y += 24 * (i - 1);
drawOutlineText("Hello, Processing World!", 0, y, 24 * i, color(255), color(0));
@takahashilabo
takahashilabo / drawArrow.pde
Last active December 27, 2017 13:23
draw an arrow method for Processing
void setup() {
size(400, 400);
stroke(255);
noLoop();
}
void draw() {
background(255);
stroke(255, 0, 0);
fill(255, 0, 0);
@takahashilabo
takahashilabo / consecutive_line_counter.rb
Created June 17, 2017 04:39
This code counts consecutive lines in standard input
cnt = 1
prev_s = ""
while s = gets do
s.chomp!
if prev_s == "" then
prev_s = s
next
end
@takahashilabo
takahashilabo / consecutive_line_counter2.rb
Created June 17, 2017 22:42
This code counts consecutive lines in standard input
data = []
while s = gets
data << s.chomp
end
tmp = {}
data.each do |item|
if tmp.has_key?(item) then
tmp[item] << item
else