Archives for category: snippet
javascript:$('#banner').remove(); $('#top, #player').width('auto');$('#capital').hide(); $('#application').css('margin-right',0);$(window).trigger('resize');

 

javascript:$('#banner').remove(); $('#top, #player').width('auto');$(window).trigger('resize');
javascript:$('#capital').hide();$('#application').css('margin-right',0);$(window).trigger('resize');
.shadow {
 
box-shadow: 0px 0px 6px rgba(0,0,0,0.3);
-webkit-box-shadow: 0px 0px 6px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 6px rgba(0,0,0,0.3);
-webkit-transition-duration: 0.2s;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
margin-bottom: 20px;
}
 
.shadow:hover {
box-shadow: 0px 0px 20px rgba(0,235,255,0.8);
-webkit-box-shadow: 0px 0px 20px rgba(0,235,255,0.8);
-moz-box-shadow: 0px 0px 20px rgba(0,235,255,0.8);
}

From Christian Heilmann. Nothing too fancy for those who are used to write jQ plugins, but nice to save it for reference…

var myApp = function(){
	var nome = 'Mauricio Wolff';
	var idade = 35;
 
	function insertPessoa(){
		// [...]
	}
 
	function updatePessoa(){
		// [...]
	}
 
	function setPessoa () {
		// [ usa insert ou update ]
	}
 
	function getPessoa () {
		// [...]
	}
 
	return{
		set: setPessoa,
		get: getPessoa
	}
}();
 
// Example usage:
myApp.get();

Sometimes I just like to write code in Python and PHP to compare them, and admire both…

Here’s a little code to find IP adressess inside strings (returned from a nslookup). The code is not optimal, but illustrate how both languages works. Just for some friday fun…

Python

 
Python 2.6.1 (r261:67515, Jul  7 2009,  23:51:51)
 [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
 Type "help", "copyright", "credits" or "license"  for  more information.
 
>>> a  = 'yahoo.com IN A 69.147.114.224 18774s  (05:12:54)'
>>> a += 'yahoo.com IN A 209.131.36.159 18774s  (05:12:54)'
>>> a += 'yahoo.com IN A 209.191.93.53  18774s  (05:12:54)'
>>> print a
 'yahoo.com IN A 69.147.114.224  18774s (05:12:54)yahoo.com IN A 209.131.36.159 18774s  (05:12:54)yahoo.com IN A 209.191.93.53  18774s (05:12:54)'
>>>; import re
>>> p = re.compile('(?:\d{1,3}\.){3}\d{1,3}')
>>>; p.findall(a)
 ['69.147.114.224', '209.131.36.159',  '209.191.93.53']
>>>

PHP

$a  = 'yahoo.com IN A 69.147.114.224 18774s (05:12:54)';
$a .= 'yahoo.com  IN A 209.131.36.159 18774s (05:12:54)';
$a .= 'yahoo.com  IN A 209.191.93.53  18774s (05:12:54)';
 
print $a;
 
/*
saida: yahoo.com IN A 69.147.114.224 18774s (05:12:54)yahoo.com IN A  209.131.36.159 18774s (05:12:54)yahoo.com IN A 209.191.93.53 18774s  (05:12:54)
*/
 
$re = '/(\d+).(\d+).(\d+).(\d+)/';
 
preg_match_all($re, $a, $matches);
 
var_dump($matches[0]); // saida 1
var_dump($matches); // saida 2
 
/*
saida 1:
 
array(3) {
  [0]=>
  string(14) "69.147.114.224"
  [1]=>
  string(14) "209.131.36.159"
  [2]=>
  string(13) "209.191.93.53"
}
 
saida 2:
 
array(5) {
  [0]=>
  array(3) {
    [0]=>
    string(14) "69.147.114.224"
    [1]=>
    string(14) "209.131.36.159"
    [2]=>
    string(13) "209.191.93.53"
  }
  [1]=>
  array(3) {
    [0]=>
    string(2) "69"
    [1]=>
    string(3) "209"
    [2]=>
    string(3) "209"
  }
  [2]=>
  array(3) {
    [0]=>
    string(3) "147"
    [1]=>
    string(3) "131"
    [2]=>
    string(3) "191"
  }
  [3]=>
  array(3) {
    [0]=>
    string(3) "114"
    [1]=>
    string(2) "36"
    [2]=>
    string(2) "93"
  }
  [4]=>
  array(3) {
    [0]=>
    string(3) "224"
    [1]=>
    string(3) "159"
    [2]=>
    string(2) "53"
  }
}
*/

Pedido: Fazer com que todos os links de uma determinada página sejam externos.

  • Abordagem 1: Alterar a classe em php, genérica, para ver se o link é externo e acrescentar o target; por regex.
  • Abordagem 2: Colocar no init.js
$("a[href^='http://']").attr("target","_blank");

E todo site fica assim; links externos, para fora!
Aff… que doce.

When I use Betterzip to uncompress a directory tree, it chmods the dirs with 700. Here’s the command to solve this:

find . -type d | xargs chmod 755

It finds all subdirectories and chmod’em to 755. Clever, isn’t it?

Desde que comecei a usar GIT acho svn clumsy… prefiro jogar os arquivos no dropbox, que ele guarda versões pra mim.

Agora resolvi detonar todos os .svn de um trabalho que estou fazendo. Chega de xalassa…

  1. criar um bash script básico para remover os .svn recursivos
  2. salvar no meu ~/bin e dar chmod +x
  3. rodar e ser feliz.
#!/bin/sh
echo “recursively removing .svn folders from”
pwd
rm -rf `find . -type d -name .svn`
#!/bin/sh
 
echo "recursively removing .svn folders from"
 
pwd
 
rm -rf `find . -type d -name .svn`