alias alphahex='echo -n "Enter percentage: " ; read opt ; echo "obase=16; ibase=10; (255*$opt+50)/100" | bc'
Replace XX by percentage.
echo "obase=16; ibase=10; (255*XX+50)/100" | bc
## CONSOLE | |
# Routes for a controller | |
rake routes CONTROLLER=products | |
## CONTROLLER | |
# Redirect to referrer | |
redirect_to :back # raise RedirectBackError if no referer | |
# Before filter and after filter in a same method |
:binary # blob | |
:boolean # tinyint | |
:date # date | |
:datetime # datetime | |
:decimal # decimal | |
:float # float | |
:decimal # decimal | |
:integer # int(11) | |
:string # varchar(255) | |
:text # text |
- save | |
- valid | |
before_validation | |
- validate | |
after_validation | |
before_save | |
before_create | |
- create | |
after_create | |
after_save |
Reserved Words: | |
ADDITIONAL_LOAD_PATHS | |
ARGF | |
ARGV | |
ActionController | |
ActionView | |
ActiveRecord | |
ArgumentError | |
Array |
class Model < ActiveRecord::Base | |
attr_accessible :value, :other_value | |
default_scope | |
# ================= | |
# = RELATIONS = | |
# ================= | |
# ================= | |
# = CALLBACKS = |
require "benchmark" | |
n = 5000000 | |
Benchmark.bmbm do |x| | |
x.report("while:") { i = 1; while i < n do; a = "1 and #{i}"; i += 1; end } | |
x.report("for loop:") { for i in 1..n; a = "1 and #{i}"; end } | |
x.report("times:") { n.times do |i| ; a = "1 and #{i}"; end } | |
x.report("upto:") { 1.upto(n) do |i| ; a = "1 and #{i}"; end } | |
x.report("until:") { i = 1; until i > n do; a = "1 and #{i}"; i += 1; end } |
// How make the ActionBar title clickable on Android under API 11 (1/2) | |
private static final boolean API_LEVEL_UNDER_11 = android.os.Build.VERSION.SDK_INT < 11; | |
private boolean navigationDrawerEnabled = true; // Useful if your app need navigation drawer | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
if (API_LEVEL_UNDER_11) { | |
getSupportActionBar().setCustomView(R.layout.partial_actionbar); | |
getSupportActionBar().setDisplayShowCustomEnabled(true); |
# Restrict access to website and fallback to password. | |
<Directory "/var/sites/SITE/"> | |
AllowOverride All | |
AuthType Basic | |
AuthName "Restricted Files" | |
AuthUserFile /var/sites/SITE/.htpasswd | |
Require user | |
Order allow,deny | |
Allow from 127.0.0.1 | |
Satisfy Any |