Skip to content

Instantly share code, notes, and snippets.

View matteomattei's full-sized avatar

Matteo Mattei matteomattei

View GitHub Profile
@matteomattei
matteomattei / bash_countdown.sh
Last active August 29, 2015 14:03
Simple countdown in Bash
#!/bin/bash
# A simple countdown in Bash
echo -n "countdown..."
for i in 1 2 3 4 5 6 7 8 9 10
do
echo -n -e "\rcountdown... ${i}"
sleep 1
done
echo -e "\nDONE!"
@matteomattei
matteomattei / backup_ftp_plesk_server.sh
Last active August 29, 2015 14:03
Backup last 7 days of httpdocs and MySQL data using FTP. This script is intended to be used in a server with Plesk.
#!/bin/bash
TMP_FOLDER="/root/daily_backup"
MYSQL_FOLDER="${TMP_FOLDER}/MYSQL"
WWW_FOLDER="${TMP_FOLDER}/WWW"
LOCAL_WWW_FOLDER="/var/www/vhosts"
FTP_USER="ftp_username"
FTP_PASS="ftp_password"
FTP_HOST="ftp_host"
MAIL_ALERT="notification@email.com"
@matteomattei
matteomattei / backup_ftp_plesk_server1.sh
Last active June 16, 2021 07:36
A simple script to backup Plesk server and store data in a remote FTP
#!/bin/bash
set -e
FTP_USER="ftp_user"
FTP_PASS="ftp_password"
FTP_HOST="ftp_host"
# REMOVE BACKUPS OLDER THAN 7 DAYS
FILES=$(lftp -e 'cd pleskbackup; cls --sort="date"; exit;' -u ${FTP_USER},${FTP_PASS} ${FTP_HOST})
if [ $(echo "${FILES}" | wc -l) -gt 7 ];
@matteomattei
matteomattei / svn_stats.sh
Created July 8, 2014 07:47
How to calculate the number of inserted, deleted and modified lines in Subversion
#!/bin/bash
FIRST_REV=${1}
LAST_REV=${2}
REPO_ROOT=${3}
if [ -z "${FIRST_REV}" ] || [ -z "${LAST_REV}" ] || [ -z "${REPO_ROOT}" ]
then
echo "usage: ${0} first_revision last_revision repository_root"
exit 1
@matteomattei
matteomattei / crc32.py
Created July 8, 2014 07:52
Calculate CRC32 of a file in Python
#!/usr/bin/env python
import binascii
def CRC32_from_file(filename):
buf = open(filename,'rb').read()
buf = (binascii.crc32(buf) & 0xFFFFFFFF)
return "%08X" % buf
@matteomattei
matteomattei / phpsendmail.php
Last active August 29, 2015 14:03
How to log email sent from PHP through mail() function
#!/usr/bin/php
<?php
$sendmail = '/usr/sbin/sendmail';
$logfile = '/var/log/mail_php.log';
/* Get email content */
$logline = '';
$mail = '';
$fp = fopen('php://stdin', 'r');
@matteomattei
matteomattei / simple_messagebox.py
Last active December 9, 2015 11:09
Very simple graphical messagebox in Python useful for console applications with py2exe
import sys
if sys.version_info < (3,0):
import Tkinter as tkinter
import tkMessageBox as mbox
else:
import tkinter
import tkinter.messagebox as mbox
window = tkinter.Tk()
@matteomattei
matteomattei / pyside_template_with_external_ui.py
Created July 8, 2014 08:00
PySide and QtDesigner template for applications
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PySide.QtGui import *
from PySide.QtCore import *
from myapplication_ui import *
class MyApplication(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
@matteomattei
matteomattei / uboot_extract.py
Created July 8, 2014 08:04
Extract u-boot multi-file image in Python
#!/usr/bin/env python
import sys
def toNumber(buf):
""" Convert string in number """
size = 0
for b in buf: size=size*256+ord(b)
return size
@matteomattei
matteomattei / pyside_signal_slot_qthread_example.py
Last active May 22, 2018 17:43
PySide Signals and Slots with QThread example
#!/usr/bin/env python2
import sys, time
from PySide.QtGui import *
from PySide.QtCore import *
class MySignal(QObject):
sig = Signal(str)
class MyLongThread(QThread):