Skip to content

Instantly share code, notes, and snippets.

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

Randy Hector Bartumeu Huergo randyhbh

🏠
Working from home
  • Hamburg, Germany
View GitHub Profile
@randyhbh
randyhbh / startup.md
Created October 30, 2023 07:41 — forked from dsyer/startup.md
Notes on Spring Boot startup performance

Anatomy of Spring Boot Start Up Timing

When a Spring Boot app starts up with default (INFO) logging, there are some noticeable gaps (pauses). It's worth focusing on the gaps when looking for efficiency savings because of the amount of time they take, and because no-one bothered to log anything, so the chances are the app is doing something repetitive. We can tweak the logging levels to try and fill in the gaps and find out what is going on in there.

Basic empty web app with actuators has three such gaps:

0                                                                        1410ms
|------|---------------------------|-----|------|---------|--------|--------|
       |           578             |     |144(5)|         | 133(6) |
@randyhbh
randyhbh / ArrayManipulation.java
Created December 19, 2018 01:13
This solution applying array differences; Instead of storing the actual values in the array, you store the difference between the current element and the previous element.
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
String[] nm = scanner.nextLine().split(" ");
int n = Integer.parseInt(nm[0]);
int m = Integer.parseInt(nm[1]);
int[][] queries = new int[m][3];
@randyhbh
randyhbh / MinimumSwaps.java
Created December 18, 2018 23:35
Return an integer representing the minimum number of swaps to sort the array.
public class Main {
public static void main(String[] args) {
int [] a = new int[]{4,3,1,2};
minimumSwaps(a);
}
static int minimumSwaps(int[] arr) {
int swapsCount = 0;
int arraySize = arr.length;
@randyhbh
randyhbh / MinimumBribes.java
Created December 18, 2018 22:39
This method is the answer to the problem of "New Year's Chaos" in which he receives an int [] and must answer how many bribes there have been; If a person bribes more than 2 times it is total chaos.
static void minimumBribes(int[] q) {
int ans=0;
for(int i=q.length -1; i >= 0 ; i--) {
if (q[i] - (i+1) > 2) {
System.out.println("Too chaotic");
return;
}
for (int j = Integer.max(0, q[i] - 2); j < i; j++)
if (q[j] > q[i]) ans++;
@randyhbh
randyhbh / RotateLeftArray.java
Created December 18, 2018 20:42
A left rotation operation on an array shifts each of the array's elements 1 unit to the left.
static int[] rotLeft(int[] a, int d) {
int [] rotated = new int[a.length];
for (int i = 0; i <= a.length - 1; i++) {
rotated[i] = a[(i + d) % a.length];
}
return rotated;
}
@randyhbh
randyhbh / AmountOfLetter.java
Last active December 18, 2018 20:40
Find the amount of letter X inside the String Y
static int amountOfLetter(String chain, char letter) {
return chain.chars().mapToObj(i -> (char) i).filter(character -> character.equals(letter))
.collect(Collectors.toList()).size();
}
@randyhbh
randyhbh / buttonAnimationExtension.swift
Created October 16, 2017 00:28 — forked from SAllen0400/buttonAnimationExtension.swift
Core Animation on UIButton Example
// Swift 3
extension UIButton {
func pulsate() {
let pulse = CASpringAnimation(keyPath: "transform.scale")
pulse.duration = 0.6
pulse.fromValue = 0.95
pulse.toValue = 1.0