dP.  .dP .d8888b. .d8888b. 88d888b. d888888b
 `8bd8'  88'  `"" Y8ooooo. 88'  `88    .d8P'
 .d88b.  88.  ...       88 88        .Y8P   
dP'  `dP `88888P' `88888P' dP       d888888P
    
PROGRAMMER /ˈprōˌɡramər/
A person who solves problems you didn't know you had in ways you don't understand.
public wərk snippets contact

Code Snippets

The essential components of a golang "worker pool" using a semaphore channel to control the number of concurrent executions. This is just a basic example to demonstrate the concepts, values of combining (fixed size) queues and goroutines without adding complexity like generics or multiple pools.
package main
import (
"fmt"
"time"
)
const maxWorkers = 2
func processTask(task int) {
fmt.Printf("Processing task %d\n", task)
time.Sleep(time.Second)
fmt.Printf("Done task %d\n", task)
}
func runInWorkers(tasks []int) {
sem := make(chan struct{}, maxWorkers)
for _, task := range tasks {
sem <- struct{}{} // Acquire semaphore
go func(task int) {
defer func() { <-sem }() // Release semaphore
processTask(task)
}(task)
}
// Wait for all workers to finish
for i := 0; i < maxWorkers; i++ {
sem <- struct{}{}
}
}
func main() {
tasks := []int{1, 2, 3, 4, 5}
runInWorkers(tasks)
}
Script to quickly launch EC2 instances in a preset VPC, type, etc
#!/bin/bash
# ======= Configuration =======
REGION="us-east-1" # Set your AWS region
INSTANCE_TYPE="t2.micro"
KEY_NAME="your-key-pair-name"
SECURITY_GROUP_ID="sg-xxxxxxxxxxxxxxx"
SUBNET_ID="subnet-xxxxxxxxxxxxxxxxx"
UBUNTU_OWNER="099720109477" # Canonical (Ubuntu's AWS account ID)
UBUNTU_NAME_FILTER="ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"
# ==============================
# Input: instance suffix name
if [ -z "$1" ]; then
echo "Usage: $0 <instance-name-suffix>"
exit 1
fi
INSTANCE_NAME="temp-instance-$1"
# Get latest Ubuntu AMI ID
echo "Fetching latest Ubuntu AMI ID for $REGION..."
AMI_ID=$(aws ec2 describe-images \
--region "$REGION" \
--owners "$UBUNTU_OWNER" \
--filters "Name=name,Values=$UBUNTU_NAME_FILTER" "Name=state,Values=available" \
--query 'Images | sort_by(@, &CreationDate)[-1].ImageId' \
--output text)
if [ -z "$AMI_ID" ]; then
echo "Failed to find Ubuntu AMI."
exit 1
fi
# Launch the EC2 instance
echo "Launching EC2 instance named '$INSTANCE_NAME' with 50GB root volume..."
INSTANCE_ID=$(aws ec2 run-instances \
--region "$REGION" \
--image-id "$AMI_ID" \
--count 1 \
--instance-type "$INSTANCE_TYPE" \
--key-name "$KEY_NAME" \
--security-group-ids "$SECURITY_GROUP_ID" \
--subnet-id "$SUBNET_ID" \
--block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"VolumeSize\":50,\"VolumeType\":\"gp3\",\"DeleteOnTermination\":true}}]" \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME}]" \
--query 'Instances[0].InstanceId' \
--output text)
if [ -z "$INSTANCE_ID" ]; then
echo "Failed to launch instance."
exit 1
fi
# Wait for the instance to be in 'running' state
echo "Waiting for instance to be in 'running' state..."
aws ec2 wait instance-running \
--region "$REGION" \
--instance-ids "$INSTANCE_ID"
# Get and print the private IP address
PRIVATE_IP=$(aws ec2 describe-instances \
--region "$REGION" \
--instance-ids "$INSTANCE_ID" \
--query 'Reservations[0].Instances[0].PrivateIpAddress' \
--output text)
if [ -z "$PRIVATE_IP" ]; then
echo "Failed to retrieve private IP address."
exit 1
fi
echo "Private IP: $PRIVATE_IP"
How to adjust Softail rear shock preload

FLSTN Rear Shock Adjustment

So Softails's come from the factory with the lightest setting on the read shocks which is only good for solo riders weighing less than 180 lbs. If you weigh more yourself or you want to ride with a pack, a passenger or both - you need to adjust the preload on the rear shocks to safe your back, your passengers back and potentially your ride. A properly adjusted suspension makes all the difference!

Both the owners manual and service manual have a section describing the basics of adjusting the preload, but nothing from HD offers the actual steps to take or any guide to adjust for a specific weight. The procedure is very simple but without a guide you're left to trial and error and a lot of jacking or relying on a shop to make the adjustment for you. This is based on articles posted online by dealers and HD service shops (and doesn't that defeat the purpose of having an HD in the first place?).

This is not an exact adjustment, and perhaps that's why HD doesn't spell it out. Below there are guidelines to start from, but you adjust for a softer or stiffer ride to match your preference. Just make sure you never adjust one shock without adjusting the other!

Warnings

Disclaimer: It should go without saying but just in case it's not obvious:

Be safe, think it through and don't hurt yourself!

  • Doing this properly requires jacking the bike up. Otherwise you'll be trying to lift the weight of the bike with a little wrench which is less than a foot long. (leverage not in your favor)
  • Anytime you jack up your bike you must make sure you strap it down before you go putting anything fragile like your head underneath!
  • The most critical step to adjusting dual shocks is setting them both to the same position/adjustment. The process below tells you how, but make sure you don't mess this up. There are plenty of videos online capturing the horror awaiting the rider who doesn't heed this warning. Do not add your name to the list!

Tools required:

  • A bike jack or lift, straps and the knowledge of how to use them to safely and securely lift your bike up enough to take the weight off the rear wheel.
  • Spanner Wrench: HD part 94448-82B
  • 11/16 open ended wrench

Prep

  1. Jack the bike up so the rear tire is off the ground. The more clearance you have the easier it is. Don't forget to strap the bike down.
  2. Loosen the jam nut all the way out. This is the 11/16" nut the wrench is for. You may need some penetrating lube to break it free.
  3. With the spanner wrench, turn the adjuster plate counter-clockwise (this will cause the shock housing to move towards the front of the bike) until it is all the way up against the jam nut. This is your starting position.
  4. Then take a sharpie, paint pen or a piece of tape to mark the bottom center of the adjuster plate. You can skip this step if there is already a mark from a previous adjustment/owner and the marks on both shocks are in the same position. This is a reference point so you can adjust both of them the same. Don't worry if the two shocks are not in exactly the same position - the physical structure of the shocks themselves. This is normal and does not change anything here. This is actually why we need to mark the adjustment plate with a pen or tape.

Adjustment

Now you're ready to adjust the shocks to your weight/load/preference.

  1. With the spanner wrench, turn the adjuster plate clockwise no more than 4 complete turns by counting how many times the mark from step 4 crosses the 6 o'clock position. 0 turns is the stiffest setting, and 4 turns is the softest setting.

    Ballpark weight settings:

    First determine your load weight. This includes your weight as the rider (with whatever gear you wear), the weight of a passenger unless you're riding solo, and anything else you're packin' on the bike.

    • 4 turns for load up to 180 lbs
    • 3 turns for a load from 180 lbs to 235 lbs
    • 2 turns for a load from 235 lbs to 300 lbs
    • 1 turn for a load from 300 lbs to 375 lbs
    • 0 turns for a load over 375 lbs
  2. Once you have your adjustment made, lock it in position by tightening up the jam nut against the adjuster plate by turning the nut clockwise while holding the adjuster plate in place with the spanner wrench.

  3. Now repeat the exact same process on the other shock. The key is to adjust both shocks equally.

The most simple method to post a message to slack via an 'incoming webhook' from PHP
<?php
function post_slack_message($msg) {
$opts = [
'http' => [
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => json_encode([
'attachments' => [
[
'color' => '#ff0000',
'blocks' => [
[
'type' => 'header',
'text' => [
'type' => 'plain_text',
'text' => $msg,
]
]
]
],
]
]),
'ignore_errors' => true,
]
];
$response = file_get_contents(getenv('SLACK_WEBHOOK_URL'), false, stream_context_create($opts));
if($response !== 'ok') {
var_dump($http_response_header); // dump headers
var_dump($response); // dump body as well (usually where the problem can be found)
throw new \Exception("Unable to post to slack");
}
}
post_slack_message('hi there');
<?php
function post_slack_message_styled($msg) {
$opts = [
'http' => [
'method' => 'POST',
'header' => "Content-type: application/json\r\n",
'content' => json_encode([
'text' => $msg,
]),
'ignore_errors' => true,
]
];
$response = file_get_contents(getenv('SLACK_WEBHOOK_URL'), false, stream_context_create($opts));
if($response !== 'ok') {
var_dump($http_response_header); // dump headers
var_dump($response); // dump body as well (usually where the problem can be found)
throw new \Exception("Unable to post to slack");
}
}
post_slack_message_styled('hi there');
Posting from Dart to a URL with a redirect: Since Dart's stock http package (and even the dio package) chose to handle redirects differently than basically every other language+package out there and disregard redirect responses returned to a POST request you have to do a little extra work. Worse than anything is every solution I have found was #doingItWrong and making the followup request a POST request complete with sending the payload each time. Even those approaches fail to successfully POST to a google app script (GAS). All of this is quite ironic since Dart is itself a product of Google. This is a simple proof of concept and only supports one redirect which all that is needed for a GAS doPost endpoint, but could be modified easily to accomodate other situations.
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart';
String url =
"https://script.google.com/macros/s/YOUR_DEPLOYMENT_HASH_HERE/exec";
final data = {
'foo': 456,
'bar': 'that',
'biz': 23,
};
void main(List<String> args) {
postRequestWithRedirect(url, jsonEncode(data)).then((r) {
print('code: ' + r.statusCode.toString());
print('body: ' + r.responseBody.toString());
});
}
class postRequestWithRedirectResult {
num? statusCode;
String? responseBody;
}
Future<postRequestWithRedirectResult> postRequestWithRedirect(
String url,
String body,
) async {
var httpclient = HttpClient();
HttpClientRequest request;
HttpClientResponse response;
postRequestWithRedirectResult result = postRequestWithRedirectResult();
try {
request = await httpclient.postUrl(Uri.parse(url));
request.headers.contentLength = body.length;
request.write(body);
response = await request.close();
final location = response.headers.value(HttpHeaders.locationHeader);
if (response.statusCode == 302 && location != null) {
request = await httpclient.getUrl(Uri.parse(location));
response = await request.close();
result.statusCode = response.statusCode;
result.responseBody = await response.transform(utf8.decoder).join();
} else {
result.statusCode = response.statusCode;
result.responseBody = await response.transform(utf8.decoder).join();
}
} finally {
httpclient.close(force: true);
return result;
}
}