Skip to content

Instantly share code, notes, and snippets.

View fael's full-sized avatar

Rafael Santos Sá fael

  • OLX
  • Lisbon, Portugal
View GitHub Profile
@fael
fael / gist:1212446
Created September 12, 2011 21:10
Javascript Easter Egg - Konami Code
var kkeys = [],
konami = "38,38,40,40,37,39,37,39,66,65";
easterEgg = function (e) {
kkeys.push(e.keyCode);
if (kkeys.toString().indexOf(konami) == 0) {
var ee = $('<div id="ee">TROLOLOL</div>');
ee.css({
@fael
fael / gist:1217901
Created September 14, 2011 21:51
Load Firebug Lite when sequence "d e b u g" is typed
var hasFirebugLite = false;
runFirebug = function () {
if (!hasFirebugLite) {
$.getScript('https://getfirebug.com/firebug-lite.js', function () {
hasFirebugLite = true;
});
}
}
@fael
fael / gist:1234907
Created September 22, 2011 14:29
Drap And Drop Method
//copiei do http://petelepage.com/presentations/2011/gdd-br/webapps/helpers/dnd-lib.js
function habilitarDragAndDrop(id, thumbsId) {
var el_ = document.getElementById(id);
var thumbnails_ = document.getElementById(thumbsId);
this.dragenter = function(e) {
e.stopPropagation();
e.preventDefault();
el_.classList.add('dropHere');
@fael
fael / gist:1250715
Created September 29, 2011 13:20
Exemplo de Plugin em jQuery
jQuery.fn.extend({
reset : function() {
return jQuery(this).filter('form').each(function() {
return this.reset();
}).end();
}
});
$('form').bind('submit', function(e) {
@fael
fael / gist:1284764
Created October 13, 2011 16:50
Exemplo de um Revealing Module Pattern
var revealingModulePattern = function() {
var privateVar = 1;
function privateFunction() {
alert('private');
};
var publicVar = 2;
function publicFunction() {
@fael
fael / gist:1285003
Created October 13, 2011 18:16
Meu Module Design Pattern
/* Inspirado no post: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
Vantagens:
- Permitir a utilização de métodos/propriedades privadas.
- Adicionar metodos ou propriedades ao objeto ProjetoX a partir de outros arquivos js
Desvantagens:
- Como não é uma classe e em runtine eu não crio uma instância (new NAP()),
não é possível usar o this dentro de um método do objeto NAP
para invocar outro que também é método do objeto NAP.
@fael
fael / gist:1285038
Created October 13, 2011 18:28
Meu Antigo 'Object' Design Pattern
/* Vantagens:
- Organizador de métodos e propriedades, permite ser estendido por outros arquivos js.
- Utilizar um 'namespace' favorece o melhor consumo de memória (nos antigos IE).
Desvantagens:
- Como não é uma classe e em runtine eu não crio uma instância (new NAP()),
não é possível usar o this dentro de um método do objeto NAP
para invocar outro que também é método do objeto NAP.
*/
@fael
fael / gist:1296161
Created October 18, 2011 18:04
Another jQuery Pattern Plugin
(function ($) {
$.extend({ //plugins without context. e.g: $.plugin();
firebugLite: function () {
var vars = {
keys: [],
sequence: "68,69,66,85,71",
loaded: false,
serviceURL: 'https://getfirebug.com/firebug-lite.js'
};
@fael
fael / .htaccess
Created November 6, 2011 22:22
Exemplo PHPMailer + Tratamento de erros via HTACCESS + Qualquer console JS
# PHP error handling for production servers
# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
@fael
fael / gist:1345338
Created November 7, 2011 15:55
Exemplo de uso de Custom Types do WordPress
//gerado pelo http://themergency.com/generators/cpt-code-output/?id=8966
add_action( 'init', 'register_cpt_atividade' );
function register_cpt_atividade() {
$labels = array(
'name' => _x( 'Atividades', 'atividade' ),
'singular_name' => _x( 'Atividade', 'atividade' ),
'add_new' => _x( 'Adicionar Atividade', 'atividade' ),