Skip to content

Instantly share code, notes, and snippets.

@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@jrom
jrom / nginx.conf
Created February 7, 2012 17:14
nginx hack for multiple conditions
if ($request_uri = /) {
set $test A;
}
if ($host ~* teambox.com) {
set $test "${test}B";
}
if ($http_cookie !~* "auth_token") {
set $test "${test}C";
@fnichol
fnichol / README.md
Created February 26, 2012 01:23
A Common .ruby-version File For Ruby Projects

A Common .ruby-version File For Ruby Projects

Background

I've been using this technique in most of my Ruby projects lately where Ruby versions are required:

  • Create .rbenv-version containing the target Ruby using a definition name defined in ruby-build (example below). These strings are a proper subset of RVM Ruby string names so far...
  • Create .rvmrc (with rvm --create --rvmrc "1.9.3@myapp") and edit the environment_id= line to fetch the Ruby version from .rbenv-version (example below).

Today I learned about another Ruby manager, rbfu, where the author is using a similar technique with .rbfu-version.

@morimori
morimori / gist:3688802
Created September 10, 2012 03:59
focus タグや save_and_open_page が残っていたらコミットさせない pre-commit フック
# Block commit include focus tag for test
git stash --keep-index -q
FOCUS_TAGS=$(grep -rn ':focus => true' spec/*/**)
result=$?
git stash pop -q
if [ $result -eq 0 ]; then
echo "### PLEASE REMOVE FOCUS TAGS ###"
echo "$FOCUS_TAGS"
exit 1
fi
@jmblog
jmblog / gist:6077993
Last active November 22, 2021 08:37
所得税と住民税の計算方法

所得税(国税)

所得税の計算方法

所得税額 = (所得金額(A) - 所得控除額(B)) × 税率 - 税額控除額(C)

  • 「所得金額(A)- 所得控除額(B)」は 課税所得金額 といい、1,000円未満の端数を切り捨てる。

所得税の税率

@thescouser89
thescouser89 / 1.8.7-rbenv.patch
Created December 23, 2013 18:46
rbenv patch to be applied when installing ruby 1.8.7-p375 Patch adapted from https://github.com/sstephenson/ruby-build/wiki#make-error-for-200-p247-and-lower-on-fedorared-hat
--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -757,8 +757,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
method = EC_GFp_mont_method();
} else if (id == s_GFp_nist) {
method = EC_GFp_nist_method();
+#if !defined(OPENSSl_NO_EC2M)
} else if (id == s_GF2m_simple) {
method = EC_GF2m_simple_method();
+#endif
@profh
profh / decode_session_cookie.rb
Last active June 23, 2021 13:25
A simple script to decode Rails 4 session cookies
@nicolasembleton
nicolasembleton / restart_bluetooth.sh
Last active May 11, 2024 17:43
Restart Bluetooth Daemon on Mac OS X without restarting
#!/bin/bash
sudo kextunload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
sudo kextload -b com.apple.iokit.BroadcomBluetoothHostControllerUSBTransport
socat Examples
===============
* 注意
- SYSTEM で : を使う時は必ずエスケープすること
* 相手に接続
# telnet, netcat, socat それぞれの場合
$ socat - TCP:127.0.0.1:8000
@pahud
pahud / gen_cf_cidr.py
Created July 4, 2016 10:52
generate AWS CloudFront IP/CIDR range
#!/usr/bin/env python
import requests, json
d = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json').text
l = json.loads(d)
for ip_range in [x['ip_prefix'] for x in l['prefixes'] if x['service']=='CLOUDFRONT' ]:
print ip_range