Skip to content

Instantly share code, notes, and snippets.

View ClayRabbit's full-sized avatar

Andrey Chesnakov ClayRabbit

View GitHub Profile
@ClayRabbit
ClayRabbit / duplicate.sh
Last active June 4, 2025 12:02 — forked from tom-it/duplicate.sh
Opencart 3.0 clone default theme
#!/bin/bash
if [ "$#" -ne 3 ] || ! [ -d "$1" ]; then
echo "Usage: $0 THEMEDIR $1 ADMINDIR $2 COPYNAME" >&2
exit 1
fi
#The admin controller needs a capitalized theme name
function capitalize_first(){
string0=$COPY
@ClayRabbit
ClayRabbit / mysql_optimize_db.sh
Last active March 5, 2025 07:08
MySQL database optimisation
#!/bin/sh
# in case of `mysqlcheck -o` not available
[ -z "$1" ] && exit 1
db="$1"
for table in $(mysql -Nse "SHOW TABLES" "$db"); do
mysql -Nve "OPTIMIZE TABLE \`$table\`" "$db"
done
@ClayRabbit
ClayRabbit / example.htm
Created December 11, 2024 15:53
read-more using bootstrap
<style>
.read-more.collapse {
position: relative;
display: inherit;
height: auto !important;
transition: none !important;
}
.read-more.collapse.in,
.read-more.collapsing {
position: relative;
@ClayRabbit
ClayRabbit / mc_install.sh
Last active October 24, 2024 16:09
install Midnight Commander locally (without root)
#!/bin/sh
# install Midnight Commander locally (without root)
wget https://download.opensuse.org/repositories/home:/laurentwandrebeck:/mc/CentOS_7/x86_64/mc-4.8.27-1.1.x86_64.rpm
(mkdir rpm && cd rpm/ && rpm2cpio ../mc-4.8.27-1.1.x86_64.rpm | cpio -idv)
echo "export MC_DATADIR=~/rpm/usr/share/mc" >> .bashrc
echo "alias mc=~/rpm/usr/bin/mc" >> .bashrc
cp -rp rpm/usr/libexec/mc/* .local/share/mc/
@ClayRabbit
ClayRabbit / redirect.php
Created February 14, 2024 14:48
Simple PHP 301 redirect script
<?php
/**
* Simple PHP 301 redirect script: Space separаted list of redirects loaded from redirect.txt
*
* @author Andrey Chesnakov
* @link https://clayrabbit.ru
*/
if (!empty($_SERVER['REQUEST_URI']) AND $_SERVER['REQUEST_URI'] != '/' AND file_exists('redirect.txt')) {
$request = explode('?', $_SERVER['REQUEST_URI'], 2);
foreach(file('redirect.txt') as $str) {
@ClayRabbit
ClayRabbit / ttfb.sh
Last active October 23, 2023 06:03 — forked from sandeepraju/ttfb.sh
curl command to check the time to first byte
#!/bin/sh
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -so/dev/null -w"Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" "$1"
@ClayRabbit
ClayRabbit / oc_cron.sh
Last active June 20, 2025 15:33
OpenCart invoker for crontab or CLI
#!/bin/sh
# https://gist.github.com/ClayRabbit/0441561b409fe631a6ab5df88e759b37
# OpenCart invoker for crontab or CLI
# Alternative to `wget -O- -qt 1 https://...`
[ -z "$1" ] && echo "Usage: $0 [options] [admin/]extension/module/route1 [extension/module/route2 ...]" && exit 1
initial_dir="$(pwd)"
oc_dir=$(cd $(dirname "$0") && pwd)
php="$(env which php)"
@ClayRabbit
ClayRabbit / lemp_setup.sh
Last active March 26, 2023 12:59 — forked from RafikFarhad/lemp_setup.sh
LEMP stack installation
#!/bin/sh
HOSTNAME=$(hostname)
sudo apt-get update
sudo apt-get install -y nginx
sudo apt-get install -y mysql-server mysql-client
sudo apt-get install -y php-fpm
sudo apt-get install -y composer
@ClayRabbit
ClayRabbit / cookie.js
Last active October 16, 2024 10:19
JavaScript get/set cookie functions
@ClayRabbit
ClayRabbit / utm2cookie.js
Last active April 16, 2025 14:10
Store UTM parameters from URL into cookie
// Store UTM parameters from URL into cookie
if (window.location.search && (window.location.search.substring(0, 5) === "?utm_" || window.location.search.indexOf("&utm_") !== -1)) {
let days = 30,
expire = new Date(Date.now() + days *60*60*24*1000),
params = new URLSearchParams(window.location.search);
["source", "medium", "campaign", "term", "content"].forEach(param => {
if (params.has("utm_" + param)) {
document.cookie = "utm_" + param + "=" + encodeURIComponent(params.get("utm_" + param)) + "; path=/; expires=" + expire.toGMTString();
} else {
document.cookie = "utm_" + param + "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";