Skip to content

Instantly share code, notes, and snippets.

@Shagshag
Shagshag / backup.sh
Created October 20, 2021 09:20
Backup files and databases to FTP with space and old backup management
#!/bin/bash
### Configuration ###
### MYSQL ###
MUSER="" # MySQL user, must can execute 'show databases'
MPASS="" # MySQL password
MHOST="" # MySQL host
### FTP ###
@Shagshag
Shagshag / convert-gls-trackid.php
Created September 15, 2021 10:24
Convert GLS track ID to GLS reference
<?php
// based on https://stackoverflow.com/questions/10471991/convertions-between-decimal-and-base-36#10472259
function convertReferenceToTrackID($number) {
$offset = 2721109907456;
$base = 36;
$in = (string) ($number + $offset);
$out = '';
@Shagshag
Shagshag / PageNotFoundController.php
Created December 15, 2020 18:08
Allow product image with ID > 9 999 999 in PrestaShop
<?php
class PageNotFoundController extends PageNotFoundControllerCore
{
public function initContent()
{
list($filename) = explode('?', substr($_SERVER['REQUEST_URI'], 6));
if (preg_match('/([0-9]+)(\-[_a-zA-Z0-9-]*)?\/.*\.jpg/', $filename, $matches)) {
$path = _PS_ROOT_DIR_.'/img/p/'.implode('/', str_split($matches[1], 1)).'/'.$matches[1].$matches[2].'.jpg';
if (file_exists($path)) {
@Shagshag
Shagshag / vue3_inputdate.js
Created November 24, 2020 08:58
input-date for vue3
// adapted from https://acdcjunior.github.io/how-bind-date-object-to-input-date-vue.js-v-model.html
{
props: ['modelValue'],
emits: ['update:modelValue'],
setup() {
const dateToYYYYMMDD = (d) => {
// alternative implementations in https://stackoverflow.com/q/23593052/1850609
try {
return d && new Date(d.getTime()-(d.getTimezoneOffset()*60*1000)).toISOString().split('T')[0];
} catch(e) {
@Shagshag
Shagshag / vue3_nl2br.js
Created November 24, 2020 08:45
nl2br for vue3
// Adapted from https://github.com/inouetakuya/vue-nl2br/
{
props: {
tag: {
type: String,
required: true,
},
text: {
type: String,
required: true,
@Shagshag
Shagshag / empty_folder.php
Created October 4, 2018 08:25
Delete all files and subfolders in the current folder
<?php
/**
* Delete all files and subfolders in the current folder
* I use it to start a new project
* Be careful : There is no confirmation, this script deletes everything it can, including itself
*/
// https://stackoverflow.com/a/17161106/2530962 php glob - scan in subfolders for a file
function rglob($pattern, $flags = 0) {
$files = (array) glob($pattern, $flags);
@Shagshag
Shagshag / wp_logtoadmin.php
Created May 25, 2018 02:18
This script allows to login to WordPress without password. Put it on the root of your blog by FTP then visit the URL http://yourblog/wp_logtoadmin.php
<?php
/**
* 1. Change the password below, it's encoded with m5d https://duckduckgo.com/?q=md5+toto
* 2. Put this file at the root of your shop
* 3. Visit the URL http://yourblog/wp_logtoadmin.php
**/
$auth_pass = "f71dbe52628a3f83a77ab494817525c6"; //toto
// display login screen
if (!isset($_POST['pass'])
@Shagshag
Shagshag / netinstall.php
Last active May 14, 2020 16:55
WordPress netinstall : This script download and unzip the latest version of WordPress
<?php
// This script download and unzip the latest version of WordPress
//
// Put this file in the folder where you want to install WordPress
// Visit it with your browser
// Follow the installation process
$path = dirname(__FILE__);
$local_file = $path.'/latest.zip';
$remote_file = 'https://wordpress.org/latest.zip';
@Shagshag
Shagshag / delete_presta.php
Last active March 16, 2018 14:35
Delete a PrestaShop installation. Put it by FTP in the PrestaShop root folder and open it in a browser. ⚠ it deletes all files in the PrestaShop folder and all table with the PrestaShop prefix. ⚠⚠ It doesn't ask confirmation
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$root = dirname(__FILE__);
$server = false;
$user = false;
$password = false;
$database = false;
@Shagshag
Shagshag / tumbler-gist-insert.html
Last active May 25, 2018 02:34 — forked from tryvin/tumbler-gist-insert.html
Tumblr gist insert
<script src="//static.tumblr.com/fpifyru/VCxlv9xwi/writecapture.js"></script>
<script type="text/javascript">
$(function() {
$("a[href]").each(
function(index, element) {
if ( $(element).text().indexOf('gist.github.com') > 0 ) {
var divElement = $('<div></div>');
$(element).after(divElement);
writeCapture.html(divElement, '<script src="'+$(element).text()+'.js"></'+'script>');