Skip to content

Instantly share code, notes, and snippets.

Avatar
🕹️
Focusing

Милош Живковић zivce

🕹️
Focusing
View GitHub Profile
@zivce
zivce / RequestAndResponseLoggingFilter.java
Created Aug 26, 2021 — forked from int128/RequestAndResponseLoggingFilter.java
Spring Web filter for logging request and response
View RequestAndResponseLoggingFilter.java
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.ContentCachingResponseWrapper;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@zivce
zivce / medium-status.js
Created Aug 14, 2021 — forked from devbyray/medium-status.js
Get Curation Status from Medium Post
View medium-status.js
(() => {
if(__APOLLO_STATE__) {
let result = null
for(const [key, value] of Object.entries(__APOLLO_STATE__)) {
if(key.startsWith('Post') && value.hasOwnProperty('curationStatus')) {
result = 'Curation status: ' + value.curationStatus;
console.log(result)
}
}
View padStringResults.json
[
{
"jmhVersion" : "1.19",
"benchmark" : "de.jawb.jmh.benchmark.example.uniquechars.PaddingBenchmark.testPadding_StringFormat_2",
"mode" : "avgt",
"threads" : 10,
"forks" : 3,
"jvm" : "/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home/bin/java",
"jvmArgs" : [
"-Dfile.encoding=UTF-8"
View jdk_linked_list_arraylist_runs_size_500k.csv
JDK JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11 JDK8 JDK11
Size 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000 500000
Time/Run 3.6ms 3.5ms 3.9ms 4ms 3.2ms 4.5ms 3.9ms 5.2ms 0.7ms 1.5ms 2.1ms 2.4ms 2.9ms 6.1ms 3.3ms 3.6ms 2449ns 1659ns 3166ns 1906ns
Operation Array List search and remove Array List search and remove Linked List search and remove Linked List search and remove Array List search Array List search Linked List search Linked List search Array List addAll() Array List addAll() Linked List addAll() Linked List addAll() Array List add() from scratch Array List add() from scratch Linked List add() from scratch Linked List add() from scratch Array List add() on end Array List add() on end Linked List add() on end Linked List add() on end
View emptyCatch_removed.java
private OptionalInt readExpirationAsInt(Milk milk)
{
String expiration = milk.getExpiration();
try {
return Optional.of(Integer.parseInt(expiration));
}
catch(NumberFormatException e) {
return OptionalInt.empty();
}
View emptyCatch.java
private int readExpirationAsInt(Milk milk)
{
String expiration = milk.getExpiration();
try {
return Integer.parseInt(expiration);
}
catch(NumberFormatException ignored) {}
return 0;
}
View avoidThisForDefaultValue.java
Optional<String> defaultStoreStatus = Optional.of("Store not found.");
public Optional<String> fetchStoreStatus(int storeId) {
Optional<String> foundStore = ... ; // fetch declared store status by id
if (foundStore.isPresent())
return foundStore;
else
return defaultStoreStatus;
}
View orOptional_Java9.java
1 public Optional<String> fetchStoreStatus(int storeId) {
2 Optional<String> foundStore = ... ; // fetch declared store status by id
3 return foundStore.or(() -> Optional.of("store uid not found"));
4 }
View orElseGet_orElseCorrection.java
getValue(x).orElseGet(() -> getValue(y)
.orElseThrow(() -> new NotFoundException("value not present")));
public Optional<Value> getValue(Source s)
{
System.out.println("Source: " + s.getName());
// returns value from s source
}
View orElse_BadExample.java
getValue(x).orElse(getValue(y)
.orElseThrow(() -> new NotFoundException("value not present")));
public Optional<Value> getValue(Source s)
{
System.out.println("Source: " + s.getName());
// returns value from s source
}