Skip to content

Instantly share code, notes, and snippets.

View sergiolopes's full-sized avatar

Sérgio Lopes sergiolopes

View GitHub Profile
sergiolopes / gist:951186
Created May 2, 2011 04:49
Livros Kindle disponíveis para empréstimo
Alguns livros para Kindle que já li e tenho disponíveis para empréstimo pela Amazon. Só pedir :)
* JavaScript: The Good Parts
Douglas Crockford
* Smarter, Faster, Cheaper: Non-Boring, Fluff-Free Strategies for Marketing and Promoting Your Business
David Siteman Garland
sergiolopes / gist:1172716
Created August 26, 2011 04:46
Como causar um memory leak no Tomcat
// opcao1: ThreadLocal
new ThreadLocal<Object>().set(new Object(){});
// opcao2: Logger
Level customLevel = new Level("Meu Nivel Customizado", 555) {};
Logger.getLogger("teste").log(customLevel, "Log inocente");
// opcao3: Runtime
Runtime.getRuntime().addShutdownHook(new Thread() {});
sergiolopes /
Created September 12, 2011 00:45
Bastidores das análises dos Sites dos participantes do QCon SP
// "scriptizao" pra baixar os resultados depois de executados
public class DownloadResults {
public static void main(String[] args) throws FileNotFoundException {
Scanner results = new Scanner(new File("test-ids.txt"));
while (results.hasNextLine()) {
String[] result = results.nextLine().split("\\s+");
String testId = result[0];
String domain = result[1];
sergiolopes /
Created January 31, 2012 03:56
Shows lossy compression of a JPEG file. It just rotates an image 180 degrees a couple times. Using 100% quality it's still a lossy format.
# Params:
# - original filename
# - number of 180 degrees rotations
cp $1 degradated.jpg
for ((i=1; i <= $2 ; i++)); do
convert degradated.jpg -quality 100 -rotate 180 temp.jpg
mv temp.jpg degradated.jpg
sergiolopes /
Created February 28, 2012 21:57
Pure CSS fix to iOS zoom bug on device rotation

My approach to fix the iOS bug is documented here:

Here I present one experiment with a pure CSS solution, no JS required. It uses width=device-width normally (no device-height hacking) and scales down the page on landscape.

Works fine on all iOS versions.

There's only one problem: on old iOS versions (prior to 4.3.5), the page will get a big empty space at bottom, below the content, when on landscape. Recent iOS versions don't show this behavior.

sergiolopes /
Created March 2, 2012 21:47
Runs iOS 5 simulator with MobileSafari remote debug
# Open iPhone Simulator on default location for XCode 4.3
open /Applications/\
# Open mobile safari
echo Open mobile safari on emulator and press return
# Plug debug to
public class VRaptorExtension implements Extension {
public <T> void processAnnotatedType(@Observes ProcessAnnotatedType<T> pat) {
Class<T> clazz = pat.getAnnotatedType().getJavaClass();
if (clazz.isAnnotationPresent(Resource.class)) {
System.out.println("Found an @Resource" + clazz.getName());
sergiolopes / context.xml
Created April 23, 2012 07:08
Arquivo de configuração do Weld no Tomcat (crie dentro da pasta META-INF)
<?xml version="1.0" encoding="UTF-8"?>
<Manager pathname=""/> <!-- disables storage of sessions across restarts -->
<Resource name="BeanManager"
sergiolopes / web.xml
Created April 23, 2012 07:09
Configuração do Weld para um Servlet Container sem CDI - copie dentro do web.xml
sergiolopes / formulario.php
Created May 28, 2012 19:01
Página simples em PHP que mostra os parâmetros recebidos
<!doctype html>
<meta charset="utf-8">
<h1>Você enviou seu formulário com sucesso!</h1>