Skip to content

Instantly share code, notes, and snippets.

View andrewhodel's full-sized avatar

Andrew Hodel andrewhodel

View GitHub Profile
@andrewhodel
andrewhodel / go-pprof.md
Last active April 12, 2024 01:31
Go profiling with pprof

Importing net/http/pprof adds HTTP endpoints to an existing HTTP or HTTPS server without those that serve profile files that can be viewed or charted with a command line tool.

import into the go program

import _ "net/http/pprof"

If your application is not already running an http or https server, add "net/http" to the program imports and the following code to your main function:

go func() {
	http.ListenAndServe(":8550", nil)
@andrewhodel
andrewhodel / rc.local-amazon-linux-2023
Created August 2, 2023 00:35
rc.local on amazon linux 2023
sudo systemctl status rc-local
sudo systemctl enable rc-local
sudo systemctl start rc-local
sudo systemctl status rc-local
# it doesn't start because /etc/rc.d/rc.local does not exist
sudo ln -s /etc/rc.local /etc/rc.d/rc.local
@andrewhodel
andrewhodel / ffmpeg_audio_video_files_sync.sh
Last active May 23, 2023 15:31
ffmpeg synchonize audio and video
# trim video file to a certain range of frames
ffmpeg -i render0000-28914.mp4 -vf select="between(n\,0\,61),setpts=PTS-STARTPTS" one.mp4
# display number of frames in a video file
ffmpeg -i one.mp4 -f null /dev/null
# add audio to video file at the start and extend the audio to the end of the video with silence
ffmpeg -i one.mp4 -i electricity-zap.mp3 -filter_complex "[1:0]apad" -shortest test.mp4
# add audio to video file and leave audio length as is, -stream_loop will loop the audio faster than the video with this file
@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]
#!/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 / 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">
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
)
func main() {
@andrewhodel
andrewhodel / network_congestion_linux.sh
Last active August 29, 2022 23:27
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
@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 / 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);