Skip to content

Instantly share code, notes, and snippets.

fizz = function f() {
fizz = function () {
fizz = function () {
fizz = f
return "Fizz"
}
}
}
buzz = function f() {
@rummelonp
rummelonp / faraday.md
Last active May 20, 2022 12:23
Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

Ruby の HTTP クライアントライブラリ Faraday が便利そう

API ラッパの開発には [RestClient gem][rest_client_gem] だとか
OAuth の必要なものは [Net/HTTP][net_http] + [OAuth gem][oauth_gem] を使ってた

[Twitter gem][twitter_gem] や [Instagram gem][instagram_gem] など API ライブラリのソースを読んでみると
[Faraday gem][faraday_gem] というものがよく使われてた

@hcarvalhoalves
hcarvalhoalves / nginx_status_codes.rb
Created May 1, 2012 17:58 — forked from mipearson/nginx_status_codes.rb
Very simple munin plugin to graph nginx HTTP error codes
#!/usr/bin/env ruby
CODES = {
'400' => 'Bad Request',
'401' => 'Unauthorized',
'403' => 'Forbidden',
'404' => 'Not Found',
'405' => 'Method Not Allowed',
'406' => 'Not Acceptable',
'408' => 'Request Timeout',

Proposal for Improving Mass Assignment

For a while, I have felt that the following is the correct way to improve the mass assignment problem without increasing the burden on new users. Now that the problem with the Rails default has been brought up again, it's a good time to revisit it.

Sign Allowed Fields

When creating a form with form_for, include a signed token including all of the fields that were created at form creation time. Only these fields are allowed.

To allow new known fields to be added via JS, we could add:

@vijaydev
vijaydev / gist:1472145
Created December 13, 2011 13:35
Rails 3.2.0 Changelogs

The latest release notes is available at http://edgeguides.rubyonrails.org/3_2_release_notes.html

Railties 3.2.0 (unreleased)

  • Speed up development by only reloading classes if dependencies files changed. This can be turned off by setting config.reload_classes_only_on_change to false. José Valim

  • New applications get a flag config.active_record.auto_explain_threshold_in_seconds in the environments configuration files. With a value of 0.5 in development.rb, and commented out in production.rb. No mention in test.rb. fxn

  • Add DebugExceptions middleware which contains features extracted from ShowExceptions middleware José Valim

@dakatsuka
dakatsuka / default.rb
Created December 2, 2011 03:04
MongoDBをインストールするためのChefレシピ
script "add key" do
interpreter "bash"
user "root"
not_if "apt-key list | grep 7F0CEB10"
code <<-EOC
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
EOC
end
script "add aptline" do
def revoke(user)
proxy_association.owner.tap do |project|
# You can't remove the last user with access (someone has to have access to the project!)
if project.users.many?
if user.pending? && user.projects.one?
user.destroy
else
project.users.delete(user)
user.touch
end
@yetanothernguyen
yetanothernguyen / gist:1196492
Created September 6, 2011 03:11
unicorn init script
#!/bin/bash
### BEGIN INIT INFO
# Provides: says-dot-com-production
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the says-dot-com-production unicorns at boot
# Description: Enable says-dot-com-staging at boot time.
### END INIT INFO
@mipearson
mipearson / nginx_status_codes.rb
Created August 15, 2011 12:44
Very simple munin plugin to graph nginx HTTP error codes
#!/usr/bin/env ruby
CODES = {
'400' => 'Bad Request',
'401' => 'Unauthorized',
'403' => 'Forbidden',
'404' => 'Not Found',
'405' => 'Method Not Allowed',
'406' => 'Not Acceptable',
'408' => 'Request Timeout',
@kennyj
kennyj / rails_3_1_RC4_changes.md
Created May 6, 2011 17:34 — forked from ryanb/rails_3_1_rc4_changes.md
Rails 3.1 RC4の変更点(和訳)

Railties 3.1 RC4

  • 新しいrakeタスク assets:clean はプリコンパイルされたアセットを削除する。

  • --skip-gemfile--skip-bundleなしでの、アプリケーションとプラグインのソース生成は、bundle installを走らせる

  • jdbc*アダプターにとってのデータベースタスクを修正した

  • jdbcpostgresqlにとってのテンプレート生成