Skip to content

Instantly share code, notes, and snippets.

View takai's full-sized avatar

Naoto Takai takai

View GitHub Profile
# -*- mode: ruby; coding: utf-8-unix -*-
require 'benchmark'
Benchmark.bm(10) do |bm|
a = nil
bm.report 'ternary op' do
10000.times { a ? a.name : 'unknown' }
end
bm.report 'rescue' do
まず言及すると必ずリプライがもらえるアカウントをつくる。
それに気がついた@takkanmはツイートしてリプライをもらうようになる。
リプライされたい分だけツイートをしたら、そのアカウントには興味を無くす。
さみしくなったら、またそのアカウントのところに戻ってくる。
ツイートしても、そのアカウントからリプライが全くもらえなくなると、@takkanmはそのアカウントに興味をなくす。
ところが、ツイートして、リプライがもらえたりもらえなかったりするように設定すると、
@takkanmは一生懸命ツイートするようになる。
package app;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class UnsafeCounter {
private int nextValue = 0;
public int getNextValue() {
class Array
def odd
select {|f| f % 2 == 0}
end
end
p [].to_a.odd
# -*- mode: ruby; coding: utf-8-unix -*-
require 'active_model'
class User
include ActiveModel::Validations
attr_accessor :email
attr_accessor :password
package app;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello, Processing.js.</title>
<script type="application/javascript" src="processing-1.2.3.min.js">
</script>
<script type="application/javascript">
/*
* This code searches for all the <script type="application/processing" target="canvasid">
require 'eventmachine'
require 'ruote/worker'
module Ruote
class EMWorker < Worker
def run
EM.add_periodic_timer(1) do
step
end
require 'rubygems'
require 'bundler/setup'
require 'mysql2'
require 'active_record'
require 'logger'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.establish_connection(:adapter => 'mysql2',
#!/usr/bin/env ruby
$0 = 'daemon-env'
loop {}