Skip to content

Instantly share code, notes, and snippets.

View image72's full-sized avatar

image72 image72

View GitHub Profile
@image72
image72 / http-server-upload.js
Created September 11, 2024 01:01
simple http server
const http = require('node:http');
const { IncomingForm } = require('formidable');
const { promises: fs, constants: fsConstants } = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const { parseArgs } = require('node:util');
const options = {
port: { type: 'string', short: 'p', default: process.env.PORT || '8080' },
'upload-dir': { type: 'string', short: 'd', default: process.env.UPLOAD_DIR || process.cwd() },
@image72
image72 / node-nginx.dockerfile
Created August 2, 2024 01:49
normal nodejs project with nginx.
FROM node:20-alpine as build-stage
ARG HTTP_PROXY
ARG HTTPS_PROXY
ENV HTTP_PROXY=$HTTP_PROXY
ENV HTTPS_PROXY=$HTTPS_PROXY
WORKDIR /usr/src/app
COPY . .
RUN npm -g install pnpm@latest && pnpm config set registry=https://registry.npmmirror.com && pnpm install && npm run build
@image72
image72 / heredoc.dockerfile
Created July 31, 2024 06:27
heredoc in dockerfile snippets
FROM debian
RUN <<EOT bash
set -eux
to_install=(
vim
)
apt-get update
failing_command # set -e exit with non-zero status
apt-get install -y "\${to_install[@]}"
EOT
@image72
image72 / deploy.sh
Created July 18, 2024 11:00
deploy project build to ssh server
#!/bin/sh
trap cleanup EXIT
# green="\e[1;32m"
# red="\e[1;31m"
# reset="\e[0m"
green=$(tput setaf 64);
red=$(tput setaf 124);
reset=$(tput sgr0);
@image72
image72 / Dockerfile
Created July 11, 2024 13:25 — forked from rickxz/Dockerfile
Adminer MongoDB docker image
FROM adminer:4.8.0
# WATCH OUT WHEN UPGRADING, THE SED BELOW MIGHT STOP WORKING
USER root
RUN apk add autoconf gcc g++ make libffi-dev openssl-dev
RUN pecl install mongodb
RUN echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/docker-php-ext-mongodb.ini
# MongoDB allows connections without password.
# But that doesn't fly with Adminer which prints 'Database does not support password.' for such case.
@image72
image72 / colors.bash
Created June 21, 2024 15:48 — forked from yesmar/colors.bash
Colorized output using tput(1)
#!/bin/bash
# ~/.local/etc/colors
# Wed Jan 21 19:04:30 PST 2015 yesmar@gmail.com
# Colorized output using tput(1). This script falls back to using ANSI escape
# codes if tput(1) is unavailable. All color names have been sourced from
# http://www.december.com/html/spec/colorhex.html
# shellcheck disable=SC2034
@image72
image72 / docker-compose.yml
Created April 26, 2024 07:59
getsentry/sentry docker image docker-compose
version: '3'
services:
db:
image: postgres:13
environment:
POSTGRES_PASSWORD: sentry
POSTGRES_USER: sentry
POSTGRES_DB: sentry
networks:
- sentry-network
@image72
image72 / docker-registry-mirrors.md
Created April 26, 2024 06:20 — forked from y0ngb1n/docker-registry-mirrors.md
国内的 Docker Hub 镜像加速器,由国内教育机构与各大云服务商提供的镜像加速服务 | Dockerized 实践 https://github.com/y0ngb1n/dockerized

Docker Hub 镜像加速器

国内从 Docker Hub 拉取镜像有时会遇到困难,此时可以配置镜像加速器。Docker 官方和国内很多云服务商都提供了国内加速器服务。

Dockerized 实践 https://github.com/y0ngb1n/dockerized

配置加速地址

Ubuntu 16.04+、Debian 8+、CentOS 7+

to check if the server works - https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice
stun:
stun.l.google.com:19302,
stun1.l.google.com:19302,
stun2.l.google.com:19302,
stun3.l.google.com:19302,
stun4.l.google.com:19302,
stun.ekiga.net,
stun.ideasip.com,
// https://blog.logrocket.com/build-video-streaming-server-node/
router.get('/video/:id', (req, res) => {
const videoPath = `assets/${req.params.id}.mp4`;
const videoStat = fs.statSync(videoPath);
const fileSize = videoStat.size;
const videoRange = req.headers.range;
if (videoRange) {
const parts = videoRange.replace(/bytes=/, "").split("-");
const start = parseInt(parts[0], 10);
const end = parts[1]