Notes - JavaScript

DOM

getElementById()

Note: no “#” at the beginning of the id

1
let element = document.getElementById("message");

Get/Set InnerText

1
2
const renderedText = htmlElement.innerText
htmlElement.innerText = string

JavaScript

URL functions

url diagram

Notes - Gin Web Framework

Router

Full Router Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
func prepareRoutes(router *gin.Engine) {
	// Web Resources
	router.Static("/static", "web/dist")

	// API Routes
	api := router.Group("/api/v1")
	admin := api.Group("/admin")
	public := api.Group("/public")
	registered := api.Group("/")
	sameRegisteredUser := api.Group("/user")

	prepareMiddleware(admin, public, registered, sameRegisteredUser)

	admin.GET("/users", listUsers)
	admin.GET("/places", listPlaces)
	admin.POST("/places", createPlace)
	admin.POST("/events", createEvent)
	admin.PUT("/place/:placeId", updatePlace)
	admin.PUT("/event/:eventId", updateEvent)
	admin.DELETE("/event/:eventId", cancelEvent)

	sameRegisteredUser.GET("/:userId", getUser)
	sameRegisteredUser.PUT("/:userId", updateUser)
	sameRegisteredUser.DELETE("/:userId", disableUser)

	registered.POST("/buy/:seatId", buyTicket)

	public.GET("/place/:placeId", getPlace)
	public.GET("/events", listEvents)
	public.GET("/event/:eventId", getEvent)
	public.POST("/users", createUser) // TODO Checar, me huele raro......
	public.POST("/login", loginUser)
}

How to serve static files in root page?

1
2
3
4
api:=r.Group("/api")
api.GET("/json", serveJSON)

r.Static("/","./public")

Will get the following error:

Notes - Playwright-Go

FAQ

How to connect to an existing browser?

When access some websites, like Vendor Central, we don’t have the option to get credentials/API keys to connect from our apps. We can go to the website using our current credential and connect to it from our app.

Notes - SQL & Sqlite Database

Commands

Get unique values

SELECT DISTINCT report_date FROM daily;

How many records?

SELECT count(*) from vanall WHERE Shipped_Date="2021-01-12";

Last Shipped Date

-- Current max date in the table
SELECT max(Shipped_Date) from vanall;

Insert Or Update

INSERT or replace INTO daily (date,name_id,testing_hour,sellable,liquidation,quality,concession) 
VALUES ("2021-02-01",5,1.0,2,3,4,5);

Insert data get from other tables

-- insert new data from temp into table vanall
INSERT INTO vanall
SELECT * from temp where Shipped_Date>"2021-01-12";

Update

UPDATE associate SET show=1 WHERE show IS NULL

Delete

-- remove all the assets that are not shipped yet
DELETE FROM vanall WHERE Shipped_Date is NULL

-- delete table
DROP TABLE associate;

Creating Sub-Query

with yvr3(facility,class,cat, sub) as
(select "YVR3", class,cat, count(*) as sub from amazon where location < "QC-76.11"
group by class,cat),

yyc1(facility, class,cat,sub) as 
(select "YYC1", class,cat,count(*) as sub from amazon where location > "QC-76.10"
group by class,cat)

select yyc1.facility,yyc1.class,yyc1.cat, yyc1.sub from yyc1
left join yvr3
on (yyc1.class=yvr3.class and yyc1.cat=yvr3.cat)
where yvr3.cat is null
order by yyc1.sub desc;

FULL OUT JOIN

Sqlite doesn’t support FULL OUT JOIN or RIGHT JOIN. It’s easy to perform a RIGHT OUTER JOIN in SQLite by simply reversing the order of tables and using a LEFT OUTER JOIN. It’s also possible to do a FULL OUTER JOIN by combining LEFT OUTER JOINs using the UNION keyword.

X-Talker T51A Setup

T51A Two Way Radio

We get these free T51A radio from Uline. It can cover more than 1 mile range for us to communicate within warehouse.

Notes - Caddy Server

Installation

How to install Caddy to MacBook?

Install Homebrew

Homebrew: The Missing Package Manager for macOS (or Linux)

// Install the Howebrew from Mac terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Caddyserver

homebrew install caddy

To start caddy new and restart at login:

Notes - Go Programming Language

Tips

Regular expression is not a const

There are boolean, rune, integer, floating-point, complex, and string constants. Rune, integer, floating-point, and complex constants are collectively called numeric constants.

Website Security With ReCAPTCHA

reCAPTCHA is a free google service that protects your website from spam and abuse. reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep automated software from engaging in abusive activities on your site. It does this while letting your valid users pass through with ease.

Notes - Linux

Linux Notes

Common Commands

How to show file permission?

ls /var/www -al

How to add a user?

sudo adduser new_username
// or
sudo useradd new_username

How to remove a user?

sudo userdel username
// remove user's home folder
sudo rm -r /home/username

How to change other user’s password?

// set / change password for user postgres
sudo passwd postgres

How to add a user to sudo group?

adduser username sudo
// or
usermod -aG sudo username

How to execute commands as other user?

su // as root
su - postgres // login as postgres
su postgres // switch to postgres

// preserve the entire environment (HOME, SHELL, USER, and LOGNAME) of the calling user
su -p postgres 

How to change file permission?

See https://help.ubuntu.com/community/FilePermissions