Skip to content

Instantly share code, notes, and snippets.

View edinella's full-sized avatar
🐝
“Nothing will work unless you do.” — Maya Angelou

Ezequias Dinella edinella

🐝
“Nothing will work unless you do.” — Maya Angelou
View GitHub Profile
@edinella
edinella / gist:3914322
Created October 18, 2012 19:38
Extract extension from filename
var filename = 'github.txt';
var extension = filename.split('.').pop();
@edinella
edinella / gist:4008209
Created November 3, 2012 18:32
Native fullscreen javascript api
addEventListener("click", function(){
var el = document.documentElement;
var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen;
rfs.call(el);
});
@edinella
edinella / gist:4512106
Created January 11, 2013 16:37
A JSON Vulnerability (http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx) allows third party web-site to turn your JSON resource URL into JSONP request under some conditions. To counter this your http://expressjs.com/ server can allow only xhr requisitions with this middleware.
app.all('/path/to/api/*', function xhrOnly(req, res, next) {
if (req.xhr) next();
else res.send(403, 'XHR requests only, please');
});
@edinella
edinella / gist:5006629
Created February 21, 2013 17:44
Generate random 16 chars string
Math.random().toString(36).substr(2,16);
@edinella
edinella / html_dentro_de_html.php
Last active December 15, 2015 17:09
Mostrando um HTML dentro de outro HTML, sem quebrá-lo
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<style type="text/css">
iframe#meuhtml{width:100%;border:0;}
</style>
<iframe src="about:blank" id="meuhtml"></iframe>
<?php
$html = "<h1>Atenção!</h1>\n<p>Texto com ' aspas simples</p>";
$html = str_replace(array("'", "\n"), array("\\'", "\\n"), $html);
@edinella
edinella / magic.php
Last active December 15, 2015 17:29
Using php magic setters and getters to validate object properties
<?php
date_default_timezone_set('America/Sao_Paulo');
/**
* Classe com filtros mágicos sobre as propriedades
*/
abstract class Magic {
/** @var array Propriedades */
private $_properties;
@edinella
edinella / toCamelCase
Created April 7, 2013 23:11
Converts a space separated string to camel case
function toCamelCase(str) {
return str.toLowerCase().replace(/(?:(^.)|(\s+.))/g, function(match) {
return match.charAt(match.length-1).toUpperCase();
});
}
@edinella
edinella / encoding_universal.php
Last active December 16, 2015 03:59
Detecta encoding de uma string, testando as opções informadas, com PHP4+ e iconv
<?php
/**
* Detecta encoding de uma string, testando as opções informadas
* @param string $string
* @param array $opcoes
* @return string|null
*/
function obtemEncoding($string, $opcoes=array('UTF-8', 'ISO-8859-1', 'WINDOWS-1251'))
{
<?php
/**
* Extrai e-mails de uma string, no padrão usado na estrutura de mensagens
* @param string $str
* @return array
*/
function emailsFromStr($str)
{
preg_match_all('/<([^>]*)>/', $str, $matches);
<?php
function verificadorDe($tipo){
return function($var) use($tipo) {
return gettype($var) == $tipo;
}
}
$verificaInteiro = verificadorDe('integer');
$verificaTexto = verificadorDe('string');