Skip to content

Instantly share code, notes, and snippets.

@Macagare
Macagare / gist:4024294
Created November 6, 2012 12:08
MySQL: Create db and user
$ mysql -uroot -p
mysql> create database my_new_database;
mysql> grant all on my_new_database.* to new_user@localhost identified by 'my secret password';
mysql> flush privileges;
mysql> quit
@Macagare
Macagare / gist:4044440
Created November 9, 2012 08:28
Javascript: getInternetExplorerVersion()
/**
* Returns the version of Internet Explorer or a -1
* (indicating the use of another browser).
*/
function getInternetExplorerVersion()
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
@Macagare
Macagare / gist:4044474
Created November 9, 2012 08:35
Javascript: Lazy Loading Images
/*
ressource: http://css-tricks.com/snippets/javascript/lazy-loading-images/?utm_source=dlvr.it&utm_medium=twitter
*/
<img src="blank.gif" class="lazy" data-src="/images/full-size.jpg" width="240" height="152"></a>
/* lazyload.js (c) Lorenzo Giuliani
* MIT License (http://www.opensource.org/licenses/mit-license.html)
*
* expects a list of:
@Macagare
Macagare / gist:4046188
Created November 9, 2012 15:02
Javascript: jquery find parent
//Find a parent div by id where display is none:
/*
<div id="#extended_selectors"...>
...
<span id="lorem"... />
</div>
*/
if( $(id).parents().find("#extended_selectors").css('display') == "none" ) {
console.log("found");
}
@Macagare
Macagare / gist:4058163
Created November 12, 2012 08:32
Javascript: Class (using a function)
function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
}
// Or, this other way:
@Macagare
Macagare / gist:4058166
Created November 12, 2012 08:32
JavaScript: class (using object literals)
var apple = {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
}
}
@Macagare
Macagare / gist:4072116
Created November 14, 2012 13:40
Javascript: Script link with fallback
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="http://www.myurl.com/js/jquery-1.4.2.min.js">\x3C/script>')</script>
@Macagare
Macagare / gist:4099552
Created November 17, 2012 20:03
Javascript: Mobile detection
/**
* jQuery.browser.mobile (http://detectmobilebrowser.com/)
*
* jQuery.browser.mobile will be true if the browser is a mobile device
*
**/
(function(a){jQuery.browser.mobile=/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s
@Macagare
Macagare / gist:4123671
Created November 21, 2012 07:47
Javascript: Browser history back
<a href='#' onClick='window.history.go(-1);return false;'>BACK</a>
@Macagare
Macagare / Normalize
Created November 21, 2012 10:16 — forked from cybermarinella/Normalize
CSS: Normalize
/*! normalize.css 2012-03-11T12:53 UTC - http://github.com/necolas/normalize.css */
/* =============================================================================
HTML5 display definitions
========================================================================== */
/*
* Corrects block display not defined in IE6/7/8/9 & FF3
*/