Skip to content

Instantly share code, notes, and snippets.

View zivce's full-sized avatar
🕹️
Focusing

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

🕹️
Focusing
View GitHub Profile
@zivce
zivce / RequestAndResponseLoggingFilter.java
Created August 26, 2021 13:41 — forked from int128/RequestAndResponseLoggingFilter.java
Spring Web filter for logging request and response
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 August 14, 2021 06:41 — forked from devbyray/medium-status.js
Get Curation Status from Medium Post
(() => {
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)
}
}
[
{
"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"
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
private OptionalInt readExpirationAsInt(Milk milk)
{
String expiration = milk.getExpiration();
try {
return Optional.of(Integer.parseInt(expiration));
}
catch(NumberFormatException e) {
return OptionalInt.empty();
}
private int readExpirationAsInt(Milk milk)
{
String expiration = milk.getExpiration();
try {
return Integer.parseInt(expiration);
}
catch(NumberFormatException ignored) {}
return 0;
}
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;
}
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 }
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
}
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
}