Skip to content

Instantly share code, notes, and snippets.

@hachy
hachy / colors256.rb
Last active December 16, 2015 21:48
256 terminal colors and hex colors in Ruby
class Array
def generate_color(num, reg)
each.with_index(num) do |hexcolor, termcolor|
number = "#{termcolor}".ljust(3)
bg = "\e[48;5;#{termcolor}m \e[0m"
fg = "\e[38;5;#{termcolor}m #{number} ##{hexcolor} \e[0m"
print bg + fg
print "\n" if reg =~ hexcolor
end
end
@hachy
hachy / space_squeeze.rb
Created September 25, 2013 09:06
ruby space_squeeze.rb file1.txt > file2.txt
ARGF.each_line do |line|
puts line.gsub(/[ ]+/, ' ').rstrip
end
@hachy
hachy / eva01.vim
Created January 25, 2014 03:28
colorscheme for lightline.vim
" lightline colorscheme
" Name: eva01
" Author: hachy
" License: MIT License
let s:purple1 = [ '#875faf', 97 ]
let s:purple2 = [ '#af5fff', 135 ]
let s:green = [ '#87ff5f', 119 ]
let s:orange = [ '#d7af5f', 179 ]
let s:red = [ '#d75f87', 168 ]
@hachy
hachy / aiueo_order.rb
Created January 30, 2014 02:21
ローマ字をあいうえお順にソート
aiueo = "aiueokgsztdnhbpmyrw"
alpha = "a-s"
nogizaka = %w(shiraishimai akimotomanatsu matsumurasayuri ikomarina hatanakaseira itounene itoumarika itoukarin itoujunna ikutaerika)
puts nogizaka.sort_by { |name| name.tr(aiueo, alpha) }
# => akimotomanatsu
# => ikutaerika
# => ikomarina
@hachy
hachy / flash.haml
Created March 6, 2014 08:19
RailsのflashとBootstrapを組み合わせる。Ruby on Railsチュートリアル参考 -> http://railstutorial.jp/book/ruby-on-rails-tutorial?version=4.0#sec-the_flash
- flash.each do |key, value|
%div{class: "alert alert-#{key} alert-dismissable"}
= value
%button.close(type="button" data-dismiss="alert" aria-hidden="true")
×
@hachy
hachy / nogizaka46_8th_member.rb
Last active August 29, 2015 14:00
乃木坂46 八枚目シングル「気づいたら片思い」 メンバー
romaji = %w(manatsu.akimoto erika.ikuta rina.ikoma rena.ichiki nene.ito marika.ito sayuri.inoue misa.eto hina.kawago mahiro.kawamura hinako.kitano asuka.saito chiharu.saito yuuri.saito reika.sakurai mai.shiraishi mai.shinuchi kazumi.takayama kana.nakada himeka.nakamoto seira.nagashima nanase.nishino ami.noujo nanami.hashimoto seira.hatanaka hina.higuchi mai.fukagawa minami.hoshino miona.hori sayuri.matsumura rina.yamato yumi.wakatsuki maaya.wada)
kanji = %w(秋元真夏 生田絵梨花 生駒里奈 市來玲奈 伊藤寧々 伊藤万理華 井上小百合 衛藤美彩 川後陽菜 川村真洋 北野日奈子 齋藤飛鳥 斎藤ちはる 斉藤優里 桜井玲香 白石麻衣 新内眞衣 高山一実 中田花奈 中元日芽香 永島聖羅 西野七瀬 能條愛未 橋本奈々未 畠中清羅 樋口日奈 深川麻衣 星野みなみ 堀未央奈 松村沙友理 大和里菜 若月佑美 和田まあや)
# puts member = romaji.zip(kanji).to_h
last = romaji.length
print '{ '
romaji.zip(kanji).each_with_index do |(k, v), i|
@hachy
hachy / nogizaka_cli.rb
Last active October 31, 2015 14:45
nogizaka_blog example
# gem install nogizaka_blog
# https://github.com/hachy/nogizaka_blog
require 'optparse'
require 'nogizaka_blog'
def run
ym = @nogi.yearmonth
puts "#{ym[0..3]}/#{ym[4..5]}"
header = display_format('name', 'comment', 'article')
puts header
@hachy
hachy / parse.rb
Last active October 6, 2015 00:57
yaml to string-array
require 'yaml'
data = YAML.load_file('sakana.yml')
data.keys.each do |k|
puts "<item>#{k}</item>"
end
data.values.each do |v|
puts "<item>#{v}</item>"
@hachy
hachy / kanji.rb
Created July 5, 2015 07:12
android values/strings.xml generator
file_name = 'kokumei_0.txt'
quiz_list_name = 'kokumei_0'
kanji = []
yomi = []
File.open(file_name).each_line do |line|
a, b = line.split(' ')
kanji << a
yomi << b
@hachy
hachy / nogizaka_blog_url.rb
Created July 27, 2015 02:00
Create json file from Nogizaka46's members and blog url.
member = %w(
秋元真夏
生田絵梨花
生駒里奈
伊藤かりん
伊藤純奈
伊藤万理華
井上小百合
衛藤美彩
川後陽菜