Skip to content

Instantly share code, notes, and snippets.

View heri16's full-sized avatar

Heri Sim heri16

View GitHub Profile
@heri16
heri16 / README.md
Last active March 29, 2024 02:43
Openwrt: Uses CAKE's diffserv4 classifications: Bulk, Best Effort, Video, Voice in combination with act_ctinfo and CONNMARK --set-dscpmark to restore DSCP classifications on ingress.

Smart Queue

Initial Setup

opkg update
opkg install luci-app-sqm kmod-sched-ctinfo iptables-mod-hashlimit ipset nano

# Install modified layer_cake to sqm-scripts
wget https://gist.githubusercontent.com/heri16/06c94b40f0d30f11e3a82166eca718f3/raw/layer_cake_ct.qos -O /usr/lib/sqm/layer_cake_ct.qos
@heri16
heri16 / upload.js
Last active February 20, 2021 10:41
Upload with cloudfront signature
const bucketName = "";
const bucketEnpoint = "";
const s3 = new AWS.S3({
params: { Bucket: bucketName },
endpoint: bucketEndpoint,
s3BucketEndpoint: true,
// s3DisableBodySigning: false,
computeChecksums: true,
correctClockSkew: true,
@heri16
heri16 / App.jsx
Last active November 12, 2020 13:10
Lightweight Authenticator Component for Aws-Amplify
import React from 'react'
import { Switch, Route } from 'react-router-dom'
import { Amplify } from '@aws-amplify/core'
import { amplifyConfig } from './config'
import { AllContextProvider } from './context'
import {
@heri16
heri16 / filter.js
Last active October 30, 2020 12:33
AWS Lambda to filter CloudTrail management logs in S3 (before Athena)
const { chain } = require('stream-chain');
const { parser } = require('stream-json');
const { pick } = require('stream-json/filters/Pick');
const { filter } = require('stream-json/filters/Filter');
const { streamValues } = require('stream-json/streamers/StreamValues');
const { disassembler } = require('stream-json/Disassembler');
const { stringer } = require('stream-json/Stringer');
const ST = require('stream-template');
@heri16
heri16 / s3-bucket-cors.xml
Last active November 18, 2020 05:28
S3 Fetch Folder to Zip file with aws-sdk-js
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
@heri16
heri16 / example.js
Last active October 21, 2020 20:13
Download private AWS S3 folder via aws-sdk-js (with Browserify Shim / Webpack Polyfill for Nodejs Stream)
const file1 = {
name: "example/file1.txt",
stream: () => new Blob(["support blobs too"]).stream()
};
// Note: windows gets confused when file & folders starts with /
const fileMap = new Map([
["file1", file1],
["file2", new File(["file1 content"], "example/file2.txt")],
["zip-subfolder/Sintel.mp4", "s3key/Sintel.mp4"],
@heri16
heri16 / s3-bucket-cors.xml
Last active October 20, 2020 14:03
Complete CORS Config for AWS S3 Bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
@heri16
heri16 / bash.bashrc
Created October 19, 2020 06:21
Arch Linux bashrc alias
#
# /etc/bash.bashrc
#
# ......
# Custom functions
function expac-diff-file {
if [[ "$1" == "" ]];
then
@heri16
heri16 / win10.xml
Last active December 1, 2020 20:04
Windows 10 on libvirt qemu 5
<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0" type="kvm">
<name>win10</name>
<uuid>d2c97462-3a70-4afb-ab72-5916e8ac25ae</uuid>
<title>Windows 10</title>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://microsoft.com/win/10"/>
</libosinfo:libosinfo>
</metadata>
<memory unit="KiB">12582912</memory>
@heri16
heri16 / secure-random-legacy.js
Last active October 31, 2020 11:07
Shortest secure mixed-password generator - Easy to audit CSPRNG crypto.getRandomValues() with no bias
// Special chars from https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-policies.html
const validUppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const validLowercase = 'abcdefghijklmnopqrstuvwxyz';
const validNumber = '0123456789';
const validSpecial = '^$*.[]{}()?"!@#%&/\\,><\':;|_~\`';
const validChars = validSpecial + validUppercase + validLowercase + validNumber;
// See: https://javascript.info/regular-expressions
const regexpUppercase = new RegExp(`[${validUppercase}]`, 'g');
const regexpLowercase = new RegExp(`[${validLowercase}]`, 'g');