Skip to content

Instantly share code, notes, and snippets.

View marcospereira's full-sized avatar
🏠
Working from home

Marcos Pereira marcospereira

🏠
Working from home
View GitHub Profile
@marcospereira
marcospereira / praquenao.rb
Created June 2, 2011 20:32
"pra que o que" generator
hein = ["pra que", "por que", "pra quem", "pra quando", "pra onde"]
hein.each do |olha_so|
hein.shuffle.each do |shhhh|
puts "#{olha_so} que tu #{shhhh}?"
end
end
@marcospereira
marcospereira / Unique.java
Created November 3, 2011 09:22
Unique validation for Play!Framework
package utils.validation;
import java.lang.annotation.Target;
import java.lang.annotation.Retention;
import java.lang.annotation.ElementType;
import java.lang.annotation.RetentionPolicy;
import net.sf.oval.configuration.annotation.Constraint;
@Retention(RetentionPolicy.RUNTIME)
@marcospereira
marcospereira / Bootstrap.java
Created January 23, 2012 00:48
Initialize and register Jasypt Encryptor
package utils.jobs;
import java.util.List;
import play.Play;
import play.Logger;
import play.jobs.Job;
import play.test.Fixtures;
import play.jobs.OnApplicationStart;
public class Article extends Model {
public static List<Article> recents(int limit) {
return Article.find("order by publishedAt desc").fetch(limit);
}
public static Article mostPopular() {
return Article.find("order by views desc").first();
}
@marcospereira
marcospereira / Conta.java
Created January 26, 2012 16:58
Como remover a anemia do seu código
// anemica
public class Conta {
private BigDecimal saldo;
private String numero;
private String agencia;
public Conta(BigDecimal saldo, String numero, String agencia) {
this.saldo = saldo;
this.numero = numero;
@marcospereira
marcospereira / Roteiro.md
Last active June 24, 2017 22:30
Roteiro Recife & Olinda

Pernambuco

Roteiro para Recife, Olinda e Porto de Galinhas.

Porto de Galinhas

Porto de Galinhas vale mais a pena se a maré estiver baixa. Abaixo de 0.5 está ok porque aí as piscinas naturais ficam visíveis e, se a maré ficar mais baixa ainda, dá até para ir a pé. Vocês podem ver a tabua de marés de novembro aqui (escolha PORTO DE SUAPE):

http://www.mar.mil.br/dhn/chm/box-previsao-mare/tabuas/index.htm

@marcospereira
marcospereira / Application.scala
Created February 27, 2016 13:30
Play controller using a custom logger
package controllers
import play.api.Logger
import play.api.mvc._
class Application extends Controller {
lazy val logger = Logger(classOf[Application])
def index = Action { implicit request =>
@marcospereira
marcospereira / compiler-stacktrace.txt
Created January 13, 2017 17:08
Weird error while compiling Play code
[warn] an unexpected type representation reached the compiler backend while compiling HttpRequestHandler.scala: <error>. If possible, please file a bug on issues.scala-lang.org.
scala.MatchError: <error> (of class scala.reflect.internal.Types$ErrorType$)
at scala.tools.nsc.backend.jvm.BTypesFromSymbols.typeToBType(BTypesFromSymbols.scala:212)
at scala.tools.nsc.backend.jvm.BTypesFromSymbols.$anonfun$methodBTypeFromMethodType$1(BTypesFromSymbols.scala:147)
at scala.tools.nsc.backend.jvm.BTypesFromSymbols.methodBTypeFromMethodType(BTypesFromSymbols.scala:147)
at scala.tools.nsc.backend.jvm.BTypesFromSymbols.methodBTypeFromSymbol(BTypesFromSymbols.scala:137)
at scala.tools.nsc.backend.jvm.BTypesFromSymbols.$anonfun$buildInlineInfoFromClassSymbol$5(BTypesFromSymbols.scala:583)
at scala.collection.Iterator$$anon$11.nextCur(Iterator.scala:473)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:479)
at scala.collection.Iterator.foreach(Iterator.scala:929)
@marcospereira
marcospereira / thread.dump
Created February 9, 2017 21:31
Thread dump after running tests without forking
2017-02-09 13:30:19
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.121-b13 mixed mode):
"AsyncAppender-Worker-ASYNCSTDOUT" #619 daemon prio=5 os_prio=31 tid=0x00007fa1d1d36800 nid=0x19b0b waiting on condition [0x000070001af19000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000007749ceab0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
trait ResetDbSpec extends PlaySpec with BeforeAndAfterAll {
private def withTestDatabase[T](block: Database => T) = {
Databases.withDatabase(
driver = "com.mysql.jdbc.Driver",
url = "jdbc:mysql://localhost/test",
name = "mydatabase",
config = Map(
"user" -> "test",
"password" -> "secret"
)