Skip to content

Instantly share code, notes, and snippets.

@hyoshida
hyoshida / install-patched-ruby-1.8.7-p375.sh
Last active August 3, 2017 04:05
patch for ruby-build error
# patch for make ruby error
# % rbenv install 1.8.7-p375
# ...
# ossl_pkey_ec.c:815: error: ‘EC_GROUP_new_curve_GF2m’ undeclared (first use in this function)
# ossl_pkey_ec.c:815: error: (Each undeclared identifier is reported only once
# ossl_pkey_ec.c:815: error: for each function it appears in.)
# make[1]: *** [ossl_pkey_ec.o] error 1
# ...
#
# refs: http://forums.cpanel.net/f5/case-84173-error-installing-ruby-377831.html
def associations_for_includes(recursive: true, except: nil, _breadcrumb: [])
_breadcrumb << self.class_name
self.reflect_on_all_associations.map do |association_reflection|
association_name = association_reflection.name
class_name = association_reflection.class_name
next if _breadcrumb.include?(class_name)
next if association_reflection.options.has_key?(:polymorphic)
case except
@hyoshida
hyoshida / code_hunter.rake
Last active August 29, 2015 14:01
code_hunter を実行し、改善事項がある場合は終了ステータスに 1 を返す
# code_hunter: https://github.com/r7kamura/code_hunter
task :code_hunter do
report_yaml = `code_hunter --application-path=#{Rails.root}`
successed_flag = YAML.load(report_yaml).empty?
puts "\e[31m#{report_yaml}\e[0m" unless successed_flag
exit successed_flag
end
@hyoshida
hyoshida / notes.rake
Last active August 29, 2015 14:02
notesタスクの対象にHACKとXXXを加える
# refs http://crypt.codemancers.com/posts/2013-07-12-redefine-rake-routes-to-add-your-own-custom-tag-in-Rails/
#
# for re-defining the Rake task
# otherwise the previous Rake task is still called
ADDITIONAL_NOTES = %w( hack xxx )
task(:notes).clear
desc "Enumerate all annotations (use notes:optimize, :fixme, :todo, :#{ADDITIONAL_NOTES.join(', :')} for focus)"
task :notes do
# 特異クラスを取得
def eigenclass
class << self; self; end
end
@hyoshida
hyoshida / maybe.rb
Last active August 29, 2015 14:04 — forked from kkismd/maybe.rb
class Maybe < BasicObject
UNPROXIED_METHODS = %i(__send__ __id__ send object_id extend instance_eval initialize block_given? raise caller method)
delegate *(::NilClass.instance_methods - UNPROXIED_METHODS), to: :@just
def initialize(obj)
@just = obj
end
# for debug
@hyoshida
hyoshida / image_path.coffee.erb
Last active November 24, 2015 02:18
Referencing Rails Assets in CoffeeScript
# refs: http://dennisreimann.de/blog/referencing-rails-assets-in-coffeescript/
<%
image_path_map = {}
Dir.chdir("#{Rails.root}/app/assets/images/") do
image_path_map = Dir.glob('**/*').inject({}) do |result, filepath|
next result if File::ftype(filepath) == 'directory'
result.merge(filepath => image_path(filepath))
end
end
%>
@hyoshida
hyoshida / GHOST.c
Last active August 29, 2015 14:14
GHOST exploit
//
// usage:
// gcc -o GHOST GHOST.c
// ./GHOST
//
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@hyoshida
hyoshida / beepmusic.sh
Created February 15, 2015 13:57
Beep music in FreeBSD
#!/bin/sh
# requirements: kldload speaker
echo 'CDE ~ CDE ~ GEDCDED ~ CDE ~ CDE ~ GEDCDEC ~ GGEGAAG ~ EEDDL2C' > /dev/speaker
@hyoshida
hyoshida / display_category_tree_by_awesome_nested_set.rb
Created March 9, 2015 05:53
Display the category tree by awesome_nested_set
Category.roots.map do |root|
tree = []
root.class.each_with_level(root.self_and_descendants) do |category, level|
tree << "#{' ' * level}#{category.name}"
end
tree
end.join("\n").display