eclipse being eclipse

 since 2006 I am using eclipse on and off, I am using intellij more in work but I dont have license for home so I decided to check eclipse back. I am trying to write some aspectj and installed the editor to latest eclipse and exception is

“AJCompilationUnit tried to access private field org.eclipse.jdt.internal.core.JavaElement.parent (org.eclipse.ajdt.core.javaelements.AJCompilationUnit is in unnamed module of loader “

 

decided to get latest from https://github.com/eclipse/org.aspectj/blob/master/docs/developer/IDE.md#eclipse

 

 and finally aj editor works

reorder an int as big as possible

 I found https://www.codewars.com/ and solving a algorithm question, reorder given number as big as possible, example given 123, ordered biggest version is 321, so we just need to order digits separately and concatenate them, I wrote 2 approaches

public void testStreamCode() {
int num = 123;
AtomicReference<String> str = new AtomicReference<>();
String.valueOf(num).chars().boxed().sorted(Collections.reverseOrder()).forEach(c -> str.updateAndGet(v -> v + (c - 48)));
int parseInt = Integer.parseInt(str.get().replaceAll("null", ""));
assert parseInt == 321;
}

public void testArraysSortCode() {
int num = 7657585;
char[] c = String.valueOf(num).toCharArray();
Arrays.sort(c);
String s = "";
for (int i = c.length - 1; i >= 0; i--)
s += c[i];
Integer integer = Integer.valueOf(s);
assert integer == 8776555;
}
then CW gave another solution
public void cw() {
int num = 7657585;
int i1 = Integer.parseInt(String.valueOf(num)
.chars()
.mapToObj(i -> String.valueOf(Character.getNumericValue(i)))
.sorted(Comparator.reverseOrder())
.collect(Collectors.joining()));
assert i1 == 8776555;
}

I know java stream api looks cool and I decided to benchmark this. here is the result
Benchmark                                Mode  Cnt  Score   Error  Units
DemoApplicationTests.cw avgt 2 0.808 us/op
DemoApplicationTests.testArraysSortCode avgt 2 0.194 us/op
DemoApplicationTests.testStreamCode avgt 2 0.884 us/op
 
fastest is using arrays.sort(0.194) second is CW and last one is "testStreamCode". 

jhipster login and how to call a rest api under

 In order to use jhipster user system I needed to find out how to call jhipster, I am planning to do this with curl because it is easiest way to test and see the results.

  curl -v https://xxx.herokuapp.com/api/authenticate -X POST -d '{"password":"xxxxx","username":"admin"}' -H 'Content-Type: application/json' 

 and result is {"id_token":"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTYzNDY2MDAwM30.1g_8nXgZfTITCfQgewLm8V6PnGKy5kx41dm9gbpJMltVARK8DJZBbbnI-VzQFFO1kkP-8wzVcsB-bvAaHGMPkA"}  

 now I will use this token to call another rest api 
curl "https://xxx.herokuapp.com/api/categories?page=0&size=20&sort=id,asc" -H 'Accept: application/json' -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfVVNFUiIsImV4cCI6MTYzNDY2MDAwM30.1g_8nXgZfTITCfQgewLm8V6PnGKy5kx41dm9gbpJMltVARK8DJZBbbnI-VzQFFO1kkP-8wzVcsB-bvAaHGMPkA'
 

 and result is [{"id":1051,"description":"Emlak","sortOrder":null,"dateAdded":null,"dateModified":null,"status":"AVAILABLE","picture":null,"propertyGroup":null,"parent":null,"advert":null},{"id":1052,"description":"Kiralik Evler","sortOrder":null,"dateAdded":null,"dateModified":null,"status":"AVAILABLE","picture":null,"propertyGroup":null,"parent":{"id":1051,"description":"Emlak","sortOrder":null,"dateAdded":null,"dateModified":null,"status":"AVAILABLE"},"advert":null},{"id":1053,"description":"Satilik Evler","sortOrder":null,"dateAdded":null,"dateModified":null,"status":"AVAILABLE","picture":null,"propertyGroup":null,"parent":{"id":1051,"description":"Emlak","sortOrder":null,"dateAdded":null,"dateModified":null,"status":"AVAILABLE"},"advert":null}]

download zipped/gz file and unzip and use in java

 Example code for downloading a zipped file and unzipping in java

public static void main(String[] args) throws Exception {
String mmdb = "https://someaddress/somefile.gz";
String zipFilename = "somefile.gz";
if (!Files.exists(Path.of(zipFilename))) {
System.out.println(mmdb);
Files.copy(
new URL(mmdb).openStream(),
Paths.get(zipFilename));
try (GZIPInputStream gis = new GZIPInputStream(new FileInputStream(Path.of(zipFilename).toFile()))) {
Files.copy(gis, Path.of(dbFileName));
}
}

SpringApplication.run(Application.class, args);
}

xrebel ve jrebel kullanılmalı

yaklaşık 10 senedir profosyonel java geliştiriyorum. ve evet java ortamları insanı sıkacak kadar yavaş olabiliyor. kodu yazıp denemesi en az 30 saniye. hadi profile edim dersen en az 5dk harcanıyor. bunları hızlandırmak mümkün. uzun süredir jrebel social kullanıyorum. kendisi şuradan edinilebilir

https://my.jrebel.com/

gelelim xrebel e. xrebel bir profiling ürünü ve önyüzde  sonuç veriyor. kısa tanıtım filmi şöyle

türkçe anlatmak gerekirse jar ı indirip javaagent parametresiyle jvm e vermeniz yeterli sonra önyüzde kaç saniye nerede geçirdiğini ekrandan görebiliyorsunuz. umarım bunuda social falan yaparlar çok sevdim tool u blog yazdırdı bana 🙂

tekrarlı harfleri sıkıştırma sorusu

soru
“aaaaaaabbbbbbbcccccddddaaaa” gibi bi string gelince “a7b7c5d4a4” şeklinde çıktı üretecek kodu yazınız.

cevap