Skip to content

Instantly share code, notes, and snippets.

View tosik's full-sized avatar
🏠
Working from home

Toshiyuki Hirooka tosik

🏠
Working from home
  • Tokyo, Japan
View GitHub Profile
describe '.bar' do
subject { Foo }
it { should_receive(:boo) }
it { should_receive(:baa) }
# when
after do
subject.bar
end
end
@tosik
tosik / controller.rb
Created November 8, 2012 08:45
CSVがステキに見える!
params[:upload_file].tap do |upload_file|
file = upload_file.tempfile.tap
master_class = upload_file.original_filename.sub('.csv', '').classify
master_class.delete_all
csv = CSV.parse(file.read, headers: true)
csv.each do |row|
row = row.to_hash.with_indifferent_access
row.delete(nil)
if row[:id]
master_class.new(row).tap {|record|
# coding: utf-8
require 'open-uri'
module Ikioi
module_function
def run
puts ActiveSupport::JSON.decode(open('http://2ch-ranking.net/ranking.json?board=gameswf')
.read.sub('callback(', '').sub(/\);$/, '')).find {|item| item['title'].include? "あらあらかしこ" }['ikioi']
rescue
puts 0
end
@tosik
tosik / file0.txt
Created November 26, 2012 10:17
dotcloud で cd current した後 rake する ref: http://qiita.com/items/37445354e969993b48a8
dotcloud run www 'cd current; rake foo'
@tosik
tosik / notification.rb
Created January 2, 2013 11:23
local notification by rubymotion
module Helper
module Notification
def setup(args)
time = args[:time]
text = args[:text]
opts = args[:opts]
UILocalNotification.alloc.init.tap do |notif|
notif.fireDate = NSDate.dateWithString( time.to_s )
User.order('rand()').first
  User Load (2.5ms)  SELECT `users`.* FROM `users` ORDER BY rand() LIMIT 1
User.select(:id).order('rand()').first.reload
@tosik
tosik / friendship.rb
Last active December 13, 2015 21:08
Rails (ActiveRecord) base union
class Friendship < ActiveRecord::Base
scope :of_user, ->(user) { union(where(user1_id: user), where(user2_id: user)) }
class << self
def union(*relations)
union_clause = "(#{relations.map {|r| r.ast.to_sql }.join(') UNION (')})"
as_clause = "AS #{self.table_name}"
from "(#{union_clause}) #{as_clause}"
@tosik
tosik / dfault.scss
Last active December 15, 2015 08:28
button {
label {
position: 0 0;
}
image-view {
position: 0 0;
}
}
@tosik
tosik / gist:5632905
Created May 23, 2013 05:19
なぜか動かない jq がパイプしてくれないっぽい?
ssh gerrit.example.com -p 29418 gerrit stream-events | jq '.|select(.type == "comment-added")|{comment, url: .change.url}|.[]' --raw-output | ruby -e "require 'carrier-pigeon'; loop { message = STDIN.gets; if message then CarrierPigeon.send(uri: 'irc://gerrit:password@irc.example.com/#gerrit', message: message, ssl:true, notice:true, join:true) ; p message ;end }"
@tosik
tosik / gist:5632979
Last active December 17, 2015 15:39
#!/usr/bin/env ruby
require 'carrier-pigeon'
require 'json'
require 'pp'
command = <<EOS
ssh gerrit.example.com gerrit stream-events
EOS
IO.popen(command, 'r+') do |io|