Skip to content

Instantly share code, notes, and snippets.

View bugb's full-sized avatar
🎯
Do it small and do it well!

Chau Giang bugb

🎯
Do it small and do it well!
View GitHub Profile
@bugb
bugb / README.md
Created June 14, 2021 03:19 — forked from joyrexus/README.md
Perl one-liners

Hi:

perl -e 'print "hello world!\n"'

A simple filter:

perl -ne 'print if /REGEX/'

Filter out blank lines (in place):

Problem

A lot of GitHub projects need to have pretty math formulas in READMEs, wikis or other markdown pages. The desired approach would be to just write inline LaTeX-style formulas like this:

$e^{i \pi} = -1$

Unfortunately, GitHub does not support inline formulas. The issue is tracked here.

Investigation

@bugb
bugb / picasa_upld.sh
Created May 7, 2021 08:56 — forked from hrpunio/picasa_upld.sh
Upload pic_file to Google photos/Picasa with curl; returns source image URL
#!/bin/bash
# Upload pic_file to Google photos/Picasa with curl; returns source image URL
#
# Usage: picasa.sh -s SCALE -a ALBUMID -t PIC_NAME -u -r pic_file
# -s SCALE -- scale pic_file to SCALE% (with imagemagic's convert)
# -a ALBUMID -- if not given upload to default album
# -t PIC_NAME -- picture name, if not given the same as pic_file
# -u -- print HTML fragment with URL to pic_file
# -r -- remove scaled pic_file
#
@bugb
bugb / policy.md
Created December 28, 2020 02:50 — forked from pgolding/policy.md
s3 bucket policy for presigned URLs generated by serverless lambda functions

AWS Presigned URLs

Presigned URLs are useful for fine-grained access control to resources on s3.

For example, if storing larger text blocks than DynamoDB might allow with its 400KB size limits s3 is a useful option.

Ignoring various ACL methods and using presigned URLs, it's possible to create lambda functions that can generate the required upload and download URLs.

Using the default IAM roles and lambda proxy configuration of serverless, lambdas are assigned an IAM role for the application (so that a logical group of functions can share resources - e.g. for a CRUD REST API). Each function then assumes the IAM role via its own function name.

@bugb
bugb / Makefile
Created October 17, 2020 17:54 — forked from kvz/Makefile
The only Makefile for Node.js projects you'll ever need - https://twitter.com/kvz/status/685853830425231361
# Licensed under MIT.
# Copyright (2016) by Kevin van Zonneveld https://twitter.com/kvz
#
# This Makefile offers convience shortcuts into any Node.js project that utilizes npm scripts.
# It functions as a wrapper around the actual listed in `package.json`
# So instead of typing:
#
# $ npm script build:assets
#
# you could just as well type:
@bugb
bugb / webrtc.js
Created September 21, 2020 07:39 — forked from dristic/webrtc.js
Full code from my WebRTC Data Channel post.
// Fix Vendor Prefixes
var IS_CHROME = !!window.webkitRTCPeerConnection,
RTCPeerConnection,
RTCIceCandidate,
RTCSessionDescription;
if (IS_CHROME) {
RTCPeerConnection = webkitRTCPeerConnection;
RTCIceCandidate = window.RTCIceCandidate;
RTCSessionDescription = window.RTCSessionDescription;
@bugb
bugb / docs.md
Created August 8, 2020 18:02
k8s

get all pods in all namespace:

kubectl get pods --all-namespaces -o jsonpath="{..image}" |\
tr -s '[[:space:]]' '\n' |\
sort |\
uniq -c
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', function(deadWorker, code, signal) {
var worker = cluster.fork();
const newPID = worker.process.pid;
@bugb
bugb / install.sh
Last active August 11, 2020 07:10
Install docker and compose
#!/bin/bash
sudo apt install curl -y
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER
newgrp docker
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
@bugb
bugb / swap.sh
Created May 29, 2020 19:42
Script install swap for ubuntu
#!/bin/bash
sudo fallocate -l 4G /swapfile
chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
cat /etc/fstab
sudo echo "vm.swappiness=10" >> /etc/sysctl.conf