Skip to content

Instantly share code, notes, and snippets.

View julianjupiter's full-sized avatar

Julian Jupiter julianjupiter

View GitHub Profile
@julianjupiter
julianjupiter / FruitsApp.java
Created February 1, 2024 11:41
Get fruits with highest count
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class FruitsApp {
public static void main(String[] args) {
var fruits = new String[] {
"Apple",
"Banana",
"Cherry",
@julianjupiter
julianjupiter / Scheduler.java
Last active September 26, 2023 10:20
Task scheduler in Java
package com.julianjupiter.scheduler;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class Scheduler {
private static final int DEFAULT_CORE_POOL_SIZE = 1;
private final ScheduledExecutorService scheduler;
@julianjupiter
julianjupiter / App.java
Created August 13, 2023 15:04
Read XML file from resources directory and deserialize it into POJO using Jackson
public class App {
public static void main(String[] args) {
record User(String id, String name) {}
var reader = XmlResourceReader.create(User.class);
// src/main/resources/files/user.xml
reader.read("files/user.xml")
.ifPresent(user -> System.out.pritnln(user.id() + " " + user.name()));
}
}
@julianjupiter
julianjupiter / TwoSum.java
Created October 20, 2022 05:42
Given an array of distinct integers and a target sum, find two numbers in the array that add up to the target sum.
public class TwoSum {
public static int[] twoSum(int[] a, int sum) {
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
int x = a[i];
int y = a[j];
if ((x + y) == sum) {
return new int[]{x, y};
}
}
@julianjupiter
julianjupiter / CsvApp.java
Created October 18, 2022 13:41
Create CSV file in Java
package app;
import com.julianjupiter.csv.CsvWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;
public class CsvApp {
public static void main(String[] args) throws IOException {
@julianjupiter
julianjupiter / bootstrap-collapse.html
Created October 31, 2021 17:14
Bootstrap Collapse
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<!-- CSS only -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css"
@julianjupiter
julianjupiter / TextFieldBinding.java
Last active October 20, 2022 05:43
JavaFX - MVVM - TextField Binding
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.stage.Stage;
@julianjupiter
julianjupiter / BCrypt.java
Last active May 22, 2020 18:01
BCrypt implements OpenBSD-style Blowfish password hashing using the scheme described in "A Future-Adaptable Password Scheme" by Niels Provos and David Mazieres. This password hashing system tries to thwart off-line password cracking using a computationally-intensive hashing algorithm, based on Bruce Schneier's Blowfish cipher. The work factor of…
// Copyright (c) 2006 Damien Miller <djm@mindrot.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@julianjupiter
julianjupiter / TestDatabaseSetup.md
Created March 2, 2020 08:48 — forked from gvenzl/TestDatabaseSetup.md
A script that sets up test databases for Oracle, MySQL, Postgres, SQL Server, and Db2
@julianjupiter
julianjupiter / FolderDelete.java
Created January 27, 2020 09:43
Delete directory with or without files
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
public class FolderDelete {
public static void main(String[] args) throws IOException {