Archive for the 'Source Code' Category

MySQL, Source Code, Web, php

PHP backup of a mysql database

MySQLDump class is now at version 2.0 and this article contains obsolete informations about the version 1.0. For information about the new version check this article

I searched a way to do a daily backup of my wordpress blog in my home pc but I didn’t find nothing that completely satisfy me, so I decided to code it.
I separated the problem in two scripts:
The first, that is written in php and runs on the web server, makes the dump of mysql databases from my hosting provider and leaves the dump on the web server.
The other one (written in bash, and running locally) downloads the site and the mysql dump from the web server, via FTP. Unfortunately I discovered that my hosting provider (Aruba.it) didn’t supply with mysqldump its server.

Lamp

First of all, I searched for a php script that makes the direct dump of the database.

Continue Reading »

C, Source Code, Windows

C++ Timer Class

Starting from the article “C++ timer”, we created a simply class that act as a wrapper to the Windows API and that easily allows to start a timer, stop it. and assign the function to call when the timer is elapsed.

Timer

The following is a little example that explains how to use the class:
Continue Reading »

C, Source Code, Windows

Detect when an usb device is inserted or removed.

Normally the autorun in usb storage devices like pendrives is disabled for security reasons, so i wrote a little utility in c++ to launch a custom application in my pendrive when I insert it in a usb port.

Logo usb

Normally if you want to detect when a “hotplug” device has been inserted or removed from your system, you have to intercept the system message “WM_DEVICECHANGE” in “WndProc” function of the main window of your application.
Continue Reading »

C, Source Code

Optimized Access to Bitmaps

If we need image processing in c#, the fastest way for a programmer to access the pixels of a Bitmap is to use the SetPixel() and GetPixel() .NET methods. Unfortunately the fastest way for a programmer, often does’nt correspond to the fastest way for the program: These functions are REALLY slow, so if your objective is to analyze all pixels of an image, or, still worse, to make an elaboration of many images, you are not adviced to use them. Fortunately the c# is a very language flexible: It allows to make things at high levels, but often gives the opportunity to do low-level programming when is necessary.

For semplicity, in this article i will deal only the images at 8bpp (8 bit per pixel): every byte will be a pixel.

The only way to work fast with an image is to use the pointer to the image data. Work with the pointers is like working with the char * in c++: Initialliy, the pointer will point to the memory address of the first pixel of the bitmap. Increasing the pointer we would gradually obtain the values of the next pixels.
Pointer to image example
Continue Reading »

.NET, C, Source Code

CRC in C#

This is a post about the CRC (Cyclic Redundancy Check) in C#. I searched through the internet a C# class that can calculate the crc-12, but I found only links about crc-8, crc-16 and crc-32.

binary matrix

After an hard search, i founded a class that can calculate the crc from 1 to 32 (this is the link), I cleaned it and I added:

  • The crc-12 standard
  • A class that simplifies the insert of the values (CRCSettings)
  • A function that generate non-standard polynomys.

Continue Reading »

C, MySQL, Source Code

Convert a C# Object to a SQL string

This post is part of the SQLStringBuilder project. For the latest version of the code i suggest to take the source code from the CVS.

Every time that we need to create SQL queries in a programming language, often we do something like:

int id = GetTableID();
string place = GetPlace();
DateTime timestamp = GetLastActionDate();
string strTimestamp = Utils.GetSQLDate(DateTime.Now);
string sql = "INSERT INTO table VALUES(" + id + ",'" + place + "'," + timestamp + "')";

During the string creation we must add , ‘ and ” with attention.
In this article we will create a function that takes as input a c# Object and gives as output the formatted SQL String:

public static string GetSQLObject(object value)

Continue Reading »

« Prev