Skip to content

Instantly share code, notes, and snippets.


Junichi Ito JunichiIto

View GitHub Profile
View qiita.js
(function(){"use strict";var a,b,c,d,e,f,g,h,i,j;a=function(){function a(a){var b,d,e,f;this.title=a.title,this.url=a.url,this.tags=[],f=a.tags;for(d=0,e=f.length;d<e;d++)b=f[d],this.tags.push({,url:""});this.user=new c(a.user)}return a}(),b=function(){function b(){}return b.prototype.itemContainer={},b.prototype.findByUsername=function(b,c){var d=this;if(b in this.itemContainer){c(this.itemContainer[b]);return}return e(""+b+"/items?per_page=10",function(e){var f,g,h;d.itemContainer[b]=[];for(g=0,h=e.length;g<h;g++)f=e[g],d.itemContainer[b].push(new a(f));return c(d.itemContainer[b])})},b}(),c=function(){function a(a){,this.profileImageUrl=a.profile_image_url,this.url=""}return a}(),e=function(a,b){var c,d,e=this;c="get",d=new XMLHttpRequest;if("withCredentials"in d),a,!0);else{if(typeof XDomainRequest=="undefined")throw"Failed to initialize CORSRequest";d=new XDomainRequest,d.op
JunichiIto / gist:9870182
Created Mar 30, 2014
Ruby: How to count for each word
View gist:9870182
str = "no ruby no life" #=> count as {"no"=>2,"ruby"=>1,"life"=>1}
# require Ruby 2.1.1
JunichiIto / gist:10015280
Created Apr 7, 2014
Sample code to find next/prev user by date_of_birth.
View gist:10015280
user = User.find params[:id]
older_user = User.where("date_of_birth <= ? AND id <> ?", user.date_of_birth,"date_of_birth DESC, id").limit(1).first
younger_user = User.where("date_of_birth >= ? AND id <> ?", user.date_of_birth,"date_of_birth ASC, id").limit(1).first
View gist:a87fe61c4f28e3268804
(define (total_count_for amount)
(+ amount (/ (abs (pred amount)) 2)))
View gist:e27150de2700e92983bb
class Event < ActiveRecord::Base
has_many :groups
# reference:
has_many :next_events, class_name: "Event", foreign_key: "previous_event_id"
belongs_to :previous_event, class_name: "Event"
# schema.rb
create_table "events", force: :cascade do |t|
View gist:891d1a8eb1f5efded351
# Gemfile
source ''
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
JunichiIto / bingo_spec.rb
Created Mar 5, 2015
ビンゴカード作成問題・解答テンプレート (
View bingo_spec.rb
# coding: utf-8
class Bingo
def self.generate_card
# 以下の行は削除して、自分でロジックを実装してください。
def self.sample
View sum_matrix_test.rb
require 'minitest/autorun'
module SumMatrix
extend self
def generate_sum_matrix(col: 4, row: 4, number_range: 1..1000)
matrix = generate_matrix(col: col, row: row, number_range: number_range)
View fill_blank_test.rb
require 'test/unit'
require 'csv'
class FillBlankTest < Test::Unit::TestCase
def fill_blank(csv_text)
CSV.parse(csv_text).inject([]) { |results, row|
results << || []).map { |curr, prev| curr || prev }
.map { |row| row.join(',') }
View true_truthy_spec.rb
describe 'Test true/truthy' do
context 'test 1' do
example do
expect(1).to be_truthy
example do
expect(1).to be true
example do
expect(1).to eq true