Skip to content

Instantly share code, notes, and snippets.

View medigeek's full-sized avatar
💭
▶️ Entering flow state✨

Savvas Radevic medigeek

💭
▶️ Entering flow state✨
View GitHub Profile
@medigeek
medigeek / mc-validate-messages.js
Created November 21, 2022 16:36
translate mailchimp error messages - plus mc_gdpr "Please choose an option." and others - mc-validate-messages.js
/**
Source: https://downloads.mailchimp.com/js/mc-validate-messages.js
Reason: Couldn't find "Please choose an option.".
Ended up discovering it myself, beautified the js link:
https://s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js
Also found:
zipcodeUS: "The specified US ZIP Code is invalid",
skip_or_fill_minimum: "Please either skip these fields or fill at least {0} of them.",
skip_or_complete_group: "Please supply missing fields.",
@medigeek
medigeek / cache_warmup.sh
Created July 26, 2021 13:52
asynchronous crawler / warmer based on sitemap.xml
#!/bin/bash
#run multiple concurrent connections to speed up cache warming
#install eliashaeussler/cache-warmup
mkdir cache-warmer-elias
cd cache-warmer-elias
composer require eliashaeussler/cache-warmup
#run it
@medigeek
medigeek / croncrawler.sh
Created May 16, 2021 20:40
magento 2 litemage crawler script
#!/bin/bash
# 1. prepare a sitemap url for the site in magento 2
# 2. download M2-crawler.sh from https://docs.litespeedtech.com/lscache/litemage/crawler/
# 3. add this script. it will run for 43200 seconds (12 hours) and stop.
cd "$(dirname "$0")"
#timeout after x seconds
echo "Starting litemage crawler script in $PWD"
timeout 43200 bash M2-crawler.sh -m -r https://example.com/media/sitemap.xml || echo "Process Litemage crawler timed out"
@medigeek
medigeek / magento-invalidate-index.php
Created July 9, 2021 15:00
Invalidate magento 2 reindex
<?php
//set your indexer to update on schedule
//and make sure your cronjob for magento is running
header("Content-type: text/plain");
//Assuming the php script is in pub/ subfolder. You can put it wherever.
chdir(__DIR__.'/../');
$out = shell_exec('php bin/magento indexer:reset');
echo("\n".$out."\n");
@medigeek
medigeek / python-pandas-split-every-n-rows.py
Created July 7, 2021 15:19
Python pandas - split csv file every n rows
#!/usr/bin/python
import pandas as pd
import numpy as np
import csv
#get every 10000 rows
#group by 0,1,2,3,4,...
#df2[np.arange(len(df2))//10000==0].to_csv('out0.csv', index=False)
@medigeek
medigeek / exportProductsExample.php
Created January 28, 2021 19:54
Magento 2 script - export a product list (product name, sku and status)
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
use Magento\Framework\App\Bootstrap;
function prepareCsv($csvData, $filename = "exportDataExample.csv", $delimiter = ',', $enclosure = '"'){
$f = fopen('php://memory', 'w');
$first = true;
@medigeek
medigeek / timeperiodwithstepping
Created September 25, 2020 08:59
getting a time period with stepping in php (I know, I know... CarbonPeriod)
<?php
printf("<pre>\n");
$secStep = 5;
$a = strtotime("2020-09-24 07:04:35 UTC");
$b = strtotime("2020-09-24 07:05:50 UTC");
var_dump($a);
var_dump($b);
@medigeek
medigeek / test-spurious-arguments.php
Created August 8, 2020 21:18
Why is declare(strict_types=1); important -- test with spurious (extra) arguments passed to methods
<?php
declare(strict_types=1);
//see results:
//using declare(strict_types=1): https://3v4l.org/XJYlJ
//commented out declare(strict_types=1): https://3v4l.org/1bD85
class Fruit {
// Properties
private string $name;
@medigeek
medigeek / carbon-test-tz-conversion.php
Created July 7, 2020 11:00
test time zone conversion using carbon
<?php
// date/time variables using CarbonImmutable: https://carbon.nesbot.com/docs/
//set user time zone
$userTimeZone = 'Europe/London';
//======================= UTC ==============================================
//now in UTC
//CarbonImmutable i.e. don't change the hour value when switching timezones
$nowUTC = CarbonImmutable::now('UTC');
//$nowUTC = CarbonImmutable::parse('2020-05-31 23:12:58 UTC');
@medigeek
medigeek / logrotate_script_platform.sh
Last active June 20, 2020 21:55
logrotate script for platform.sh -- can be modified for other purposes
#!/usr/bin/env bash
set -e
SCRIPTDIR=$(dirname "$0")
SCRIPTREALPATH=$(realpath $(dirname "$0"))
#cd "$SCRIPTDIR"
#echo $SCRIPTREALPATH