Skip to content

Instantly share code, notes, and snippets.

View aziz's full-sized avatar

Allen Bargi aziz

  • Gothenburg, Sweden
View GitHub Profile
@aziz
aziz / manage_debug.js
Created July 30, 2011 10:24
Manage Debug
//Call this function after body load
function manageDebug(){
var debug = false;
if(window.console){
var consoleBackUp = window.console.log;
window.console.log = function(str){
if(debug){
consoleBackUp.call(this,str);
}
}
@aziz
aziz / cancel.rb
Created June 19, 2011 18:41
cancel link helper
module ApplicationHelper
include Rails.application.routes.url_helpers
def cancel_link
return link_to 'Cancel', request.env["HTTP_REFERER"],
:class => 'cancel',
:confirm => 'Are you sure? Any changes will be lost.'
end
end
@aziz
aziz / snippet.rb
Created June 11, 2011 23:18
ruby Array: in_coulmns
class Array
def in_columns(count)
in_groups_of(count).transpose.collect(&:compact)
end
end
@aziz
aziz / soft-scroll.js
Created June 10, 2011 08:07
Soft-scroll to an anchor with jQuery
$('a[href^="#"][data-animate]').live('click', function() {
var hash = $(this).attr('href');
var offset = $(hash).offset();
if (offset) {
$('html, body').animate({ scrollTop: offset.top }, 'slow');
location.hash = hash;
return false;
}
});
@aziz
aziz / snippet.rb
Created June 9, 2011 19:33
Often used regular expressions
# Often used regular expressions - Cheatsheet
EMAIL = /\A[a-z0-9\+\-_\.]+@[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\z/i
HOST = /\A[a-z0-9]+[a-z0-9\-\.]*[a-z0-9]+\z/i
URL = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)*([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/
HEX_COLOR = /\A([a-fA-F0-9]{3}){1,2}\z/
@aziz
aziz / deploy.sh
Created May 18, 2011 22:25 — forked from alexyoung/deploy.sh
Deployment script
#!/usr/bin/env bash
# Configuration
SERVER='myserver'
DEPLOY_TO='/path/to/app'
EXCLUDE='*.swp .git/ db/sphinx/ tmp/ log/'
DRY_RUN=false
DEPLOY_GEM_PATH='/opt/ec/ruby/1.8.7/lib/ruby/gems/1.8'
module ActsAsTaggableOn
class Tag < ::ActiveRecord::Base
def self.named_any(list)
where(list.map { |tag| sanitize_sql(["LOWER(name) #{like_operator} LOWER(?)", tag.to_s.downcase]) }.join(" OR "))
end
end
end
module ActsAsTaggableOn::Taggable
module Core
@aziz
aziz / in_cluomns.rb
Created May 16, 2011 09:44
in_cluomns Array monkey patck
class Array
def in_columns(count)
in_groups_of(count).transpose.collect(&:compact)
end
end
@aziz
aziz / devise.fa.yml
Created April 26, 2011 14:48 — forked from rezb/devise.fa.yml
Persian (fa) translations for Devise (https://github.com/plataformatec/devise/wiki/I18n)
fa:
errors:
messages:
not_found: "یافت نشد"
already_confirmed: "قبلا تایید شده است"
not_locked: "قفل نشده است"
not_saved:
one: "۱ خطا جلوی ذخیره %{resource} را گرفت:"
other: "%{count} خطا جلوی ذخیره این %{resource} را گرفت:"
# The following initializer provides an :alias => "my_route_name" option to restful routes in your
# route.rb. This simply makes the same route also available under a different …_path / …_url helpers.
# For example,
# map.resources :notes, :alias => :snippets
# Gives you
# notes_path, notes_url, new_note_path... #as always