Skip to content

Instantly share code, notes, and snippets.

Allen Bargi aziz

  • Gothenburg, Sweden
Block or report user

Report or block aziz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aziz
aziz / snippet.js
Created Sep 28, 2011 — forked from necolas/snippet.js
Optimise DOM insertion of cross-domain scripts
View snippet.js
( 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 Sep 23, 2011
jQuery Image Wrapper
View jquery.image_wrapper.js
$(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");
});
});
View manage_debug.js
//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 Jun 19, 2011
cancel link helper
View cancel.rb
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 Jun 11, 2011
ruby Array: in_coulmns
View snippet.rb
class Array
def in_columns(count)
in_groups_of(count).transpose.collect(&:compact)
end
end
@aziz
aziz / soft-scroll.js
Created Jun 10, 2011
Soft-scroll to an anchor with jQuery
View soft-scroll.js
$('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 Jun 9, 2011
Often used regular expressions
View snippet.rb
# 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 — forked from alexyoung/deploy.sh
Deployment script
View deploy.sh
#!/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
in_cluomns Array monkey patck
View in_cluomns.rb
class Array
def in_columns(count)
in_groups_of(count).transpose.collect(&:compact)
end
end
View act as taggable case insensitive tags
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
You can’t perform that action at this time.