Skip to content

Instantly share code, notes, and snippets.

View JunichiIto's full-sized avatar

Junichi Ito JunichiIto

View GitHub Profile
@JunichiIto
JunichiIto / gist:7809860
Created December 5, 2013 17:41
Confirm url with url_for.
$ rails c
pry(main)> app.url_for user_registration_url
"http://localhost:3000/users"
pry(main)> app.url_for new_user_registration_url
"http://localhost:3000/users/sign_up"
pry(main)> app.url_for new_user_registration_url(:user)
"http://localhost:3000/users/sign_up.user"
@JunichiIto
JunichiIto / private.xml
Last active January 3, 2016 04:39
My KeyRemap4MacBook's private.xml for Topre RealForce 87U and RubyMine.
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>TopreCorporation</vendorname>
<vendorid>0x0853</vendorid>
</devicevendordef>
<appdef>
<appname>RubyMine</appname>
<equal>com.jetbrains.rubymine</equal>
WITH events_with_schedule AS (
SELECT
ROW_NUMBER() OVER (PARTITION BY e.id ORDER BY s.due_date) AS rowno
,e.id AS event_id
,e.name
,s.id AS schedule_id
,s.due_date
FROM
schedules s
INNER JOIN events e
context '有効なパラメータの場合' do
before do
@user = attributes_for(:user)
end
it '正しく登録されること' do
expect{
post :create, user: @user
}.to change(User, :count).by(1)
expect(response.status).to eq 302
expect(response).to redirect_to root_path
describe 'Post #create' do
context '有効なパラメータの場合' do
let(:create_user) { -> { post :create, user: attributes_for(:user) } }
it 'リクエストは302 リダイレクトとなること' do
create_user.call
expect(response.status).to eq 302
end
it 'データベースに新しいユーザーが登録されること' do
@JunichiIto
JunichiIto / format_month.rb
Created June 21, 2016 03:46
Dynamically parse and calc month number in text.
require 'minitest/autorun'
require 'date'
class SandboxTest < Minitest::Test
def format_month(text, current_date)
text.gsub(/#\{ *month(?: *([-+]) *(\d+))? *\}/) do
op = Regexp.last_match[1]
val = Regexp.last_match[2]
if op == '+'
(current_date >> val.to_i).month

Because Junichi Ito's post was public, I wanted to translate my answer to Japanese before posting it. Here's my English answer:

Thanks for your comments and your support! I realise we should have done a better job at explaining how we arrived at the pricing.

With Doorkeeper, we’re focused on organisers who hold events on a regular basis, not one off events. This is why we’ve chosen to go with monthly pricing, instead of one a one off fee. We think Doorkeeper already provides you some value when you’re not holding events (people can join your community, you can send them messages), and we want look to how we can provide even more continuous value for communities. If you have any ideas how we could make Doorkeeper more valuable to you even when you’re not holding an event, please let us know.

We chose the smallest plan to have five upcoming events number because we thought it would be the largest number a non professional event organiser would have. We think that ¥1,500 per month is a reasonable price even i

-- https://gist.github.com/natcl/7a5c98aae8b21475caf9
log "start"
property imageFiles : {"jpg", "pef", "dng", "jpeg"}
tell application "Finder"
set MyFolder to folder POSIX file "/Users/your-path/"
set SubFolders to every folder of MyFolder
end tell
repeat with aFolder in SubFolders
@JunichiIto
JunichiIto / fizz_buzz.rb
Created December 13, 2016 01:40
Rubyで書く変なFizzBuzz (Strange FizzBuzz function in Ruby)
fizz_buzz = -> (n) do
f = -> (cond, ans, nxt, n) { n % cond == 0 ? ans : nxt.(n) }.curry
patterns = [[n, n.to_s], [5, 'Buzz'], [3, 'Fizz'], [15, 'Fizz Buzz']]
patterns.inject(nil) { |nxt, (cond, ans)| f.(cond, ans, nxt) }.(n)
end
(1..20).map(&fizz_buzz)
=begin
[
[ 0] "1",
@JunichiIto
JunichiIto / answer.sql
Last active February 6, 2017 22:32
【SQL腕試し問題】現在の部署に所属する社員の一覧を取得するSQLを書いて下さいの解答例
-- http://qiita.com/jnchito/items/29e22cc5a73da29f65a3
SELECT
e.id
,e.name
,sh.section_name
,to_char(sh.start_date, 'yyyy/mm/dd') as start_date
FROM
employees e
INNER JOIN
section_histories sh