Skip to content

Instantly share code, notes, and snippets.

View crazyoptimist's full-sized avatar
🐌
crawling

crazyoptimist crazyoptimist

🐌
crawling
View GitHub Profile
@crazyoptimist
crazyoptimist / live-stream-server.js
Last active March 3, 2023 22:25
Live Stream Server Deployment
const NodeMediaServer = require('node-media-server');
const config = {
rtmp: {
port: 1935,
chunk_size: 10000,
gop_cache: true,
ping: 30,
ping_timeout: 60
},
@crazyoptimist
crazyoptimist / rbenv-install.sh
Last active January 4, 2023 18:11
Install rbenv on Ubuntu/Debian
# Install build dependencies for ruby(https://github.com/rbenv/ruby-build/wiki#suggested-build-environment)
sudo apt-get install -y autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
# Install rbenv using git
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
source ~/.bashrc
# Install ruby-build plugin for rbenv
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
# List available ruby versions
rbenv install --list
@crazyoptimist
crazyoptimist / pointers.go
Created November 2, 2022 21:18
Pointer in Go (Checkout this gist whenever you forget the concept of pointers in Go)
package main
import "fmt"
func main() {
i, j := 42, 2701
fmt.Println(i, j)
fmt.Println(&i, &j)
// you can read "&i" as "address of i"
@crazyoptimist
crazyoptimist / bat-install.sh
Created October 6, 2022 17:24
bat is written in rust, is an excellent alternative to cat
#!/bin/bash
curl -s https://api.github.com/repos/sharkdp/bat/releases/latest \
| grep -v ".sha256" \
| grep browser_download_url
curl -SL https://github.com/sharkdp/bat/releases/download/v0.22.1/bat_0.22.1_amd64.deb -o bat.deb
sudo dpkg -i bat.deb
rm bat.deb
@crazyoptimist
crazyoptimist / debounce.ts
Created July 5, 2022 16:38
Debounce Wrapper in Typescript
export function debounce<T extends unknown[], U>(
callback: (...args: T) => U,
wait: number,
): (...args: T) => void {
let timer: NodeJS.Timeout | undefined = undefined
return (...args: T): void => {
if (timer) {
clearTimeout(timer)
}
@crazyoptimist
crazyoptimist / install-kubeadmin.sh
Created April 22, 2022 22:32
Install kubeadmin on debian based OS
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
@crazyoptimist
crazyoptimist / install-containerd.sh
Last active April 22, 2022 22:09
Install containerd on debian based OS
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
# Setup required sysctl params, these persist across reboots.
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
@crazyoptimist
crazyoptimist / serve.go
Created September 14, 2021 20:05 — forked from paulmach/serve.go
Simple Static File Server in Go
/*
Serve is a very simple static file server in go
Usage:
-p="8100": port to serve on
-d=".": the directory of static files to host
Navigating to http://localhost:8100 will display the index.html or directory
listing file.
*/
package main
@crazyoptimist
crazyoptimist / vim-install-note.md
Created April 25, 2021 23:45
Install Vim From the Source on Fedora/CentOS

Installing Vim by building from the source needs bunch of dependancies.

Setup essential build environment

yum -y groupinstall "Development Tools"
yum -y install ncurses-devel git-core

Get the source

@crazyoptimist
crazyoptimist / image-clean.sh
Last active November 26, 2020 22:03
Remove <none> tagged docker images
if [ -z "$(docker images | awk '/^<none>/ {print $3}')" ]; then
echo "You don't have any <none> tagged images."
else
docker rmi $(docker images | awk '/^<none>/ {print $3}')
fi