Skip to content

Instantly share code, notes, and snippets.

View sergiolopes's full-sized avatar

Sérgio Lopes sergiolopes

View GitHub Profile
@sergiolopes
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
http://www.amazon.com/gp/product/B0026OR2ZY/
* Smarter, Faster, Cheaper: Non-Boring, Fluff-Free Strategies for Marketing and Promoting Your Business
David Siteman Garland
http://www.amazon.com/gp/product/B004D4YO38/
@sergiolopes
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
sergiolopes / DownloadResults.java
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
sergiolopes / generation_loss.sh
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.
#/bin/bash
# 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
sergiolopes / README.md
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:

https://github.com/sergiolopes/ios-zoom-bug-fix

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
sergiolopes / ios5webdebug.sh
Created March 2, 2012 21:47
Runs iOS 5 simulator with MobileSafari remote debug
#!/bin/bash
# Open iPhone Simulator on default location for XCode 4.3
open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
# Open mobile safari
echo Open mobile safari on emulator and press return
read
# Plug debug to MobileSafari.app
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
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"?>
<Context>
<Manager pathname=""/> <!-- disables storage of sessions across restarts -->
<Resource name="BeanManager"
auth="Container"
type="javax.enterprise.inject.spi.BeanManager"
factory="org.jboss.weld.resources.ManagerObjectFactory"/>
</Context>
@sergiolopes
sergiolopes / web.xml
Created April 23, 2012 07:09
Configuração do Weld para um Servlet Container sem CDI - copie dentro do web.xml
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<resource-env-ref>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>
javax.enterprise.inject.spi.BeanManager
</resource-env-ref-type>
</resource-env-ref>
@sergiolopes
sergiolopes / formulario.php
Created May 28, 2012 19:01
Página simples em PHP que mostra os parâmetros recebidos
<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<h1>Você enviou seu formulário com sucesso!</h1>