{{toc}}
- Use UTF-8. It’s 21 century, 8bit encodings dead now.
- Use 2 space indent, not tabs
- Use Unix-style line endings
- Keep lines not longer than 80 chars
require 'securerandom' | |
def find_secure_token | |
token_file = Rails.root.join('.secret_token') | |
if File.exist? token_file | |
File.read(token_file).chomp | |
else | |
token = SecureRandom.hex(64) | |
f = File.new(token_file, 'w') | |
f.write(token) |
class Time | |
def diff_to_i(from = nil) | |
from = Time.now if from.blank? | |
(from - self).to_i | |
end | |
def diff_to_words(from = nil) | |
diff = self.diff_to_i(from) | |
case diff |
var disableEmptyFormField = function (ele){ | |
ele.find('input,select').each(function () { | |
if ($(this).val() == '') { | |
$(this).attr("disabled", "disabled"); | |
} | |
}); | |
ele.find('button').attr("disabled", "disabled"); | |
$('.filter-manufacturers input[type="checkbox"]').removeAttr('checked'); | |
} |
foreach($this->Paginator->options['url']['?'] $ key => $val){ | |
if(empty($val)) | |
unset($this->Paginator->options['url']['?'][key]); | |
} |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteRule ^(downloads)($|/) - [L] | |
RewriteRule ^$ app/webroot/ [L] | |
RewriteRule (.*) app/webroot/$1 [L] | |
</IfModule> |
//Sorting using a column | |
usort($rows, function ($a, $b) { | |
return strcmp($a[0], $b[0]); | |
}) | |
//Redirect from www to non-www | |
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] | |
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] | |
//Redirect from non-www to www | |
RewriteCond %{HTTP_HOST} !^www\. | |
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L] |
$( '.basic-filter-options input[type="checkbox"]' ).click(function(e){ | |
$('.basic-filter-options input[type="checkbox"]').filter(':checked').not(this).removeAttr('checked'); | |
}); |
<?php | |
App::import('Inflector'); | |
class SluggableBehavior extends ModelBehavior | |
{ | |
private $_settings = array(); | |
function setup(&$model, $settings = array()) | |
{ |