Skip to content

Instantly share code, notes, and snippets.

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

Tatsuro Baba tbaba

🏠
Working from home
View GitHub Profile
#!/usr/bin/env ruby
# coding: utf-8
require 'rubygems'
require 'oauth2'
require 'sinatra'
require 'json'
API_KEY = your_api_key
API_SECRET = your_api_secret
@tbaba
tbaba / am_sample1
Created July 28, 2011 14:01
activemodel test
class Person
attr_accessor :first_name, :last_name
def initialize(attributes=nil)
@first_name = attributes[:first_name]
@last_name = attributes[:last_name]
end
end
@tbaba
tbaba / 001_create_articles.rb
Created September 4, 2011 15:24
Single Table Inheritance Sample
class CreateArticles < ActiveRecord::Migration
self.up
create_table :articles do |t|
t.string :title
t.text :body
t.string :type
t.timestamps
end
end
@tbaba
tbaba / migration.rb
Created December 22, 2011 14:56
Rails 3.1 feature: has_secure_password
$ rails console
ruby-1.9.3-p0 :001 > user = User.new
=> #<User id: nil, username: nil, password_digest: nil, created_at: nil, updated_at: nil>
ruby-1.9.3-p0 :002 > user = User.new username: 't.baba', password: 'hogehoge', password_confirmation: 'hogehoge'
=> #<User id: nil, username: "t.baba", password_digest: "$2a$10$HaXYndWU/kgCYopLf5nyb.PnX2QN0BQeKjECuoreZ2qO...", created_at: nil, updated_at: nil>
ruby-1.9.3-p0 :003 > user.save!
Binary data inserted for `string` type on column `password_digest`
=> true
ruby-1.9.3-p0 :005 > user.authenticate 'hoge'
=> false
@tbaba
tbaba / gist:1544858
Created December 31, 2011 18:26
introduce octokit gem
@client = Octokit::Client.new(login: YOUR_ACCOUNT_NAME, password: YOUR_PASSWORD)
@account = @client.user
@repos = @client.repos.select{|r| !r.private }
@tbaba
tbaba / Gemfile
Created January 7, 2012 12:44
Post to Twitter with OmniAuth
gem 'omniauth'
gem 'omniauth-twitter'
puts 'hoge'
@tbaba
tbaba / config.ru
Created April 8, 2012 13:28
Nginx and Unicorn
require 'rack'
class Hello
def call(env)
[200, {'Content-Type' => 'text/plain'}, ['Hello, Nginx!']]
end
end
run Hello.new
@tbaba
tbaba / parallel_assets_compiler.gemspec
Created September 3, 2012 08:28 — forked from joerichsen/parallel_assets_compiler.gemspec
Microgem for compiling assets in parallel
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = 'parallel_assets_compiler'
s.version = '0.2.0'
s.platform = Gem::Platform::RUBY
s.author = 'Jørgen Orehøj Erichsen'
s.email = 'joe@erichsen.net'
s.summary = 'Compile assets in parallel'
s.description = 'Compile assets in parallel to speed up deployment'
@tbaba
tbaba / all_or_nothing.gemspec
Last active December 11, 2015 04:18
ActiveRecord::QueryMethods#all!
Gem::Specification.new do |gem|
gem.name = "all_or_nothing"
gem.version = '0.0.1'
gem.authors = ["Tatsuro Baba"]
gem.email = ["harakirisoul@gmail.com"]
gem.description = %q{TODO: Write a gem description}
gem.summary = %q{TODO: Write a gem summary}
gem.homepage = "https://gist.github.com/4543857"
gem.files = ['all_or_nothing.rb']