Tag: Code Example

PHP Class for modifying old HTML static copies / mirrors

Ok you made a static mirror(maybe with HTTrack, maybe with something else) and you still want to host it somewhere, but you also want to make a change to all the static pages without modifying each and every one of the files. In that case, you need to load that file using a script that reads the file at the time of loading then makes the changes you want and after that displays it. Sound simple enough so I made a PHP class that does just that and I even wrote 2 flavors of the script to work on an ancient PHP version( and by ancient I mean around 2010 5.3.x). View full article

Shred Function Qt C++ on windows

So, I searched for such a function and, I did find some things on O-Stack, but I rewrote what I found because it didn’t actually work, I tested this function and it works pretty well, I think it has room for improvement as usual but I thought to share it anyway.

So here it is:

bool QtClAct::shred(const QString & fileName, uint RepeatWrite, bool DeleteFileLink) {

  if(RepeatWrite < 1) RepeatWrite = 1;
  QSaveFile file(fileName);
  QFileInfo fi(file.fileName());

  for(int i=0; i < RepeatWrite; i++){ qint64 fileSize = fi.size(); if (! file.open(QIODevice::WriteOnly )) return false; QByteArray block(65536, '\0'); while (fileSize > 0) {
    if (fileSize < block.size()) block.truncate(fileSize);
    qint64 written = file.write(block);
View full article

Linux Folder / Folders Backup on Yandex

Ok so a little while ago I made a Linux Yandex python script for backing MySQL databases and sync them on Yandex Disk, so if I already did that I thought I should use a part of that script and make a backup script for folders.

Most of the script is self-explanatory, all you have to do is to change the variables before the starting of the class keyword for your own needs. I put some comments that will better explain what you should define in each variable. Most of them are either of type string or number, just one is a bit different is a list of x lists of a 3 element list. View full article

MySQL Backup on Yandex Disk with Cron

I wrote a very small python script that works in conjunction with another MySQL backup script to sync your backup on the Yandex disk service.

First, in order to do this, you should have a Yandex client installed. You can get the packages from the Yandex repo at http://repo.yandex.ru/yandex-disk/ .

More specific in Debian/ubuntu case just do a:

wget http://repo.yandex.ru/yandex-disk/yandex-disk_latest_amd64.deb

After that install the Yandex Console client as usual doing:

dpkg -i yandex-disk_latest_amd64.deb

After installing the package, basic Yandex commands should be available(commands like yandex-disk start, yandex-disk sync, and others).
The script uses the yandex-disk commands.

Next, you should set up your Yandex client with the command Yandex setup. View full article