Skip to content

Instantly share code, notes, and snippets.

View Felipe00's full-sized avatar
😤
Banzai!

Felipe Costa Felipe00

😤
Banzai!
  • SulAmérica
  • Brazil - PI
View GitHub Profile
@Felipe00
Felipe00 / MyController.java
Last active March 19, 2018 11:53
Exemplo de autenticação Play Framework 2.6 +
import meu_pacote.UserAuthenticator;
import play.mvc.Controller;
import play.mvc.Security;
@Security.Authenticated(UserAuthenticator.class)
public class MyController extends Controller {
// Todos os métodos estarão sujeitos ao Autenticator
}
@Felipe00
Felipe00 / Authenticator.java
Created March 9, 2018 22:46
Exemplo de Authenticator play framework. Colocar na raiz do módulo (dentro da pasta app).
import controllers.SecuredController;
import play.mvc.Http;
import play.mvc.Result;
import play.mvc.Security;
import java.util.Optional;
public class Authenticator extends Security.Authenticator {
public static final String ID_SESSION = "id_session"; // eu coloco o email ou um código
@Felipe00
Felipe00 / SeuController.java
Last active January 22, 2018 17:12 — forked from anonymous/LoginForm.java
Chamando um método do Controller através da View - Play framework
public class SeuController extends Controller {
public Result login() {
System.out.println("Chamando meu método java");
// Aqui vc faz algo...
// retorno pra view...
return ok();
}
@Felipe00
Felipe00 / ConsultarLista.java
Last active December 30, 2017 01:07
Dúvida: Como retornar uma lista de um objeto Foo, com base no type da list Doo?
class Foo {
public static Finder<Long, Foo> find = new Finder<>(Foo.class);
Long id;
String name;
List<Doo> dooList;
/* Retorna uma lista de objetos Foo pelo type de Doo */
public static List<Foo> getAllFoos(String type) {
@Felipe00
Felipe00 / PlayController.java
Last active November 29, 2017 19:42
Como usar threads e fazer a página aguardar a requisição ser finalizada. [CompletableFuture<Result> , Firebase]
/** This method was called by Play! through the some tag in the html */
public CompletableFuture<Result> submit() {
auth = FirebaseAuth.getInstance(app);
final Form<LoginForm> filledForm = loginForm.bindFromRequest();
return signIn(filledForm);
}
private CompletableFuture<Result> signIn(Form<LoginForm> filledForm) {
final CompletableFuture<Result> resultFuture = new CompletableFuture();
@Felipe00
Felipe00 / DialogBuilder.java
Created May 25, 2017 20:35
Generic dialog with a button and a text
public class DialogBuilder {
/**
* Cria um diálogo com uma mensagem personalizada
*
* @param context
* @param message
*/
public static void createGenericErrorDialog(Context context, String message) {
final Dialog errorDialog = new Dialog(context);
@Felipe00
Felipe00 / ExemploSuperClass.java
Created May 4, 2017 14:24
Exemplo de uso de herança
class Monster extends Enemy {
private String monsterName;
protected void monsterfy() {
this.monsterName = "Monster " + getRandomId(); // comando qualquer
}
}
class People extends Monster {
// quando a classe for criada, eu quero que o método monsterfy() execute como um "init()"
@Felipe00
Felipe00 / activity_main.xml
Created April 29, 2017 00:45
Ajuda pro Arleyde. Viewpager com título.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3F3F4"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
@Felipe00
Felipe00 / Exemplo_page.java
Created April 28, 2017 11:04
Exemplo de interação com a troca de abas do ViewPager
// Verifico se é a aba de produtos e, caso seja, troco o menu da toolbar
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
// Verifico se é a aba de produtos
@Felipe00
Felipe00 / Dude.kt
Last active April 14, 2018 05:30
Lambda use cases. Simple example.
public class Dude {
// Easy way ¬¬ april, 14 2018
fun main(args: Array<String>) {
lambdaCall({
System.out.println(it)
})
}