Skip to content

Instantly share code, notes, and snippets.

@gsusmonzon
gsusmonzon / custom-entity-not-found-exception-filter.md
Last active February 17, 2024 06:04
Make NestJs returns 404 when EntityNotFoundError exception is thrown

Make NestJs returns 404 when EntityNotFoundError exception is thrown

When using findOrFail() or findOneOrFail() from typeORM, a 500 error is returned if there is no entity (EntityNotFoundError).

To make it returns a 404, use an exception filter as described in https://docs.nestjs.com/exception-filters .

file /src/filters/entity-not-found-exception.filter.ts

# ./adb shell pm list packages
./adb shell pm uninstall -k --user 0 com.amazon.appmanager
./adb shell pm uninstall -k --user 0 com.miui.msa.global
./adb shell pm uninstall -k --user 0 com.google.android.apps.googleassistant
./adb shell pm uninstall -k --user 0 com.facebook.appmanager
./adb shell pm uninstall -k --user 0 com.facebook.system
./adb shell pm uninstall -k --user 0 com.facebook.services
./adb shell pm uninstall -k --user 0 com.miui.daemon
./adb shell pm uninstall -k --user 0 com.miui.videoplayer
# ./adb shell pm list packages -f | facebook
./adb shell pm uninstall -k --user 0 com.samsung.android.mateagent
./adb shell pm uninstall -k --user 0 com.samsung.android.app.spage
./adb shell pm uninstall -k --user 0 com.samsung.android.app.social
./adb shell pm uninstall -k --user 0 com.samsung.android.app.watchmanagerstub
./adb shell pm uninstall -k --user 0 com.samsung.android.app.tips
./adb shell pm uninstall -k --user 0 com.microsoft.appmanager
./adb shell pm uninstall -k --user 0 com.microsoft.skydrive
./adb shell pm uninstall -k --user 0 com.google.android.googlequicksearchbox
./adb shell pm uninstall -k --user 0 com.samsung.android.game.gametools
@gsusmonzon
gsusmonzon / ResourceState.kt
Last active October 4, 2022 16:43
A generic class that holds a value with its loading status. Like a Result, but with a `Loading` state
/**
* A generic class that holds a value with its loading status.
* @param <T>
*/
sealed class ResourceState<out T> {
open val isSuccess get():Boolean {return false}
open val isFailure get():Boolean {return false}
open val isLoading get():Boolean {return false}
open fun getOrNull(): T? {return null}
@gsusmonzon
gsusmonzon / ejs-options-in-express.md
Created January 27, 2022 17:02
Configure ejs options in node express
// example 
app.set('view options', { root: join(rootDir, 'views') });
@gsusmonzon
gsusmonzon / how-to-send-payload-per-platform.ts
Last active December 16, 2021 19:16
How to send different payloads per platform with node-gcm
import { IResponseBody as FcmResponse, Message as FcmMessage, Sender as FcmSender } from 'node-gcm';
class FcmMessage2 extends Message {
private apns: Record<string, unknown>;
private android: Record<string, unknown>;
addApnsData(data: Record<string, unknown>): void {
this.apns = data;
}
addAndroidData(data: Record<string, unknown>): void {
this.android = data;
@gsusmonzon
gsusmonzon / html5-template.html
Last active May 29, 2021 16:48
HTML5 template
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Your Website</title>
<meta name="description" content="HTML5 template">
<meta name="author" content="unknown">
<!-- <link rel="stylesheet" href="css/styles.css?v=1.0"> -->
@gsusmonzon
gsusmonzon / utils-debounce.js
Last active November 19, 2020 10:20
Vanilla Javascipt debounce utility
/**
* Debounce utility based on `underscore` debouce, but simpler
* usage: `_debounce(onScrollEvent, 100, true)`
* usually you want atBeginning set to false.
* use atBeginning if you want `func` is called when teh sequence of calls starts,
* instead of waiting until `wait` ms have passed without more calls
*/
window._debounce = window._debounce || function(func, wait, atBeginning) {
var timeout;
if (atBeginning){