Skip to content

Instantly share code, notes, and snippets.

View murajun1978's full-sized avatar
🍻

murajun1978 murajun1978

🍻
  • GEEX
  • Japan
View GitHub Profile
@murajun1978
murajun1978 / get_token.rb
Created October 31, 2012 15:43
Get the token using the API of Qiita
require 'net/https'
Net::HTTP.version_1_2
http = Net::HTTP.new('www.qiita.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
#twittername or githubname@github
@murajun1978
murajun1978 / atnd_search.rb
Created November 5, 2012 07:17
Search ATND events
require 'nokogiri'
require 'open-uri'
#ATND API Reference -> http://atnd.org/doc/api.html
#Search "Pronama" events.
xml_doc = Nokogiri::XML(open("http://api.atnd.org/events/?keyword=pronama&format=xml"))
#Get titles
xml_doc.search("//title").each do |title|
puts title.text
@murajun1978
murajun1978 / regular_expression.rb
Created January 4, 2013 14:55
Using Variables in Ruby Regular Expression.
foo = "hogehoge"
bar = "hoge"
foo.scan(/#{bar}/) # => ["hoge", "hoge"]
namespace :secret do
secret_token_file = Rails.root.join('config', 'initializers', 'secret_token.rb')
file secret_token_file do
require 'securerandom'
token = SecureRandom.hex(64)
require 'active_support/core_ext/string/strip'
application_name = Rails.application.class.name
content = <<-EOS.strip_heredoc
@murajun1978
murajun1978 / encode_csv.rb
Last active December 14, 2015 22:29
RubyでCSVファイルをShift-JISからUTF-8へエンコード
require 'csv'
file_path = ARGV[0]
CSV.foreach(file_path, encoding: 'SJIS:UTF-8') do |row|
p row
end
@murajun1978
murajun1978 / rails_template.rb
Last active December 29, 2015 02:39
my template file
gem('sqlite3', group: :development)
gem('thin', group: :development)
gem('pg', group: :production)
gem('everywhere')
gem('rubocop', group: [:development, :test])
gem('brakeman', group: [:development, :test])
gem('rspec-rails', group: [:development, :test])
gem('factory_girl_rails', group: [:development, :test])
gem('database_rewinder', group: [:development, :test])
# "0:Ruby" "1:mruby" "2:RubyMotion"
%w(Ruby mruby RubyMotion).each_with_index do |name, index|
puts "#{index}:#{name}"
end #=> ["Ruby", "mruby", "RubyMotion"]
# "1:Ruby" "2:mruby" "3:RubyMotion"
%w(Ruby mruby RubyMotion).each.with_index(1) do |name, index|
puts "#{index}:#{name}"
end #=> ["Ruby", "mruby", "RubyMotion"]
module PrependModule
def foo
'prepend module'
end
end
class PrependClass
prepend PrependModule
def foo
@murajun1978
murajun1978 / ボーリングのスコア計算
Created April 26, 2014 05:07
Shinosaka.rb ペアプロ問題
ex.
[[5,3],[7,2],[8,/],[X],[7,1],[9,-],[6,2],[X],[6,/],[8,-]]
score: 126
[]: 1フレーム
n: 倒したピンの数
X: ストライク
/: スペア
-: ガター
@murajun1978
murajun1978 / ruby_silver_array.rb
Created May 1, 2014 09:07
Rubyの配列 (Ruby Silver)
ary = Array.new(2, Hash.new)
ary =[0][:dog] = "pochi"
ary #=> ???
ary = Array.new(2){Hash.new}
ary[0][:dog] = "pochi"
ary #=> ???