Skip to content

Instantly share code, notes, and snippets.

View andrewhodel's full-sized avatar

Andrew Hodel andrewhodel

View GitHub Profile
/*
Copyright 2016 Andrew Hodel
[email protected]
LICENSE
This program, design, source code, document or sequence of bits is licensed and the terms issued below must be followed. By using or reading or including this content you are automatically a licensee granted permission by the licensor (Andrew Hodel) under the following terms.
Usage - You may use this content under the following conditions:
@andrewhodel
andrewhodel / aws.js
Last active October 13, 2020 17:59
aws.js AWS library for Node.JS
var https = require('https');
var crypto = require('crypto');
var get_signature = function(secret_key, auth_date, region, service) {
// return the AWS version 4 signature
// by chaining through 4 different strings and creating a sha256 hash for each
// to generate a 256 bit key
//console.log('get_signature():', secret_key, auth_date, region, service);
@andrewhodel
andrewhodel / iptables-rate-limit
Last active July 31, 2023 02:29
iptables-rate-limit
sudo iptables -F
sudo ip6tables -F
# limit traffic with destination port 443 to 80 NEW CONNECTIONS per minute
# --hashlimit-burst is when the rate limiting starts counting, at the first new connection
# --hashlimit-htable-expire is in milliseconds and is required to be at least as long as the --hashlimit-above interval
# use a different --hashlimit-name with each service
# accept port traffic
@andrewhodel
andrewhodel / linediff.js
Created June 24, 2021 17:54
diff two files by line with any type line character
var fs = require('fs');
var o = fs.readFileSync('./file1.txt').toString();
var oo = fs.readFileSync('./file2.txt').toString();
var get_lines_array = function(str) {
if (typeof(str) != 'string') {
console.log('must pass string to get_lines_array()');
process.exit(1);
@andrewhodel
andrewhodel / javascript-nodejs-modules.md
Last active September 7, 2024 03:29
nodejs modules

ECMAScript modules sometimes known as ES modules

These use the module loader system in the Browser.

When a module is loaded, it has a special name that is only available within this module loader system. The special name is why import doesn't work with modules that import other modules using that special name, because import() cannot assign that name.

Loading is possible with:

  1. import is capable of loading the module's script and setting the special name of the module. This allows other modules to access it. It is not capable of load or error events or a retry function or subresource integrity.
  2. import() is capable of a Promise but it does not allow access to the special name of the module and does not have subresource integrity.
@andrewhodel
andrewhodel / network_congestion_linux.sh
Last active February 12, 2025 16:17
network congestion steps (latency and loss) for linux (iptables and tc)
#!/bin/sh
remove_rules()
{
echo "removing iptables and tc rules"
sudo iptables -F
echo "removing tc qdisc for ${netif}"
sudo tc qdisc del dev ${netif} root
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
@andrewhodel
andrewhodel / map.html
Last active January 23, 2023 04:45
OpenLayers v3 javascript map library working example
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="/ol.css" type="text/css">
<!--https://openlayers.org/en/v3.20.1/apidoc/-->
<script src="/ol.js" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 400px; width: 400px;"></div>
<script type="text/javascript">
#!/bin/sh
for i in ./*; do
echo ${i}
magick ${i} -quality 80 ${i}.webp
magick ${i} -resize 250x -quality 80 ${i}-small.webp
done
@andrewhodel
andrewhodel / email_domain_validation.js
Last active June 16, 2023 21:10
world email and domain validation in javascript
var email_validate = function(s) {
if (typeof(s) !== 'string') {
return false;
}
var parts = s.split('@');
if (parts.length !== 2) {
// should be [email protected]