Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
@percybolmer
percybolmer / docker-file-multibuild.dockerfile
Created August 31, 2022 06:21
A multistage docker file showing how to copy go binary
FROM golang:1.9 AS builder
WORKDIR /
# copy everything from host folder into this image
COPY . .
# Build binary and place it at /main
RUN go build -o /main
# Initiate the Second Build stage
FROM scratch
COPY --from=builder /main /main
@percybolmer
percybolmer / main.go
Created August 31, 2022 06:16
Small program to run inside a docker scratch image
package main
import "log"
func main() {
log.Println("Hello from Scratch")
}
@percybolmer
percybolmer / multibuild.dockerfile
Last active August 31, 2022 06:11
dockerfile multibuild
FROM golang:1.9 AS builder
# Build our software binary
FROM scratch
# Here we will copy the binary from the Builder Image into this scratch Container
COPY --from=builder path/on/builder path/on/scratch
// setupAPI will start all Routes and their Handlers
func setupAPI() {
// Create a Manager instance used to handle WebSocket Connections
manager := NewManager()
// Serve the ./frontend directory at Route /
http.Handle("/", http.FileServer(http.Dir("./frontend")))
http.HandleFunc("/ws", manager.serveWS)
}
package main
import (
"log"
"net/http"
"github.com/gorilla/websocket"
)
var (
/**
* Once the website loads, we want to apply listeners and connect to websocket
* */
window.onload = function () {
// Apply our listener functions to the submit event on both forms
// we do it this way to avoid redirects
document.getElementById("chatroom-selection").onsubmit = changeChatRoom;
document.getElementById("chatroom-message").onsubmit = sendMessage;
// Check if the browser supports WebSocket
@percybolmer
percybolmer / websocket-index-v1.html
Last active August 27, 2022 07:21
Simple HTML website with yet not websockets
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>PP - Websockets</title>
</head>
@percybolmer
percybolmer / websockets-main-v1.go
Created August 22, 2022 06:17
simple hosting of frontend dir
package main
import (
"log"
"net/http"
)
func main() {
setupAPI()
@percybolmer
percybolmer / docker run.bash
Last active August 18, 2022 06:48
docker ffmpeg
docker build -t demo/ffmpeg .
# Run the container on the demo video and output into mounted share
docker run -v $PWD/data:/shared demo/ffmpeg -i /videos/big_buck_bunny_720p_1mb.mp4 -filter:v "setpts=PTS/60" /shared/output.mkv
FROM ubuntu
RUN apt-get -y update &&\
apt-get -y install ffmpeg &&\
mkdir /videos
ADD https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4 /videos
ENTRYPOINT ["ffmpeg"]