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 {
...
}
@jnizet
jnizet / confirm-modal-and-service.ts
Last active October 27, 2022 16:54
How to create a reusable service allowing to open a confirmation modal from anywhere with ng-bootstrap
import { Component, Injectable, Directive, TemplateRef } from '@angular/core';
import { NgbModal, NgbModalRef, NgbModalOptions } from '@ng-bootstrap/ng-bootstrap';
/**
* Options passed when opening a confirmation modal
*/
interface ConfirmOptions {
/**
* The title of the confirmation modal
*/
public final class Rectangle {
private final int width;
private final int height;
public Rectangle(int width, int height) {
this.width = width;
this.height = height;
}
public int area() {
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();