Skip to content

Instantly share code, notes, and snippets.

View gcpantazis's full-sized avatar

George Pantazis gcpantazis

View GitHub Profile
@gcpantazis
gcpantazis / gist:1262062
Created October 4, 2011 16:14
Remove Dupes
// Provided an array, remove all duplicated items.
removeDuplicates : function(anArray) {
var a = anArray.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a[i] === a[j]) a.splice(j, 1);
}
}
return a;
@gcpantazis
gcpantazis / gist:1326312
Created October 30, 2011 19:25
IEMobile Conditional Comments
<!--[if IEMobile]>
<link rel="stylesheet" media="screen" href="styles/mobile_wp.css" />
<![endif]-->
@gcpantazis
gcpantazis / gist:1352640
Created November 9, 2011 19:28
Animating CSS3 transforms (and other non-numerics) with jQuery.
$elem.animate({
'customScale': someScaleValue
}, {
step: function(now, fx){
if ( fx.prop == 'customScale' ) {
$elem.css({
'-webkit-transform': 'scale('+now+')'
});
}
}
@gcpantazis
gcpantazis / gist:1383556
Created November 21, 2011 18:58
Embedding a script into the DOM
c = document.createElement('script');
c.type = 'text/javascript';
c.src = 'URL TO SCRIPT';
(document.getElementsByTagName('head')[0] || document.getElemntsByTagName('body')[0]).appendChild(c);
@gcpantazis
gcpantazis / gist:1642397
Created January 19, 2012 20:31
Basic (WAP, etc.) vs. Modern CSS, Mobile
<link rel="stylesheet" media="screen" href="basic.css" /> <!-- Everything -->
<link rel="stylesheet" media="screen and (min-device-width: 1px)" href="awesome.css" /> <!-- Modern -->
@gcpantazis
gcpantazis / gist:2305089
Created April 4, 2012 19:49
Custom class types for Backbone.js
var CustomClass = Backbone.CustomClass = function(options) {
this.cid = _.uniqueId('CustomClass');
this._configure(options || {});
this.initialize.apply(this, arguments);
};
var classOptions = ['attributes'];
_.extend(CustomClass.prototype, null, {
@gcpantazis
gcpantazis / gist:2865745
Created June 4, 2012 01:18
Array Shuffler [Randomly Efficient]
var y = [25, 8, 7, 41, 22, 11, 2, 1000];
var randomize = function(array) {
var output = [],
arrLen = array.length;
for ( var i = 0; i < array.length; i++ ) {
output[i] = false;
}
@gcpantazis
gcpantazis / gist:2866174
Created June 4, 2012 03:35
Sort strings and numbers.
var x = [1,3,'b',5,2,4,'a'];
x.sort(function(a,b){
if ( typeof a === typeof b ) {
return (a > b);
} else {
return typeof a > typeof b;
}
});
@gcpantazis
gcpantazis / gist:2871256
Created June 4, 2012 22:37
Add jQuery support for outerHTML, with feature detection
// Add support for outerHTML, which in FF was only added at version 11.
// Only use elem.outerHTML once support for FF<11 is no longer needed.
(function($){
$.fn.outerHTML = function() {
var a = this.get(0).outerHTML;
return a ? a : $('<p/>').append(this.clone()).html();
}
})(jQuery);
@gcpantazis
gcpantazis / gist:2961257
Created June 20, 2012 18:02
Opacity CSS
#foo { display: block; float: left;
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
filter:alpha(opacity=40);
opacity: 0.4;
}