Skip to content

Instantly share code, notes, and snippets.

import 'dart:typed_data';
import 'dart:async';
import 'dart:math' as math;
enum AcknowledgementResult {
AckReceived,
NakReceived,
CrcCommand,
EotReceived,
@trabulium
trabulium / quickie_bash_challenge_bots
Created March 17, 2024 02:29
Tails the apache / nginx logs for the last 5000 and excludes requests to static assets and then either block on firewall or challenges on Cloudflare
#!/bin/bash
LOG=/var/www/path_to/log/access.log
COUNTS=`/usr/bin/tail -5000 $LOG | grep -iv "Cloudflare-Healthchecks\|M2ePro\|UptimeRobot\|api\| 403 \|googlebot\|AdsBot-Google\|bing\|png\|jpg\|gif\|svg\|css\|js" | awk {'print $1'} | sort | uniq -c | sort -rn | head -1 | awk {'print $1'}`
IPADDRESS=`/usr/bin/tail -5000 $LOG | grep -iv "Cloudflare-Healthchecks\|M2ePro\|UptimeRobot\|api\| 403 \|googlebot\|AdsBot-Google\|bing\|png\|jpg\|gif\|svg\|css\|js" | awk {'print $1'} | sort | uniq -c | sort -rn | head -1 | awk {'print $2'}`
COUNTRY=`/usr/bin/geoiplookup $IPADDRESS | grep Country | awk {'print $5'}`
@trabulium
trabulium / regex_check_au_street
Created September 19, 2023 02:29
Checks if the string matches any of the forms of Australian Streets, Roads, Alleys, Boulevard, Drive, Esplanade etc.
$pattern = "/\d+[A-Za-z]{0,1}[ ](?:[A-Za-z0-9'.-]+[ ]?)+(?:Alley|Ally|Arcade|Arc|Avenue|Av|Ave|Boulevard|Blv|Blvd|Bvd|Bypass|Bypa|Circuit|Circle|Cir|Ct|Cct|Close|Cl|Corner|Crn|Court|Ct|Crt|Crescent|Cres|Crs|Cul-de-sac|Cds|Drive|Dve|Dr|Esplanade|Esp|Gardens|Green|Grn|Grove|Gr|Heights|Highway|Hwy|Junction|Jnc|Lane|Lane|Link|Link|Loop|Mews|Mews|Outlook|Pane|Parade|Pde|Place|Pl|Ridge|Rdge|Rise|Road|Rd|Square|Sq|Street|ST|St|Terrace|Tce|The|Way|Walk|Box|Driftway)\.?/";
@trabulium
trabulium / nema17_chatGPT_first_attempt
Created February 3, 2023 04:52
chatGPT 1st Attempt to create FreeCAD adaptor for Nema17
import FreeCAD
import Part
def create_adapter_plate():
# Define Nema17 dimensions
width = 42.3
length = 42.3
bolt_diameter = 4.0
shaft_diameter = 5.0
height = 10.0
@trabulium
trabulium / nema17_chatGPT_2nd_attempt
Last active February 3, 2023 04:51
ChatGPT output of an adaptor plate for a Nema17 stepper motor for FreeCAD
import FreeCAD
import Part
def create_adapter_plate():
# Define Nema17 dimensions
width = 42.3
length = 42.3
bolt_diameter = 4.0
shaft_diameter = 5.0
height = 10.0
@trabulium
trabulium / clear_amp_cache.php
Created April 30, 2019 07:50
php script to Bulk Update AMP cache to clear AMP urls
<?php
function urlsafe_b64encode($string) {
return str_replace(array('+','/','='),array('-','_',''), base64_encode($string));
}
$ampBaseUrl="https://www-example-com-au.cdn.ampproject.org";
$file = fopen("urls.txt", "r") or exit("Unable to open file!");
@trabulium
trabulium / simple_orphaned_products
Last active August 22, 2018 04:11
Magento 1: Find orphaned simple products with no parent configurable
select
type_id,sku, cpev.value,
CASE when cpei2.value = 1 THEN "Enabled" ELSE "Disabled" END
from catalog_product_entity a
left join catalog_category_product cp on cp.`product_id` = a.entity_id
left join catalog_product_relation cpr on cpr.child_id = a.entity_id
left join catalog_product_entity_int cpei on cpei.`entity_id` = a.entity_id AND cpei.attribute_id = '91' #visibility
left join catalog_product_entity_int cpei2 on cpei2.`entity_id` = a.entity_id AND cpei2.attribute_id = '84' #status
left join catalog_product_entity_varchar cpev on cpev.`entity_id` = a.entity_id AND cpev.attribute_id = '60' #name
where
@trabulium
trabulium / mage1_remove_fax_bad_phone
Created July 6, 2018 00:10
Magento 1 - Remove Fax #'s and remove email address and Alphanumeric from Phone Field on customer accounts
Attribute IDs 32, 178 for Fax
Attribute IDs 31, 175 for Phone
update customer_address_entity_varchar set value = '' where attribute_id in (32,178) and value != '';
update customer_address_entity_varchar set value = '' where attribute_id in (31,175) and (value REGEXP '^[A-Za-z]+$' OR value like ('%@%'));
@trabulium
trabulium / magento1_clone_gallery_position_label_new_store
Last active July 6, 2018 00:08
Copy Image position and label from Store Id 6 to Store ID 5 where position is '2'
@trabulium
trabulium / am_shopby_value
Created May 28, 2018 07:05
Bulk add am_shop_by images based on the brand name / meta title
UPDATE am_shopby_value
SET img_medium = Concat(Lower(REPLACE (meta_title, ' ', '-')), '.jpg')
WHERE img_medium = ''
AND filter_id = 1
AND meta_title NOT LIKE ( "a:%" );