Skip to content

Instantly share code, notes, and snippets.

View Justintime50's full-sized avatar

Justin Hammond Justintime50

View GitHub Profile
@Justintime50
Justintime50 / limit-concurrent-threads-python.py
Created April 10, 2021 03:46
An example of how to limit concurrent threads in Python
import time
from threading import BoundedSemaphore, Thread
def main():
max_num_threads = 100
thread_limiter = BoundedSemaphore(max_num_threads)
# OS's have limits on the number of threads that can be opened at once,
# be aware of that with this number (eg: don't try something like 10,000+)
@Justintime50
Justintime50 / laravel-nested-subfolder-nginx.conf
Last active March 28, 2022 10:24
Host Laravel in a Nested Subfolder/Directory - Nginx Configuration
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/site;
location / {
try_files $uri $uri/ /index.php;
@Justintime50
Justintime50 / reset_mysql_replication.md
Created March 24, 2022 18:46
Reset your MySQL Replication

Resetting MySQL Replication

If you have a master/slave replication setup that comes across something similar to error 1236 where the binlogs get out of sync, you can run the following commands to get things back on track.

# On the master node
SHOW MASTER STATUS;

# On the slave node
STOP SLAVE;
@Justintime50
Justintime50 / insecure-mixed-content-laravel-prod.md
Created February 16, 2022 06:52
Fix the insecure mixed content error in a Laravel production instance.

Insecure or Mixed Content Production Laravel

Make sure your AppServiceProvider.php file has a boot function that looks like this to avoid the was not allowed to run insecure content error in production:

use Illuminate\Support\Facades\URL;

/**
 * Bootstrap any application services.
 *
@Justintime50
Justintime50 / working-with-ssh-keys.md
Last active January 31, 2022 23:15
Run the following commands to generate and copy an SSH key.

Working with SSH Keys

Follow this guide to generate an SSH private/public key pair, retrieve it, or send it to a client machine.

Usage

# 1) Generate an SSH Key
ssh-keygen -t rsa
@Justintime50
Justintime50 / setup-macos-mail-server.md
Last active October 26, 2021 06:04
Setup a Mail Server on macOS - No Dependencies Required!

Setup a Mail Server on macOS

After years of trying to setup a mail server on macOS without requiring dependencies or messing with ports to trick my ISP into letting mail out, I figured out a solution.

Note: This guide is opinionated towards a Gmail setup.

Steps

  1. Backup the existing Postfix configuration:
@Justintime50
Justintime50 / import-export-sql-docker.md
Last active October 10, 2021 06:39
Learn how to import or export SQL from a Docker Container

Import or Export SQL from a Docker Container

To export SQL, you must have permissions to do so (AKA: root).

# Importing SQL
docker exec -i CONTAINER_NAME mysql -uUSERNAME -pPASSWORD DATABASE_NAME < MY_FILE.sql

# Exporting SQL
docker exec -i CONTAINER_NAME mysqldump -uroot -p DATABASE_NAME &gt; MY_FILE.sql
@Justintime50
Justintime50 / package-non-python-assets.md
Created September 23, 2021 16:43
Learn how to package non-Python assets into your Python Package

Package non-Python Assets into your Python Package

There are times where you may need to include non-Python assets in your Python package for distribution. This may include data files or JSON assets from a submodule for example that your Python package needs to reference. By default, Python will not include these assets in the bdist/sdist. You can either include an empty __init__.py file in that submodule (even if the project isn't Python) and rely on the magic of packages=setuptools.find_packages() in setup.py or you can explicitly include those non-Python assets by using the following steps.

  1. In setup.py, include an array of locations to include. These are glob matching patterns. An example of this looks like the following:
package_data={
    'top_level_package': [
 'path/to/assets/one/*.json',
@Justintime50
Justintime50 / aws_ip_range_parser.py
Created September 1, 2021 15:45
Gets the complete list of AWS IP ranges and parses the results
import requests
# Gets the complete list of AWS IP ranges and parses the results
# Usage: venv/bin/python aws_ip_range_parser.py
AWS_IP_URL = 'https://ip-ranges.amazonaws.com/ip-ranges.json'
REGIONS_TO_FILTER = [
'us-east-2',
'us-west-2',
]
@Justintime50
Justintime50 / postal-codes.json
Created June 27, 2021 06:09 — forked from jamesbar2/postal-codes.json
Global postal codes regex formats
[{
"Note": "The first two digits (ranging from 10–43) correspond to the province, while the last two digits correspond either to the city/delivery zone (range 01–50) or to the district/delivery zone (range 51–99). Afghanistan Postal code lookup",
"Country": "Afghanistan",
"ISO": "AF",
"Format": "NNNN",
"Regex": "^\\d{4}$"
}, {
"Note": "With Finland, first two numbers are 22.",
"Country": "Åland Islands",
"ISO": "AX",