Skip to content

Instantly share code, notes, and snippets.

Avatar

Heri Sim heri16

View GitHub Profile
@heri16
heri16 / .eslintrc.js
Created May 5, 2021
Example eslint config
View .eslintrc.js
const path = require('path')
const { readFileSync } = require('fs')
const schemaString = readFileSync(`${__dirname}/data/schema.graphql`, 'utf8')
module.exports = {
root: true,
plugins: [
// 'jest',
'@typescript-eslint',
@heri16
heri16 / .README.md
Last active Apr 21, 2021
Install & init terraform
View .README.md
# Install pgp
brew install gnupg

# Write out the hashicorp public pgp key
cat <<EOF > hashicorp.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBFMORM0BCADBRyKO1MhCirazOSVwcfTr1xUxjPvfxD3hjUwHtjsOy/bT6p9f
W2mRPfwnq2JB5As+paL3UGDsSRDnK9KAxQb0NNF4+eVhr/EJ18s3wwXXDMjpIifq
@heri16
heri16 / README.md
Last active May 17, 2022
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.
View README.md

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 Feb 20, 2021
Upload with cloudfront signature
View upload.js
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 Nov 12, 2020
Lightweight Authenticator Component for Aws-Amplify
View App.jsx
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 Oct 30, 2020
AWS Lambda to filter CloudTrail management logs in S3 (before Athena)
View filter.js
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 Nov 18, 2020
S3 Fetch Folder to Zip file with aws-sdk-js
View s3-bucket-cors.xml
<?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 Oct 21, 2020
Download private AWS S3 folder via aws-sdk-js (with Browserify Shim / Webpack Polyfill for Nodejs Stream)
View example.js
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 Oct 20, 2020
Complete CORS Config for AWS S3 Bucket
View s3-bucket-cors.xml
<?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 Oct 19, 2020
Arch Linux bashrc alias
View bash.bashrc
#
# /etc/bash.bashrc
#
# ......
# Custom functions
function expac-diff-file {
if [[ "$1" == "" ]];
then