Skip to content

Instantly share code, notes, and snippets.

@jnizet
jnizet / IndexFilter.java
Last active January 9, 2024 15:06
Index
import java.io.IOException;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpServletRequest;
// Don't do
return next(req).pipe(
catchError(error => {
const status = error.status;
if (status === HttpStatusCode.BadRequest) {
// ...
} else {
...
}
public Pojo parseJson(String json) {
// parse
return pojo;
// don't catch the exception. If there is an exception, there is a bug, so you shouldn't catch it and ignore it
// that will only cause a cryptic NullPointerException later.
}
public Mono<Pojo> query(long id) {
Integer value = idMapper.getValue(id);
import java.util.Arrays;
import java.util.stream.Collectors;
public class Benchmark {
public static void main(String[] args) {
System.out.println(Arrays.asList(1, 2, 3, 4, 5)
.stream()
.filter(i -> i > 10)
.map(i -> {
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collections;
import com.fasterxml.jackson.databind.ObjectMapper;
public class MyCustomObject{
private String appName;
package com.example.demo;
public class Employee {
}
package com.foo;
import java.io.IOException;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.databind.ObjectMapper;
public class QnA implements Serializable {
private long idQnA;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class InterfaceTest {
interface TestInterface {
default Set<String> getRequiredStrings() {
return Collections.emptySet();
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input, OnInit } from '@angular/core';
@Component({
selector: 'foo',
template: 'hello {{ nameCopy }}'
})
class FooComponent implements OnInit {
@Input() name: string;
nameCopy: string;
data class Course(val id: Long, val students: MutableSet<Student> = mutableSetOf())
data class Student(val id: Long, val courses: MutableSet<Course> = mutableSetOf())
fun main() {
val english = Course(1L)
val john = Student(1L)
english.students.add(john)
john.courses.add(english)
println(john) // StackOverflowError