Skip to content

Instantly share code, notes, and snippets.

View Chavao's full-sized avatar
💻
Coding...

Diego Chavão Chavao

💻
Coding...
View GitHub Profile
@Chavao
Chavao / git-server.sh
Created December 19, 2011 18:50
Configurar servidor Git
#!/bin/bash
# Os usuários precisam estar no grupo chamado git! (Configurar em /etc/group)
# Modo de usar:
# ./git-server.sh nome-do-projeto
mkdir $1
cd $1
git init --shared=group
git config --bool core.bare true
@Chavao
Chavao / robo.py
Created December 27, 2011 23:19
Ensinando programação para minha irmã com entrada e saída de informação através de um robozinho.
# -*- encoding: utf-8 -*-
class Robo:
def perguntar_filme(self):
self.filme = raw_input("Qual seu filme favorito? \n")
def comentar_sobre_o_filme(self):
print 'Caramba, esse filme ' + str(self.filme) + ' também é meu favorito!'
def perguntar_sobre_comida(self):
@Chavao
Chavao / gist:1943339
Created February 29, 2012 18:29
Old school AJAX object
var http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try { http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try { http_request = new ActiveXObject("Microsoft.XMLHTTP");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>sem título</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 0.19.1" />
<style>
@Chavao
Chavao / gist:1974142
Created March 4, 2012 17:54
Dado um valor em segundos, a função monta um contador no formato HH:MM:SS
function mountCounter(p_seconds)
{
var hours = new String(parseInt(parseInt(p_seconds) / 3600));
var minutes = new String(parseInt((p_seconds / 60) % 60));
var seconds = new String(parseInt(p_seconds % 60));
if(hours.length == 1) hours = '0' + hours;
if(minutes.length == 1) minutes = '0' + minutes;
if(seconds.length == 1) seconds = '0' + seconds;
@Chavao
Chavao / gist:1974196
Created March 4, 2012 18:08
Busca de endereço por CEP
<?
function getCEP($psCEP)
{
echo utf8_encode(urldecode(trim(@file_get_contents('http://cep.republicavirtual.com.br/web_cep.php?cep='.urlencode($psCEP).'&formato=javascript'))));
// Retorna var resultadoCEP = { 'uf' : 'UF', 'cidade' : 'Cidade', 'bairro' : 'Bairro', 'tipo_logradouro' : 'Avenida', 'logradouro' : 'Logradouro', 'resultado' : '1', 'resultado_txt' : 'sucesso - cep completo' }
}
?>
@Chavao
Chavao / gist:2089545
Created March 19, 2012 01:36
Uma solução que achei para tentar conexão em algum momento de instabilidade, dando até 5 segundos para desafogar e conseguir a conexão.
<?php
$i = 0;
while ($i++ < 5 && !$connected)
{
$connected = ($this->_resource = mysql_connect($host, $user, $password, true));
if(!$connected) {
sleep(1);
}
@Chavao
Chavao / gist:2344644
Created April 9, 2012 16:43
Exemplo de Strategy
<?php
interface IStrategy
{
public function mover();
public function falar();
}
class Strategy implements IStrategy {
private $objeto;
@Chavao
Chavao / gist:2485583
Created April 25, 2012 02:22
Remover todos os tweets que foram enviados como replies/mention.
$('.js-tweet-text').each(function() { if($(this).text().match(/^@/g)) $(this).closest('.tweet').remove(); });
var g_link_amigos = ['http://chav.in/1wh', 'http://chav.in/1CO'];
jQuery(function() {
jQuery(".link-amigos").attr('href', g_link_amigos[(Math.floor(Math.random()*g_link_amigos.length))]);
});