Skip to content

Instantly share code, notes, and snippets.

View jason-shen's full-sized avatar
🗼
Coding........

Jason Shen jason-shen

🗼
Coding........
View GitHub Profile
useEffect(() => {
console.log(“ComponentDidUpdate”
});
useEffect(() => {
console.log(“ComponentDidMount”
},[]);
useEffect(() => {
console.log(“will run when x changes”
@jason-shen
jason-shen / access_postgresql_with_docker.md
Created December 9, 2020 17:06 — forked from MauricioMoraes/access_postgresql_with_docker.md
Allow Docker Container Access to Host's Postgres Database on linux (ubuntu)

You have to do 2 things in order to allow your container to access your host's postgresql database

  1. Make your postgresql listen to an external ip address
  2. Let this client ip (your docker container) access your postgresql database with a given user

Obs: By "Host" here I mean "the server where docker is running on".

Make your postgresql listen to an external ip address

Find your postgresql.conf (in case you don't know where it is)

$ sudo find / -type f -name postgresql.conf

@jason-shen
jason-shen / gist:620361bced194dfe5f3f4454759a2314
Created January 13, 2021 07:43 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
func openbrowser(url string) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
@jason-shen
jason-shen / volume_meter.html
Created April 20, 2021 05:46 — forked from yying/volume_meter.html
WebAudio volume meter using a MediaStream (can be easily applied to MediaStream from WebRTC)
<!DOCTYPE html>
<html lang="en">
<head>
<title> </title>
<link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/min/1.5/min.min.css">
<style>
body,textarea,input,select {
background:0;
border-radius:0;
font:16px sans-serif;
@jason-shen
jason-shen / ws.go
Created July 23, 2021 06:56 — forked from bradfitz/ws.go
pre-Go1.12 websocket hijack+proxy
httpsServer := &http.Server{
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hj, isHJ := w.(http.Hijacker)
if r.Header.Get("Upgrade") == "websocket" && isHJ {
c, br, err := hj.Hijack()
if err != nil {
log.Printf("websocket websocket hijack: %v", err)
http.Error(w, err.Error(), 500)
return
}
@jason-shen
jason-shen / Docker Compose + NATS example
Created August 15, 2021 12:03 — forked from wallyqs/Docker Compose + NATS example
NATS Docker blog post/HTTP Server
FROM golang:1.6.2
COPY . /go
RUN go get github.com/nats-io/nats
RUN go build api-server.go
EXPOSE 8080
ENTRYPOINT ["/go/api-server"]
@jason-shen
jason-shen / caddy https
Created October 9, 2021 13:10
New Gist
Caddy is ready to serve your site over HTTPS:
Point your domain's A/AAAA DNS records at this machine.
Upload your site's files to /var/www/html.
Edit your Caddyfile at /etc/caddy/Caddyfile:
Replace :80 with your domain name
Change the site root to /var/www/html
Reload the configuration: systemctl reload caddy
Visit your site!
@jason-shen
jason-shen / webrtc_simulcast.js
Created November 6, 2021 17:45 — forked from hissinger/webrtc_simulcast.js
webrtc simulcast example
document.getElementById("btn").onclick = async () => {
await run();
}
async function run() {
let stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: false });
/* sender */
let sender = new RTCPeerConnection();
sender.onicecandidate = e => receiver.addIceCandidate(e.candidate);
@jason-shen
jason-shen / vim_cheatsheet.md
Created February 21, 2022 11:04 — forked from awidegreen/vim_cheatsheet.md
Vim shortcuts

Introduction

  • C-a == Ctrl-a
  • M-a == Alt-a

General

:q        close
:w        write/saves
:wa[!]    write/save all windows [force]
:wq       write/save and close