Skip to content

Instantly share code, notes, and snippets.

View henriqueboaventura's full-sized avatar

Henrique Boaventura henriqueboaventura

View GitHub Profile
function type()
{
var str = text.substr(0, currentChar);
var last = str.substr(str.length -1, str.length);
if(last != '<' && last != '>' & last != '/') {
$("#consoleText").html(str);
}
currentChar++;
if(currentChar <= text.length)
{
@henriqueboaventura
henriqueboaventura / gist:1184046
Created August 31, 2011 16:53
Hacker News Algorhythm
<?php
function calculate_score($votes, $item_hour_age, $gravity=1.8) {
return ($votes - 1) / pow(($item_hour_age+2), $gravity);
}
@henriqueboaventura
henriqueboaventura / os_detection.js
Created May 10, 2012 01:17
Operational System detection
<script language="javascript" type="text/javascript">
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
</script>
@henriqueboaventura
henriqueboaventura / kohana_file_validation.php
Created June 18, 2012 19:03
Kohana file upload validation
<?php
$file = Validation::factory($_FILES);
$file->rules(
'curriculo',
array(
array(array('Upload', 'valid')),
array(array('Upload', 'not_empty')),
array('Upload::type', array(':value', array('jpg', 'png', 'gif')))
)
@henriqueboaventura
henriqueboaventura / .htaccess
Created July 4, 2012 12:22
.htaccess mobile redirect
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine On
# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]
# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
function validaCPF($cpf) {
$cpf = str_pad(ereg_replace('[^0-9]', '', $cpf), 11, '0', STR_PAD_LEFT);
if (strlen($cpf) != 11 || $cpf == '00000000000' || $cpf == '11111111111' || $cpf == '22222222222' || $cpf == '33333333333' || $cpf == '44444444444' || $cp
return false;
} else {
for ($t = 9; $t < 11; $t++) {
for ($d = 0, $c = 0; $c < $t; $c++) {
$d += $cpf{$c} * (($t + 1) - $c);
if (preg_match('/(iphone|android|webos|blackberry|ipod|ipad|mobile)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) {
header('Location: http://m.site.com/index.php?id='.$HTTP_GET_VARS["id"]);
}
<?php
<?php defined('SYSPATH') or die('No direct script access.');
class Form extends Kohana_Form{
public static function select_from_model($name, array $collection, array $config = null , $selected = NULL, array $attributes = NULL)
{
$base_config = array(
#!/bin/sh
echo 'gerando o dump dos bancos';
mysqldump --all-databases -h 127.0.0.1 -u root > /tmp/dump.sql
echo 'compactando o dump';
NOW=$(date +"%Y_%m_%d");
zip "backup_db_$NOW.zip" /tmp/dump.sql
echo 'removendo arquivos temporários';
<?php defined('SYSPATH') or die('No direct script access.');
//ie session bug-fix
header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');
// -- Environment setup --------------------------------------------------------
// Load the core Kohana class
require SYSPATH.'classes/Kohana/Core'.EXT;