Skip to content

Instantly share code, notes, and snippets.

View LidiaKovac's full-sized avatar
🌻

Lidia Kovac LidiaKovac

🌻
View GitHub Profile
@LidiaKovac
LidiaKovac / index.js
Created May 10, 2024 14:41
AWS EC2 Pupetteer configuration
const browser = await puppeteer.launch({
headless: config.headless,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
ignoreDefaultArgs: ["--disable-extensions"],
})
const page = await this.browser.newPage()
await page.setRequestInterception(true)
page.on("request", (req) => {
if (
@LidiaKovac
LidiaKovac / IController.java
Created February 9, 2024 09:02
JAVA SPRING INTERFACES (v0.1)
package ...;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import example.example.exceptions.BadRequestException;
import example.example.exceptions.ElementNotFoundException;
@LidiaKovac
LidiaKovac / ROUTE PARAMETER - COME NAVIGARE
Last active August 21, 2023 07:42
ROUTE PARAMETER // Angular
<a routerLink="/6">Portera' alla rotta /:id con params.get("id") uguale a 6</a>
this.router.navigate(['/', ID DOVE VOLETE NAVIGARE])
//Esempio di file upload usando FormData e Typescript
//Component.jsx
import { useState } from "react" //ChangeEvent e FormEvent sono i tipi degli eventi onChange e onSubmit
export const Component = () => {
const [fd, setFd] = useState(new FormData()) //FormData e' una classe usata per raccogliere dati non stringa dai form
//E' formata da coppie chiave/valore => ["post", File], ["exp", File]
const handleSubmit = async (ev) => {
ev.preventDefault()
let res = await fetch(
//Esempio di file upload usando FormData e Typescript
//Component.jsx
import { ChangeEvent, FormEvent, useState } from "react" //ChangeEvent e FormEvent sono i tipi degli eventi onChange e onSubmit
export const Component = () => {
const [fd, setFd] = useState(new FormData()) //FormData e' una classe usata per raccogliere dati non stringa dai form
//E' formata da coppie chiave/valore => ["post", File], ["exp", File]
const handleSubmit = async (ev: FormEvent) => {
ev.preventDefault()
let res = await fetch(
@LidiaKovac
LidiaKovac / gist:250bdaf12ff0cab8168e266b5e8848da
Last active December 18, 2021 12:06
Typescript + Express REST API - Mini-guide

TypeScript REST API

General notes:

  • Request and Response are both basic TS interfaces and express interfaces. You want to use the express one, so remember to import them correctly.
  • NextFunction is the interface for next() and is also imported from ExpressJS.
  • Async functions return Promises (which, in the TS language is Promise<T> where T is the type of data the Promise will return if fullfilled). In case of Express endpoints, you will use res.send(), not return, so T will be void.

Possible errors:

req.header("Authorization").replace("Bearer ", "") - error TS2532: Object is possibly 'undefined' when trying to get the authorization header