Skip to content

Instantly share code, notes, and snippets.

View yasaichi's full-sized avatar
😇

Yuichi Goto yasaichi

😇
View GitHub Profile
@xaviershay
xaviershay / application_controller.rb
Created May 19, 2011 21:43
Access helper methods outside controllers and views
class ApplicationController < ActionController::Base
# Provide access to helper methods from outside controllers and views,
# such as in Presenter objects. Rails provides ActionController::Base.helpers,
# but this does not include any of our application helpers.
def self.all_helpers
@all_helpers_proxy ||= begin
# Start with just the rails helpers. This is the same method used
# by ActionController::Base.helpers
proxy = ActionView::Base.new.extend(_helpers)
@jboner
jboner / latency.txt
Last active May 14, 2024 16:01
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@deeeki
deeeki / memo.md
Created July 22, 2012 13:51
RailsにおけるRESTfulなURL設計勉強会
  • legacy wild controller route ':controller(/:action(/:id))(.:format)' は使わない派

  • 利用するURLを明示しておきたい

  • named_route使えないとリンクの記述が冗長になるのでは

  • namespaceなど少し複雑なことをやろうとすると何かしらルーティングを書くことになり、統一感がなくなる

  • 確認画面

    • confirmアクションの追加
      • 各アクションがすっきりする
      • 新規と編集で挙動が変わる場合 (edit_confirmアクション?)
  • パラメータ(mode=confirm)またはモデルの確認用プロパティ(http://bit.ly/mRQ8I5)

@Gab-km
Gab-km / github-flow.ja.md
Last active April 25, 2024 04:01 — forked from juno/github-flow.ja.md
GitHub Flow (Japanese translation)
@katzchang
katzchang / README.md
Last active September 28, 2022 13:42
Steve Freeman氏とのペアプロ雑感 #tddbc

Steve Freeman氏とのペアプロ雑感

http://tddbc.doorkeeper.jp TDD Boot Camp 2013-07 -- TDDBC で、偶然にもロンドンから来日していたSteve Freeman氏を招くことができた。ちなみに本当に偶然の来日で、その日の夕方にご家族と隅田川の花火を見る予定だったらしい。貴重な時間である。

20分ほど講演していただき、さらに参加者と一緒にペアプロ課題に挑戦してもらった。しかもペアプロでっていう貴重な体験をさせてもらったので、そのことについてまとめたい。

Steve Freeman氏は書籍 "Growing Object-Oriented Software, Guided by Tests" (邦訳「実戦テスト駆動開発」)の共著者の一人で、Javaのモックフレームワーク "JMock"の開発者の一人。当然、自動販売機の課題にもJMockを駆使してモデリングしていただくことになった。

Start from the outside

@tomas-stefano
tomas-stefano / Capybara.md
Last active May 2, 2024 05:16
Capybara cheatsheet

Capybara Actions

# Anchor
click_link 'Save'

# Button
click_button 'awesome'

# Both above
@mala
mala / gist:8857629
Last active October 29, 2019 00:35
Flashと特定ブラウザの組み合わせでcross originでカスタムヘッダ付与が出来てしまう問題が未だに直っていない話

2014-07-09 それぞれ修正されたのを確認したので追記します。

APSB14-17 で修正されたようです

筆者が把握している範囲で、最新版のFlash Playerを利用している場合に、(crossdomain.xmlもしくはユーザーの許可なしで)cross originでカスタムヘッダを付与する方法はありません。

Webサイト運営者は

@demisx
demisx / active_record_objects_autosave.md
Last active April 29, 2024 09:02
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
@dhh
dhh / test_induced_design_damage.rb
Last active June 22, 2023 06:18
This is an extraction from Jim Weirich's "Decoupling from Rails" talk, which explained how to apply the hexagonal design pattern to make every layer of your application easily unit testable (without touching the database etc). It only seeks to extract a single method, the EmployeesController#create method, to illustrate the design damage that's …
# Original Rails controller and action
class EmployeesController < ApplicationController
def create
@employee = Employee.new(employee_params)
if @employee.save
redirect_to @employee, notice: "Employee #{@employee.name} created"
else
render :new
end
@JunichiIto
JunichiIto / alias_matchers.md
Last active May 14, 2024 08:48
List of alias matchers in RSpec 3

This list is based on aliases_spec.rb.

You can see also Module: RSpec::Matchers API.

matcher aliased to description
a_truthy_value be_truthy a truthy value
a_falsey_value be_falsey a falsey value
be_falsy be_falsey be falsy
a_falsy_value be_falsey a falsy value