Skip to content

Instantly share code, notes, and snippets.

View pablohdzvizcarra's full-sized avatar
🛏️
Need Sleep

Pablo Hernandez pablohdzvizcarra

🛏️
Need Sleep
View GitHub Profile
@pablohdzvizcarra
pablohdzvizcarra / Test.java
Created March 22, 2025 14:06
How to test if a test does not throws an exception in Java
package com.github.pablohdzvizcarra.lesson28;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MethodValidatorTest {
@Test
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
public class Example4 {
public static void main(String[] args) {
String filePath = "data.txt";
int bufferSize = 100; // number of bytes
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Example3 {
public static void main(String[] args) {
String filePath = "data.txt";
try {
byte[] contentBytes = Files.readAllBytes(Paths.get(filePath));
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Example2 {
public static void main(String[] args) {
String filePath = "data.txt";
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class Example1 {
public static void main(String[] args) {
String filePath = "data.txt";
try {
@pablohdzvizcarra
pablohdzvizcarra / data.txt
Last active March 8, 2025 19:31
How to read the content of a file with Java text file
1.The angel from my nightmare
2.The shadow in the background of the morgue
3.The unsuspecting victim of darkness in the valley
4.We can live like Jack and Sally, if we want
5.Where you can always find me
6.And we'll have Halloween on Christmas
7.And, in the night, we'll wish this never ends
8.We'll wish this never ends.
@pablohdzvizcarra
pablohdzvizcarra / BinarySortStrange.java
Created February 6, 2025 13:09
Strange binary sort algorithm implementation, very weird
class Solution {
public int search(int[] nums, int target) {
int left = 0;
int right = nums.length - 1;
int result = -1;
int n = nums.length;
while (n >= 1) {
int middle = (left + right) / 2;
if (target == nums[middle]) {
@pablohdzvizcarra
pablohdzvizcarra / docker-compose.yml
Created September 19, 2024 13:24
Docker compose file to override the default configuration for Apache airflow running with the astro CLI too.l
version: "3.1"
services:
webserver:
networks:
- ndsnet
scheduler:
networks:
- ndsnet
@pablohdzvizcarra
pablohdzvizcarra / create_mysql_connection.py
Created August 27, 2024 02:52
Python application to perform common operations in a SQL database using the mysql.connector client library
import mysql.connector
from mysql.connector import Error, MySQLConnection
def create_connection() -> MySQLConnection:
try:
connection: MySQLConnection = mysql.connector.connect(
host="",
database="example",
user="admin",
@pablohdzvizcarra
pablohdzvizcarra / ChapterTwoExercises.java
Created May 5, 2024 05:19
Binary Search and other algorithms implementations
public class ChapterTwoExercises {
/*
* Binary search implementation, to know the steps necessary only double the
* elements and plus 1
* Array 3 = 2 steps
* Array 7 = 3 steps
* array 15 = 4 steps
* array 31 = 5 steps
* array 63 = 6 steps