Skip to content

Instantly share code, notes, and snippets.

View invisibleroads's full-sized avatar

Roy Hyunjin Han invisibleroads

View GitHub Profile
#cloud-config
packages:
- nginx
#jq is a command-line json processor https://stedolan.github.io/jq/
- jq
- unattended-upgrades
runcmd:
- export DOMAIN=your_domain_here.com
- export DO_API_TOKEN=PASTE_YOUR_DIGITALOCEAN_API_TOKEN_HERE
- export PUBLIC_IPV4=$(curl -s http://169.254.169.254/metadata/v1/interfaces/public/0/ipv4/address)
@MrGraversen
MrGraversen / cloud-init-docker-etc.yaml
Last active April 29, 2024 15:11
Base cloud-init for security hardening, SSH, Docker, etc.
#cloud-config
package_update: true
manage-resolv-conf: true
resolv_conf:
nameservers:
- '8.8.8.8'
- '8.8.4.4'
- '1.1.1.1'
@davesteele
davesteele / cache_dict.py
Last active October 19, 2023 14:23
Python LRU Caching Dictionary - a dict with a limited number of entries, removing LRU elements as necessary
from collections import OrderedDict
# >>> import cache_dict
# >>> c = cache_dict.CacheDict(cache_len=2)
# >>> c[1] = 1
# >>> c[2] = 2
# >>> c[3] = 3
# >>> c
# CacheDict([(2, 2), (3, 3)])
# >>> c[2]
@NiklasMerz
NiklasMerz / deployment.yaml
Last active May 9, 2020 00:07
Github Actions Kubernetes Deploy
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: myproject
name: myproject
namespace: default
spec:
progressDeadlineSeconds: 600
replicas: 1
@engelen
engelen / argmax.js
Last active March 7, 2023 01:32
Single-line ArgMax for JavaScript
/**
* Retrieve the array key corresponding to the largest element in the array.
*
* @param {Array.<number>} array Input array
* @return {number} Index of array element with largest value
*/
function argMax(array) {
return array.map((x, i) => [x, i]).reduce((r, a) => (a[0] > r[0] ? a : r))[1];
}
@dseg
dseg / nftables.conf
Created April 22, 2016 07:45
A basic nftables config. Only accept ssh, http and https.
#!/usr/bin/nft -f
# ipv4/ipv6 Simple & Safe Firewall
# you can find examples in /usr/share/nftables/
table inet filter {
chain input {
type filter hook input priority 0;
# allow established/related connections
ct state {established, related} accept
@mmerickel
mmerickel / cors.py
Last active December 6, 2022 14:13
cors in pyramid
from pyramid.security import NO_PERMISSION_REQUIRED
def includeme(config):
config.add_directive(
'add_cors_preflight_handler', add_cors_preflight_handler)
config.add_route_predicate('cors_preflight', CorsPreflightPredicate)
config.add_subscriber(add_cors_to_response, 'pyramid.events.NewResponse')
class CorsPreflightPredicate(object):
@philngo
philngo / climate_zones.csv
Last active March 5, 2024 17:41
IECC and Building America climate zones by United States county
State State FIPS County FIPS IECC Climate Zone IECC Moisture Regime BA Climate Zone County Name
AK 02 013 7 N/A Very Cold Aleutians East
AK 02 016 7 N/A Very Cold Aleutians West
AK 02 020 7 N/A Very Cold Anchorage
AK 02 050 8 N/A Subarctic Bethel
AK 02 060 7 N/A Very Cold Bristol Bay
AK 02 068 7 N/A Very Cold Denali
AK 02 070 8 N/A Subarctic Dillingham
AK 02 090 8 N/A Subarctic Fairbanks North Star
AK 02 100 7 N/A Very Cold Haines
@nitaku
nitaku / README.md
Last active May 12, 2024 22:24
Minimal JSON HTTP server in python

A minimal HTTP server in python. It sends a JSON Hello World for GET requests, and echoes back JSON for POST requests.

python server.py 8009
Starting httpd on port 8009...
curl http://localhost:8009
{"received": "ok", "hello": "world"}
@danrigsby
danrigsby / packer-ami-id
Last active December 14, 2023 15:07
Get AMI ID from a packer build
packer build packer.json 2>&1 | sudo tee output.txt
tail -2 output.txt | head -2 | awk 'match($0, /ami-.*/) { print substr($0, RSTART, RLENGTH) }' > sudo ami.txt