Skip to content

Instantly share code, notes, and snippets.

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

Daichi Hirata daichirata

🏠
Working from home
View GitHub Profile
(defun consult-git-status--git-status ()
(let ((status (with-output-to-string
(with-current-buffer standard-output
(process-file "git" nil t nil "status" "--porcelain")))))
(cl-remove-if #'string-blank-p (split-string status "\n"))))
(defun consult-git-status--file-path (line)
(let ((path (car (last (split-string line " ")))))
(concat (expand-file-name (project-root (project-current))) path)))
@daichirata
daichirata / turntable_ext.rb
Created October 31, 2017 06:47
turntable ext
# config/initializers/turntable_ext.rb
module TurntableExt
def target_shard?(shard_name)
(shard_name.nil? && target_shards.blank?) || Array.wrap(target_shards).include?(shard_name)
end
end
ActiveRecord::Migration.prepend(TurntableExt)
@daichirata
daichirata / Gemfile
Created July 23, 2016 14:11
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.18', '< 0.5'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
@daichirata
daichirata / shibuya-el-position-paper.md
Created August 21, 2012 01:36 — forked from ainame/shibuya-el-position-paper.md
shibuya.elのポジションペーパーです。githubアカウントをお持ちの方はforkしてお使いください。

Shibuya.el#1 ポジションペーパー

Personal

  • 名前(任意)

    • 平田 大地
  • Twitter or Facebookのアカウント or HN等

  • @Daic_h

@daichirata
daichirata / ruby_mongo_sharding.rb
Created May 23, 2012 03:48
ruby_mongo_sharding.rb
# -*- coding: utf-8 -*-
require 'pp'
require 'fileutils'
require 'mongo'
require 'yaml'
module Sample
class Mongo
BASE_DATA_PATH = '/tmp/mongodb'
LOG_FILE_PATH = "#{BASE_DATA_PATH}/log"
module Lokka
module HelloGem
def self.registered(app)
app.get "/admin/plugins/hello_gem" do
haml view_path('test.haml'), :layout => :"admin/layout"
end
app.helpers do
def view_path(name)
view_path = File.expand_path(File.dirname(__FILE__) + "/path/to/view/#{name}")
@daichirata
daichirata / config.yml
Created February 11, 2012 20:48 — forked from nefo-mi/config.yml
Twitterのリストに人を登録するRubyスクリプト ref: http://qiita.com/items/2339
:user_name: YOUR NAME
:list_name: LIST NAME
:consumer_key: CONSUMER KEY
:consumer_secret: CONSUMER SECRET
:oauth_token: ACCESS TOKEN
:oauth_token_secret: ACCESS SECRET TOKEN
@daichirata
daichirata / alias.rb
Created February 10, 2012 11:55
alias
#!/usr/bin/env ruby
COLORS =
{ :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 27, :default => 39 }
@@command_list = {}
def with_color(state = :default)
puts "\e[#{COLORS[state]}m#{yield}\e[0m"
end
@daichirata
daichirata / Rakefile
Created August 12, 2011 04:10
Use Pry as IRB replacement in rails 2.3.5 console
namespace :pry do
def pry_setting(args)
libs ||= []
libs << %( -r "#{RAILS_ROOT}/config/environment")
libs << " -r console_app"
libs << " -r console_with_helpers"
if args.sandbox
libs << " -r console_sandbox" if args.sandbox
puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails.version})"
puts "Any modifications you make will be rolled back on exit"
class Sample
def hello
return "Hello World!"
end
end
s = Sample.new
s.hello #=> "Hello World!"