Skip to content

Instantly share code, notes, and snippets.

View netojoaobatista's full-sized avatar
💭
GitHub is not Orkut.

João Batista Neto netojoaobatista

💭
GitHub is not Orkut.
View GitHub Profile
@netojoaobatista
netojoaobatista / String.prototype.soundex.js
Created March 22, 2012 18:00
Implementação do algorítimo SoundEX em Javascript
/**
* Implementação do algorítimo SoundEx em Javascript.
* @author João Batista Neto
*
* SoundEX é um algorítimo fonético para indexação de nomes pelo som segundo
* sua pronúncia. O algorítimo foi desenvolvido por Robert C. Russell e
* Margaret K. Odell e patenteado em 1918 e 1922.
* {@link http://en.wikipedia.org/wiki/Soundex}
*
* @return {String}
@netojoaobatista
netojoaobatista / sample.html
Created April 10, 2012 12:37
Exemplo de comutação de classes CSS em Javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Sample</title>
<style type="text/css">
html { font-family: Helvetica,sans-serif; }
.horizontal > * {
float: left;
}
@netojoaobatista
netojoaobatista / brainfuck.js
Created April 18, 2012 17:16
A brainfuck programming language interpreter written in Javascript
var Context = function() {};
Object.defineProperty(Context,"create",{
writable: false, configurable: false, enumerable: true,
value: function(size,initializer) {
return Object.create(Context.prototype,(function(){
var data = (new Array(size?size:0)).join("|").split("|").map(
initializer||function(){}
);
var pointer = 0;
@netojoaobatista
netojoaobatista / jquery.unbindAll.js
Created April 20, 2012 15:11
Remove todos os manipuladores de eventos que foram anexados aos elementos
/**
* Removes all previously-attached event handlers from the elements.
*/
$.fn.unbindAll = function() {
var events = $(this).data('events');
return this.each( function() {
var $this = $(this);
for ( var evt in events ) {
@netojoaobatista
netojoaobatista / Proxy.create.js
Created April 25, 2012 19:16
Exemplo simples de uso da API antiga de ECMAScript Proxy
/**
* Um objeto de origem qualquer
*/
var o = { x: 10, y: 10 };
/**
* Criação do Proxy (API antiga).
* Cada uma dessas propriedades do proxy representa uma operação no objeto de origem; O proxy
* receberá a operação e delegará (ou não) para o objeto de origem.
*/
@netojoaobatista
netojoaobatista / class-tests.js
Created April 25, 2012 19:46 — forked from herberthamaral/class-tests.js
Simple, but effective JavaScript class system
describe("class system", function(){
it("should be possible to create classes", function(){
Class({name:'MyClass'});
expect(window.MyClass === undefined).toBeFalsy();
});
it("should be possible to create properties within classes", function(){
Class({
name:'MyClass',
attrs:{
@netojoaobatista
netojoaobatista / Date.prototype.diff.js
Created April 26, 2012 20:09
Returns the difference between two Date objects.
Object.defineProperty(Date.prototype,"diff",{
writable: false, configurable: false, enumerable: true,
/**
* Returns the difference between two Date objects.
* @param {Date} The date to compare to.
* @return {Object}
* @throws {TypeError}
*/
value: function(date) {
@netojoaobatista
netojoaobatista / gist:2783334
Created May 24, 2012 18:31
Promoção Dia do Orgulho Nerd / Dia da Toalha

Promoção Dia do Orgulho Nerd / Dia da Toalha

Para comemorar o Dia do Orgulho Nerd / Dia da Toalha, que é amanhã, dia 25 de maio, o iMasters preparou um kit super bacana pra você, nosso Nerd querido! Veja bem: camiseta, adesivos e bottons e uma toalha super exclusiva, comemorativa dos 10 anos do iMasters!

É fácil de participar: basta ser criativo e mandar uma foto com sua querida toalha (você está com ela aí, né? Ufa!) ou mandar uma frase bem bacana explicando porque você é nerd! Ah, tem que usar a hashtag #NerdMasters e mandar pra gente no twitter!

promoção dia do orgulho nerd

Prepare-se ponha essa cabeça inteligentíssima pra funcionar e boa sorte! As duas frases e as duas fotos mais legais vão ganhar esse kit especial!

@netojoaobatista
netojoaobatista / gist:2784286
Created May 24, 2012 21:17
Validação usando expressão regular para aceitar apenas letras minúsculas
<?php
/**
* Verifica se uma string é UTF-8
* @param string $string A string que será verificada
* @return boolean
*/
function is_utf8($string) {
return (bool) preg_match('%^(?:'.
'[\x09\x0A\x0D\x20-\x7E]|'.
'[\xC2-\xDF][\x80-\xBF]|'.
@netojoaobatista
netojoaobatista / gist:2876729
Created June 5, 2012 18:27
Espaço nos nomes das propriedades
<?php
$o = new stdClass();
$o->{' '} = 1;
$o->{' '} = 2;
$o->{' '} = 3;
var_dump($o);
/* Saída
* [neto@localhost ~]$ php -v