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 / snippet.js
Created September 28, 2011 21:03 — forked from necolas/snippet.js
Optimise DOM insertion of cross-domain scripts
( function ( win, doc ) {
// Google Analytics global variable
win._gaq = [ ['_setAccount','UA-XXXXX-X'], ['_trackPageview'], ['_trackPageLoadTime'] ];
// Array of cross-domain script urls
var urls = [
'//connect.facebook.net/en_US/all.js', // Facebook SDK
'//platform.twitter.com/widgets.js', // Twitter Widgets
'https://apis.google.com/js/plusone.js', // Google +1 Button
@aziz
aziz / jquery.image_wrapper.js
Created September 23, 2011 12:47
jQuery Image Wrapper
$(document).ready(function(){
$("img").load(function() {
$(this).wrap(function(){
return '<span class="image-wrap ' + $(this).attr('class') + '" style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
});
$(this).css("opacity","0");
});
});
@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\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?/
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'
@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
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