Skip to content

Instantly share code, notes, and snippets.

View holysugar's full-sized avatar

HORII Keima holysugar

  • Aiming, Inc
  • Tokyo
View GitHub Profile
@holysugar
holysugar / assert_change.rb
Created March 17, 2015 10:12
assert_change 試作版
require 'test/unit/assertions'
module AssertChange
# fixme message?
def assert_change(value_proc, options = {}, &event_proc)
change = Change.new(value_proc)
change.perform(event_proc)
case
@holysugar
holysugar / before_after_all.rb
Last active August 29, 2015 14:17
Test::Unit で一度しか呼ばれない startup / shutdown その3 これでよかった…
require 'test/unit'
require 'active_support/all'
module BeforeAfterAll
extend ActiveSupport::Concern
included do
class << self
def beforeall(&block)
@_beforeall = block
@holysugar
holysugar / onlyonce.rb
Created March 10, 2015 09:32
Test::Unit で一度しか呼ばれない startup / shutdown その2, startuponce / shutdownonce 編
require 'test/unit'
require 'active_support/all'
module OnlyOnce
extend ActiveSupport::Concern
included do
def self.singleton_method_added(method_name)
if method_name == :startup || method_name == :shutdown
@holysugar
holysugar / onlyonce.rb
Last active August 29, 2015 14:16
Test::Unit で一度しか呼ばれない startup / shutdown (試作版)
require 'test/unit'
require 'active_support/all'
module OnlyOnce
extend ActiveSupport::Concern
included do
class << self
def inherited_with_onlyonce(sub)
inherited_without_onlyonce(sub)
@holysugar
holysugar / activesupport_testcase_inherits_test_unit_testcase.rb
Last active August 29, 2015 14:16
test-unit を rails 4.2 で使う
# Rails で test-unit を使う. 参考:
# * https://github.com/test-unit/test-unit-activesupport
# * https://github.com/rails/rails/blob/master/activesupport/lib/active_support/test_case.rb
#
require 'minitest'
def Minitest.autorun; end # remove Minitest at_exit process
require 'active_support/test_case'
require 'active_support/testing/tagged_logging'
require 'active_support/testing/assertions'
@holysugar
holysugar / daime.rb
Created February 18, 2015 06:39
x代目xx
require 'gimei'
def daime(max=99)
[*(2..max)].sample.to_s.tr('0123456789','〇一二三四五六七八九') + "代目"
end
def name
"#{daime}#{Gimei.first.kanji}"
end
@holysugar
holysugar / sslnotafter.sh
Created December 9, 2014 05:30
SSL証明書の期限を表示する
#!/bin/sh
HOST=$1
if [ -z "$HOST" ]; then
echo "$0 host [port]"
exit 1
fi
PORT=${2:-443}
openssl s_client -tls1 -connect $HOST:$PORT 2>&1 < /dev/null | openssl x509 -enddate | awk -F '=' '/^notAfter/{ print $2 }'
@holysugar
holysugar / two-kanji-noun.rb
Created November 13, 2014 04:57
2文字の漢字リスト生成(メモ)
File.open("x.txt",'w'){|f| f.puts File.read("SKK-JISYO.L", external_encoding: Encoding::EUC_JP).encode(Encoding::UTF_8).split(/\n+/).map{|x| x.scan(%r!/(\p{Han}{2})(?=[;/])!).flatten.first if x !~ /[a-z]/ }.compact.flatten.sort.uniq }
@holysugar
holysugar / ngircd.patch
Created October 16, 2014 09:56
ngircd patch for POODLE
--- conn-ssl.c.orig 2014-10-16 09:37:47.303936573 +0000
+++ conn-ssl.c 2014-10-16 09:38:31.513421919 +0000
@@ -296,7 +296,7 @@
return false;
}
- newctx = SSL_CTX_new(SSLv23_method());
+ newctx = SSL_CTX_new(TLSv1_method());
if (!newctx) {
LogOpenSSLError("Failed to create SSL context", NULL);
@holysugar
holysugar / benchmark_struct.rb
Created July 23, 2014 04:31
benchmark structs. Struct が速いのは当たり前なので ostruct と hashie の比較がメイン
#!/usr/bin/env ruby
require 'benchmark'
require 'ostruct'
require 'hashie'
n = 1000000
O = Struct.new(:foo, :bar, :baz)
puts "Benchmark: Initialize"