This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
exec("LANG=ja_JP.sjis grep -rn `echo #{ARGV[0]} | nkf -s` #{ARGV[1]} | nkf -w") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Refinements | |
module AssociationCollectionExtension | |
refine ActiveRecord::Associations::CollectionProxy do | |
def find_or_build_by(arguments) | |
find_by(arguments) || build(arguments) | |
end | |
def detect_or_build_by(arguments) | |
self.detect do|instance| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiSelectWithoutCtrl | |
constructor: (_this, options)-> | |
@id = null | |
@name = options["name"] | |
@select = _this | |
@checkboxes = $("<div class='hidden_multi_select'></div>") | |
@select.after(@checkboxes) | |
@selected() | |
selected: -> | |
@select.on "click" , (event) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# lib/active_record/real_delete_discreetly.rb | |
module RealDeleteDiscreetly | |
extend ActiveSupport::Concern | |
def delete_discreetly | |
relation_exist = false | |
self.class.confirm_relations.each do |confirm_relation| | |
if destroyed_by_association | |
if destroyed_by_association.active_record == confirm_relation.to_s.classify.constantize | |
relation_exist = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/6317705/rackrequest-how-do-i-get-all-headers | |
require 'rack' | |
app = Proc.new do |env| | |
headers = env.select {|k,v| k.start_with? 'HTTP_'} | |
.collect {|pair| [pair[0].sub(/^HTTP_/, ''), pair[1]]} | |
.collect {|pair| pair.join(": ") << "<br>"} | |
.sort | |
[200, {'Content-Type' => 'text/html'}, headers] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Console | |
# Class Methods | |
class << self | |
def gets_from_stdin(message = nil) | |
print "#{message}: " unless message.nil? | |
str = STDIN.gets.chomp | |
end | |
def get_y_or_n_from_stdin(message) | |
bol = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require "aws-sdk" | |
S3_SAVE_DIR = "s3/" | |
ALL_FILE_DOWNLOAD = "全てのファイルを落とす" | |
s3 = AWS::S3.new( | |
access_key_id: "YOUR AWS ACCESS KEY" | |
secret_access_key: "YOUR AWS SECRET" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'find' | |
except_ext = %w(.log .yml .jpg .JPG .jpeg .png .pid .ttf .woff .md .json .ico .eot .gif) # 除外するファイル拡張子を設定 | |
except_pattern = %w(.git test .DS_Store migrate hankaku_kana_checker RackMultipart sprockets letter_opener underscore cache) # 除外するパスに含まれる文字列を指定 | |
# チェックする半角カナの配列 | |
han_kana = %w{ア イ ウ エ オ カ キ ク ケ コ サ シ ス セ ソ タ チ ツ テ ト ナ ニ ヌ ネ ノ ハ ヒ フ ヘ ホ マ ミ ム メ モ ヤ ユ ヨ ラ リ ル レ ロ ワ ヲ ン ァ ィ ゥ ェ ォ ャ ュ ョ ッ ゙ ゚ 、 。 ー 「 」} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
jQuery.extend jQuery.fn, | |
toggle_value: -> | |
obj = jQuery(this) | |
obj.val ((if obj.val() is "true" then "false" else "true")) | |
exists: -> | |
@length > 0 | |
enable: -> | |
$(this).removeAttr "disabled" | |
disabled: -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExtendBuiltInDataType | |
class ::Hash | |
def merge_apend_value(hash) #{{{ | |
self.update(hash) do |key, self_val, other_val| | |
Array.wrap(self_val).push(other_val) | |
end | |
end #}}} | |
end | |
end |
NewerOlder