This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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({name:b.name,url:"http://qiita.com/tags/"+b.name});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("https://qiita.com/api/v1/users/"+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.name=a.url_name,this.profileImageUrl=a.profile_image_url,this.url="http://qiita.com/users/"+this.name}return a}(),e=function(a,b){var c,d,e=this;c="get",d=new XMLHttpRequest;if("withCredentials"in d)d.open(c,a,!0);else{if(typeof XDomainRequest=="undefined")throw"Failed to initialize CORSRequest";d=new XDomainRequest,d.op |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str = "no ruby no life" #=> count as {"no"=>2,"ruby"=>1,"life"=>1} | |
Hash[str.scan(/\w+/).group_by{|s|s}.map{|k,v|[k,v.size]}] | |
str.scan(/\w+/).each_with_object(Hash.new(0)){|s,h|h[s]+=1} | |
# require Ruby 2.1.1 | |
str.scan(/\w+/).group_by{|s|s}.map{|k,v|[k,v.size]}.to_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.find params[:id] | |
older_user = User.where("date_of_birth <= ? AND id <> ?", user.date_of_birth, user.id).order("date_of_birth DESC, id").limit(1).first | |
younger_user = User.where("date_of_birth >= ? AND id <> ?", user.date_of_birth, user.id).order("date_of_birth ASC, id").limit(1).first |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (total_count_for amount) | |
(+ amount (/ (abs (pred amount)) 2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Event < ActiveRecord::Base | |
has_many :groups | |
# reference: http://guides.rubyonrails.org/association_basics.html#self-joins | |
has_many :next_events, class_name: "Event", foreign_key: "previous_event_id" | |
belongs_to :previous_event, class_name: "Event" | |
end | |
# schema.rb | |
create_table "events", force: :cascade do |t| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
source 'https://rubygems.org' | |
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
class Bingo | |
def self.generate_card | |
# 以下の行は削除して、自分でロジックを実装してください。 | |
sample | |
end | |
def self.sample | |
<<-CARD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
format_matrix(sum_matrix(matrix)) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'test/unit' | |
require 'csv' | |
class FillBlankTest < Test::Unit::TestCase | |
def fill_blank(csv_text) | |
CSV.parse(csv_text).inject([]) { |results, row| | |
results << row.zip(results.last || []).map { |curr, prev| curr || prev } | |
} | |
.map { |row| row.join(',') } | |
.join("\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe 'Test true/truthy' do | |
context 'test 1' do | |
example do | |
expect(1).to be_truthy | |
end | |
example do | |
expect(1).to be true | |
end | |
example do | |
expect(1).to eq true |
OlderNewer