Skip to content

Instantly share code, notes, and snippets.

View hidakatsuya's full-sized avatar
🏡
Working from home

Katsuya HIDAKA hidakatsuya

🏡
Working from home
View GitHub Profile
@amatsuda
amatsuda / http.rb
Created November 1, 2011 12:11
A sample of Ruby's method_missing
require 'open-uri'
class Http
def self./(url)
open("http://#{url}").read
end
end
class String
def com
self + '.com'
@shugo
shugo / fizzi.rb
Created August 10, 2012 04:45
@yhara こんな感じ
module FizzBuzzInteger
refine Fixnum do
def to_s
self % 15 == 0 ? "FizzBuzz" :
self % 5 == 0 ? "Fizz" :
self % 3 == 0 ? "Buzz" :
super
end
end
end
@moro
moro / unit_test_spec.rb
Created September 19, 2012 02:31
unit_test_spec.rb
class A
def foo(num)
%w[one two three][num - 1]
end
end
describe A do
describe "#foo" do
RSpec::Matchers.define :do_foo do |args|
match do |instance|
@thelibrarian
thelibrarian / Fixing XCode Command Line Tools.md
Last active November 6, 2017 03:28
How to fix compile errors with the XCode command line tools on Mac OS X. Solves problems such as failing to find Framework header files (e.g. ruby.h).

The Problem

If you have installed the standalone Command Line Tools for XCode on your Mac (i.e. without having XCode.app installed), some of these tools can get a bit confused due to a couple of oversights on Apple's part in finalising the setup.

Note: all commands below will need to be run from an Administrator account, or by an account with appropriate permission in /etc/sudoers.

The Solution

1. Failing to Find Frameworks

Sometime when compiling against the preinstalled Frameworks (e.g. Ruby or Python), various tools will inexplicable fail to find header files that are quite clearly there. This is caused by the fact that no XCode has been selected for the command-line tools. Wait, I hear you cry, I don't have XCode installed! Indeed, but you nonetheless need to select one, and point it somewhere where the command line tools exist, like so

@wakamsha
wakamsha / memo.md
Last active October 11, 2021 01:40
VirtualBox 内のゲスト OS からホスト OS にアクセスしたい

VirtualBox仮想マシンのネットワークはデフォルトでNATとなっている。 VirtualBox の場合、NAT ネットワークアダプタには 10.0.2.0/24 の IP アドレスが割り当てられ、ゲスト OS から見える ホスト OS の IP アドレスには 10.0.2.2 が設定される仕様。

したがってホストOS上に建てたサーバーにゲストOSからアクセスしたい場合は、http://10.0.2.2とアクセスすれば普通に見ることができる。

参考

@kwatch
kwatch / gist:2814940
Created May 27, 2012 16:18
Rubyの特殊変数一覧
$! raise された例外オブジェクト
$" require で読み込まれたファイルの配列
$#
$$ 現在のプロセス ID
$%
$& 正規表現にマッチした箇所の文字列
$' 正規表現にマッチした箇所より後ろの文字列
$(
$)
$* Ruby スクリプトに指定された引数。ARGV と同じ
@voluntas
voluntas / react.rst
Last active May 25, 2022 11:57
React コトハジメ

React コトハジメ

日時

2017-01-02

@voluntas

バージョン

2.1.0

URL

https://voluntas.githu.io/

突っ込みは Twitter @voluntas まで。

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:

@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@robzolkos
robzolkos / Dockerfile
Last active March 2, 2024 20:59
Kamal / SQLite3 issue
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.2.2
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
# Rails app lives here
WORKDIR /rails
# Set production environment