This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis.clients.jedis.Jedis; | |
public class RedisCacheExemplo { | |
public static void main(String[] args) { | |
// Conecta ao servidor Redis local | |
Jedis jedis = new Jedis("localhost"); | |
// Armazena dados no cache com uma chave e um valor | |
jedis.set("chave", "dados"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.util.concurrent.RateLimiter; | |
public class RateLimitingExample { | |
private static final RateLimiter rateLimiter = RateLimiter.create(10); // 10 solicitações por segundo | |
public static void main(String[] args) { | |
for (int i = 0; i < 20; i++) { | |
if (rateLimiter.tryAcquire()) { | |
System.out.println("Solicitação " + (i + 1) + ": Processada"); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableWebSecurity | |
public class SecurityConfig extends WebSecurityConfigurerAdapter { | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http | |
.authorizeRequests() | |
.antMatchers("/api/**").authenticated() | |
.and() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
@RequestMapping("/api") | |
public class ApiController { | |
@GetMapping | |
public String singleEntryPoint() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
public interface Componente { | |
void operacao(); | |
} | |
public class Folha implements Componente { | |
@Override | |
public void operacao() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EncapsulationExample { | |
private int data; | |
public int getData() { | |
return data; | |
} | |
public void setData(int data) { | |
this.data = data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
public class ProgramaConcorrenteParalela { | |
public static void main(String[] args) { | |
// Cria um pool de threads com 5 threads | |
ExecutorService executor = Executors.newFixedThreadPool(5); | |
// Submete tarefas para execução |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Button; | |
import javafx.scene.layout.StackPane; | |
import javafx.stage.Stage; | |
public class ProgramaEventos extends Application { | |
@Override | |
public void start(Stage primaryStage) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class OitoRainhas { | |
private static final int N = 8; // Tamanho do tabuleiro | |
public static void main(String[] args) { | |
int[][] tabuleiro = new int[N][N]; | |
if (resolverOitoRainhas(tabuleiro, 0)) { | |
imprimirTabuleiro(tabuleiro); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Predicado para verificar se uma rainha pode ser colocada em uma posição. | |
pode_colocar(_, []). | |
pode_colocar(Rainha, [Coluna/Linha|OutrasRainhas]) :- | |
Rainha #\= Linha, | |
Rainha + Coluna #\= Linha, | |
Rainha - Coluna #\= Linha, | |
pode_colocar(Rainha, OutrasRainhas). | |
% Predicado principal para posicionar as oito rainhas. | |
oito_rainhas([], []). |
NewerOlder