Skip to content

Instantly share code, notes, and snippets.

View fabiancarlos's full-sized avatar
🚀
Go!

Fabian Carlos fabiancarlos

🚀
Go!
View GitHub Profile
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@fabiancarlos
fabiancarlos / subir.js
Created June 21, 2012 15:29
Pequeno script para subir para topo (JS)
//element - elemento que ao clicar, sobe ao topo automaticamente e suavamente ex: $('#subir')
function subirSuavemente(element){
"use strict";
element.click(function(event){
$('html, body').animate({scrollTop:0}, 'slow');
event.preventDefault();
});
}
@fabiancarlos
fabiancarlos / web.config
Created July 19, 2012 20:01
Kohana 3.2 URL Rewrite of the IIS 7/Windows 2008 **using conversor of .htaccess to web.config
<!--# link: http://learn.iis.net/page.aspx/470/importing-apache-modrewrite-rules/ -->
<configuration>
<system.webServer>
<rewrite>
<rules>
<!--# Turn on URL rewriting-->
<!--# Protect hidden files from being viewed-->
<!--# Protect application and system files from being viewed-->
<rule name="Imported Rule 9" stopProcessing="true">
<match url="^(?:application|modules|system)\b.*" ignoreCase="false" />
@fabiancarlos
fabiancarlos / email_utf8.md
Created July 23, 2012 14:34
force utf-8 mail
function mail_utf8($to, $subject = '(No subject)', $message = '', $header = '') {
  $header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header);
}
@fabiancarlos
fabiancarlos / set-value.md
Created July 28, 2012 22:04 — forked from JeffreyWay/set-value.md
PHP: Set value if not exist

You know how, in JavaScript, we can set a value to a variable if one doesn't, like this:

name = name || 'joe';

This is quite common and very helpful. Another option is to do:

name || (name = 'joe');
@fabiancarlos
fabiancarlos / for_utf8.php
Created August 6, 2012 01:27
Force charset utf8
<?php
mysql_connect("$hostname_config", "$username_config", "$password_config") or die(mysql_error());
$db = mysql_select_db("$database_config") or die(mysql_error());
mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');
@fabiancarlos
fabiancarlos / gist:3408185
Created August 20, 2012 21:46
camel_case.js
function toCamelCase(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(letter, index) {
return index == 0 ? letter.toUpperCase() : letter.toLowerCase();
}).replace(/\s+/g, ' ');
}
@fabiancarlos
fabiancarlos / estados_cidades.sql
Created August 23, 2012 20:38
triggerPopulaCidade.js
--
-- Estrutura da tabela `estados`
--
CREATE TABLE IF NOT EXISTS `estados` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nome` varchar(60) DEFAULT NULL,
`sigla` varchar(5) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='<double-click to overwrite multiple objects>' AUTO_INCREMENT=28 ;
@fabiancarlos
fabiancarlos / percentil.sql
Created August 28, 2012 22:37
Percentil mysql
select floor(20/100*(count(*))) as min, floor(80/100*(count(*))) as max
from produto
order by valor
limit min, max;
select min, max
from (SELECT valor, floor(20/100*(count(*))) as min, floor(80/100*(count(*))) as max FROM produto group by fornecedor_id) produto
order by valor
limit 0, 4;
SET @_mediaGlobal := (SELECT AVG(valor) FROM produto ORDER BY valor);
SET @dp := (SELECT (STDDEV(valor)/2) as dp FROM produto ORDER BY valor);
select (@_mediaGlobal - @dp) as min, (@_mediaGlobal + @dp) as max, @dp, @_mediaGlobal, AVG(valor) as mediaReal from produto where valor >= (@_mediaGlobal - @dp) and valor <= (@_mediaGlobal + @dp) order by valor;