Skip to content

Instantly share code, notes, and snippets.

View matteomattei's full-sized avatar

Matteo Mattei matteomattei

View GitHub Profile
@matteomattei
matteomattei / backup_mysql.php
Last active October 13, 2020 00:47
Backup MySQL schema and data from PHP
<?php
$DBHOST = 'localhost';
$DBNAME = 'test';
$DBUSER = 'username';
$DBPASS = 'password';
$compression = TRUE;
$dst_dir = '/tmp';
$DBH = new PDO("mysql:host=".$DBHOST.";dbname=".$DBNAME."; charset=utf8", $DBUSER, $DBPASS);
@matteomattei
matteomattei / clone_mysql_schema_with_mysqli.php
Last active October 14, 2016 16:58
clone mysql database schema using mysqli PHP driver
<?php
/********************* START CONFIGURATION *********************/
$DB_SRC_HOST='localhost';
$DB_SRC_USER='root';
$DB_SRC_PASS='password';
$DB_SRC_NAME='database1';
$DB_DST_HOST='localhost';
$DB_DST_USER='root';
$DB_DST_PASS='password';
@matteomattei
matteomattei / raspberrypi_image_resize.sh
Last active July 8, 2019 09:44
Raspberry Pi image resize (shrink)
#!/bin/bash
#
# Copyright 2016 - Matteo Mattei <[email protected]>
# This script is intended to be used to shrink raspberry pi images
# created with dd client command.
# Check if you are root
if [ ! $(id -u) -eq 0 ]; then
echo "ERROR: This program must run as root"
exit 1
@matteomattei
matteomattei / apache_maxclients_calculator.sh
Last active October 9, 2018 19:02
This script calculates the MaxClients directive in Apache MPM_prefork module.
#!/bin/bash
TOTAL_MEMORY=$(grep "^MemTotal:" /proc/meminfo | awk '{print $2}')
MYSQL_MEMORY=$(ps aux | grep mysql | grep -v "grep" | grep "^mysql" | awk '{print $6}' | sort | head -n 1)
APACHE_MEMORY_PROCESSES=$(ps aux | grep 'apache' | grep -v "grep" | awk '{print $6}' | sort)
APACHE_INSTANCES=0
APACHE_TOTAL_MEMORY=0
for i in ${APACHE_MEMORY_PROCESSES}
do
@matteomattei
matteomattei / test_http.py
Last active July 8, 2021 05:55
HTTP/HTTPS GET and POST (including files) with built-in python modules
#!/usr/bin/env python3
# This script performs a GET and a POST request through HTTP/HTTPS using
# builtin python3 moudules. There is also a class to encode files for upload!
import urllib.request
import http.client
import mimetypes
import codecs
import uuid
import binascii
@matteomattei
matteomattei / wget_build.sh
Last active October 31, 2023 03:35
Cross compile wget statically for ARM
#!/bin/bash
VERSION="1.17"
if [ ! -f wget-${VERSION}.tar.xz ]; then
wget http://ftp.gnu.org/gnu/wget/wget-${VERSION}.tar.xz
fi
rm -rf wget-${VERSION} build
tar xJf wget-${VERSION}.tar.xz
@matteomattei
matteomattei / index.html
Created September 25, 2015 10:58
Ajax upload example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Ajax upload example</title>
<link type="text/css" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript">
function TransferCompleteCallback(content){
@matteomattei
matteomattei / my.label
Last active April 23, 2023 08:56
Print labels with Dymo LabelWriter 450 using Python
<?xml version="1.0" encoding="utf-8"?>
<DieCutLabel Version="8.0" Units="twips">
<PaperOrientation>Portrait</PaperOrientation>
<Id>Small30332</Id>
<PaperName>30332 1 in x 1 in</PaperName>
<DrawCommands>
<RoundRectangle X="0" Y="0" Width="1440" Height="1440" Rx="180" Ry="180" />
</DrawCommands>
<ObjectInfo>
<TextObject>
@matteomattei
matteomattei / megafusebackup.sh
Last active September 2, 2016 06:22
Mega server backup using megafuse
#!/bin/bash
SERVER="web1"
DAYS_TO_BACKUP=7
WORKING_DIR="/root/backup_tmp_dir"
BACKUP_MYSQL="true"
MYSQL_USER="root"
MYSQL_PASSWORD="your_db_root_password"
@matteomattei
matteomattei / megabackup.sh
Last active July 1, 2019 11:35
Mega server backup using megatools
#!/bin/bash
SERVER="servername"
DAYS_TO_BACKUP=7
WORKING_DIR="/root/backup_tmp_dir"
BACKUP_MYSQL="true"
MYSQL_USER="root"
MYSQL_PASSWORD="MyRootPassword"