Skip to content

Instantly share code, notes, and snippets.

Avatar

Katsunori KAWAGUCHI hamakn

View GitHub Profile
@hamakn
hamakn / hoge.rb
Created Feb 11, 2014
DBがあるときはAR::Baseを継承したクラスのインスタンス、ないときは適当なStructのインスタンスが欲しい
View hoge.rb
require "activerecord"
require "ostruct"
class Hoge < ActiveRecord::Base
end
class Factory
attr_accessor :klass
def initialize
View hoge.rb
module Hena
module Ord17Scheherazade
# 17301, 100 => [1, 73, 1]
def self.hoge(i, base)
fail if i < 0
result = []
while i > 0
View gist:265198d37cb6aa7196f0
ANSWERS = [
["YokoHamarb", "acdfp"],
["Ruby", "twx"],
["ruby", "nst"],
["PHP", "gkluv"],
["a", "bfg"],
["b", "acfgh"],
["m", "ghilnqrs"],
["mg", "bcdhilmq"],
["Mg", "fhiklmpq"],
@hamakn
hamakn / color_space_histgram.rb
Created Oct 17, 2014
color space histgram of jpeg files
View color_space_histgram.rb
require "rmagick"
color_space_histgram = {}
files = Dir.glob(File.join(ARGV[0], "*.jpg"))
files.each do |file|
image = Magick::Image.read file
color_space_histgram[image.first.colorspace.to_s] ||= 0
color_space_histgram[image.first.colorspace.to_s] += 1
end
@hamakn
hamakn / hoge.java
Created Feb 11, 2015
return multiple values using android.util.Pair
View hoge.java
private Pair<String, String> testMethod() {
Pair<String, String> p = new Pair<String, String>("hoge", "fuga");
return p;
}
View wavedash.pl
use strict;
use warnings;
use utf8;
use Encode;
# 波ダッシュ
my $wavedash = chr(hex "301c");
print encode_utf8($wavedash) . "\n";
# => "〜"
@hamakn
hamakn / hoge.rb
Last active Aug 29, 2015
array << hoge || default
View hoge.rb
require "pp"
require "ripper"
pp Ripper.sexp("arr << nil || 1")
# =>
# [:program,
# [[:binary,
# [:binary,
# [:vcall, [:@ident, "arr", [1, 0]]],
# :<<,
@hamakn
hamakn / width.java
Created Apr 20, 2015
DisplayMetrics#widthPixels の値が機種とデバイスの向きによって変わる
View width.java
# screen orientationは固定
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
Log.d("metrics.widthPixels: " + metrics.widthPixels);
# SONY SO-02g Android 4.4.4
# => デバイスが縦向きでも横向きでも metrics.widthPixels の値は同じ
View hoge.pl
use Digest::SHA2;
use Data::Dumper;
my $sha2obj = new Digest::SHA2 256;
$sha2obj->add('hoge' . 'salt');
print Dumper $sha2obj->hexdigest();
# => "2da48de22c3db5903832dc17521ec800d213a59855351bd69ff1f453f0555f01"
@hamakn
hamakn / result1.txt
Created Aug 13, 2015
OCR(tesseract)
View result1.txt
奮ーg一A
D繍Sc0uク7奮 F。。d5
願 収 証
` 〈杢ネ土お客様ィ系亡J TEL- 。ー2。・ーー83婁ー
)工円丿ーーゴヒ丿」丶岩店 囗3・5693~ー83d 丿
ビ`ソグ ' エーtま、 安全と鮮度の
良さとイ面才各の安さて~お客様の健康
生云舌と家言十を応援し丶たします。