Skip to content

Instantly share code, notes, and snippets.

View GaetanoPiazzolla's full-sized avatar
☠️
Sleep is for those without deadlines

Gaetano Piazzolla GaetanoPiazzolla

☠️
Sleep is for those without deadlines
View GitHub Profile
@GaetanoPiazzolla
GaetanoPiazzolla / JWTInterceptor.java
Created January 30, 2022 19:49
JWT Interceptor used to authorize requests.
public class JWTInterceptor implements HandlerInterceptor {
@Value("${jwt.key}")
private String jwtKey;
@Autowired
private BlackListingService blackListingService;
@Autowired
private UserRequestScopedBean userRequestScopedBean;
public class Resurrected {
private static final Set<Resurrected> resurrected = new HashSet<>();
@Override
protected void finalize() throws Throwable {
resurrected.add(this); // Resurrect the object by creating a new reference
}
}
@Override
protected void finalize() throws Throwable {
// closing resources here....
super.finalize();
}
FileInputStream input = null;
try {
input = new FileInputStream(file1);
input.close(); input = null;
} finally {
if (input != null) input.close();
}
sessionStorage.setItem('pets', '{"pets":{"fido":{"species":"dog"}}}');
const store = createStore();
const persister = createSessionPersister(store, 'pets');
await persister.load();
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}}
sessionStorage.clear();
const store = createStore().setTable('pets', {
fido: {species: 'dog'},
felix: {species: 'cat'},
cujo: {species: 'dog'},
});
const indexes = createIndexes(store);
indexes.setIndexDefinition(
'bySpecies', // indexId
'pets', // tableId to index
'species', // cellId to index
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
checkpoints.setSize(200);
store.setCell('pets', 'fido', 'sold', true);
checkpoints.addCheckpoint('sale');
console.log(store.getCell('pets', 'fido', 'sold'));
// -> true
checkpoints.goBackward();
console.log(store.getCell('pets', 'fido', 'sold'));
// -> false
const listenerId = store.addTableListener('pets', () =>
console.log('changed'),
);
store.setCell('pets', 'fido', 'sold', false);
// -> 'changed'
store.delListener(listenerId);
const store = createStore()
.setTables({pets: {fido: {species: 'dog'}}})
.setSchema({
pets: {
species: {type: 'string'},
sold: {type: 'boolean', default: false},
},
});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', sold: false}}}
// r2dbc
public Mono<OrderDTO> addOrder(@RequestParam("bookIsbn") String bookIsbn, @RequestParam("firstName") String firstName) {
return Mono.just(UUID.randomUUID()).flatMap(uuid -> {
log.info("addOrder() {} running", uuid);
Mono<User> user = userRepository.findByFirstName(firstName);
Mono<Book> book = bookRepository.findByIsbn(bookIsbn);
return Mono.zip(user, book).flatMap(zipFlux -> {
log.info("addOrder() {} I've got user and book", uuid);