Skip to content

Instantly share code, notes, and snippets.

View deximat's full-sized avatar

Dejan Pekter deximat

  • Nordeus
  • Belgrade-Sombor, Serbia
View GitHub Profile
int count = 100000000;
int hits = 0;
Random random = new Random();
for (int i = 0; i < count; i++) {
final List<Integer> doors = new ArrayList<>();
doors.add(0);
doors.add(1);
doors.add(2);
private static void rotate(int[] array, int r) {
reverse(array, 0, array.length);
reverse(array, 0, r);
reverse(array, r + 1, array.length);
}
private static void reverse(int[] array, int start, int end) {
while (start < end) {
swap(array, start, end);
start++;
@deximat
deximat / concurrency.java
Created August 28, 2015 17:16
When will it stop?
public static void main(String[] args) {
Vector<Integer> v1 = new Vector<>();
Vector<Integer> v2 = new Vector<>();
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
while(true) {
System.out.println("T1 try" + i);
@deximat
deximat / enum_trick.java
Created August 19, 2014 19:52
Enum as immutable java objects.
package com.codlex.deximat.raf.third_year.web_programming.exam.project.part2.messages;
public enum CancelReservationResponse {
PASSENGER_DOESNT_EXIST("Reservation cancellation unssuccesful selected passinger doesn't exist."),
FLIGHT_DOESNT_EXIST("Reservation cancellation unssuccesful selected flight doesn't exist."),
RESERVATION_NOT_POSSIBLE_TOO_LATE("Reservations can't be canceled if flight is within next 24 hours."),
SUCCESS(null),
WRONG_FLIGHT("Reservation cancellation unssuccesful selected passinger isn't on flight.");
private String description;
@deximat
deximat / enum_trick
Created August 19, 2014 19:51
Simple trick to having fields in enums for immutable objects.
package com.codlex.deximat.raf.third_year.web_programming.exam.project.part2.messages;
public enum CancelReservationResponse {
PASSENGER_DOESNT_EXIST("Reservation cancellation unssuccesful selected passinger doesn't exist."),
FLIGHT_DOESNT_EXIST("Reservation cancellation unssuccesful selected flight doesn't exist."),
RESERVATION_NOT_POSSIBLE_TOO_LATE("Reservations can't be canceled if flight is within next 24 hours."),
SUCCESS(null),
WRONG_FLIGHT("Reservation cancellation unssuccesful selected passinger isn't on flight.");
private String description;