Skip to content

Instantly share code, notes, and snippets.

@kencoba
kencoba / sec_to_hms.rb
Created June 14, 2017 08:29
convert interval into hms format.
interval = gets.to_i
sec = interval % 60
hour = interval / (60 * 60)
min = (interval - (hour * 60 * 60)) / 60
printf("%02d:%02d:%02d", hour, min, sec)
@kencoba
kencoba / MarkerList.sh
Last active June 15, 2017 01:34
List up chapter markers.
#!/usr/bin/env zsh
for difffile in *.txt
do
hms=`sort -n $difffile | awk 'BEGIN{threshold = 1000} $1 < threshold {print $2}' | sort -n | head -n 1 | ruby sec_to_hms.rb`
if [[ $hms == "00:00:00" ]] then
hms=`sort -n $difffile | awk '{print $2}' | head -n 1 | ruby sec_to_hms.rb`
fi
echo "$hms ${difffile}"
done
@kencoba
kencoba / MakeDiffs.sh
Created June 14, 2017 08:27
make difference data.
#!/usr/bin/env zsh
if [ $# -ne 2 ]; then
echo "$# args specified" 1>&2
echo "usage: sh ./makeDiffs.sh marker_directory target_directory" 1>&2
echo "caution! : the subdirectories of target_directory must be same the marker_directory's subdirectories."
exit 1
fi
for marker in $1/**/*.png
@kencoba
kencoba / diffs.sh
Last active July 11, 2017 02:04
compute diffs for each png files in the directory.
#!/usr/bin/env zsh
if [ $# -ne 2 ]; then
echo "$# args specified" 1>&2
echo "usage: sh ./diffs.sh marker_filename target_directory" 1>&2
exit 1
fi
for target in $2/*.png
do
@kencoba
kencoba / mp42png.sh
Last active June 14, 2017 08:26
create thresholded images from mp4 file.
#!/usr/bin/env zsh
if [ $# -ne 2 ]; then
echo "$# args specified" 1>&2
echo "usage: sh ./mp42png.sh mp4_filename output_directory" 1>&2
exit 1
fi
( mkdir -p $2 && rm -rf $2 && ffmpeg -i $1 -r 1 -vcodec png $2/%05d.png && mogrify -threshold 50% $2/*.png )
@kencoba
kencoba / index.html
Last active June 8, 2017 01:36
Video with Chapter Marker button.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.button {
width: 40%;
text-align: left;
}
</style>
@kencoba
kencoba / .vimrc
Last active June 5, 2017 00:32
This is the current setting. sudo apt-get install vim-gnome.
" vimrc に以下のように追記
" プラグインが実際にインストールされるディレクトリ
let s:dein_dir = expand('~/.cache/dein')
" dein.vim 本体
let s:dein_repo_dir = s:dein_dir . '/repos/github.com/Shougo/dein.vim'
" dein.vim がなければ github から落としてくる
if &runtimepath !~# '/dein.vim'
if !isdirectory(s:dein_repo_dir)
@kencoba
kencoba / WhyWeNeedCommentOnSourceCode.md
Last active June 2, 2017 06:19
Why we need comment on source code?

This is a good example. Fall-through works when we don't write anything. Without comment, reader can't see whether this code is correct or mistake.

飯尾淳「C言語によるスーパーLinuxプログラミング」、ソフトバンククリエイティブ、2011、p.112 Column10 フォールスルー ... ただし、フォールスルーの活用は1点、注意が必要です。 フォールスルーとして意図的にbreak文を省略したのか、プログラマーのミスでbreak文が省略されているのか、 プログラムのロジックから区別することができません。 したがってフォールスルーを使う場合には、コメントでそれがわかるように書いておくべきでしょう。

@kencoba
kencoba / index.html
Created June 2, 2017 03:54
video tag sample.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.button {
width: 40%;
text-align: left;
}
</style>
@kencoba
kencoba / duration.rb
Created June 1, 2017 09:59
Listing duration of mp4s.
#! /bin/sh
exec ruby -S -x "$0" "$@"
#! ruby
def h_mm_ss(sec)
min, ss = sec.to_i.divmod(60)
hh , mm = min.divmod(60)
"%dh%02dm%02ds" % [hh, mm, ss]
end