Assignment Overloading, Copy Constructors and RAII, How I do it.

Here is a pattern I came up with and I tend to use for my objects that can be copied. It’s is pretty simple and that is the point. More robust and useful classes can be defined by adding parameters to the non-standard methods (Create/Clone/Initialize/Destroy) .  The below example is C++. Reader should also use explicit constructors when appropriate. In the below case, defining Foo’s constructor as explicit was unnecessary

class Foo
{
private:  
  void Create()
  {
    // Create and initialize if RAII.
  }
  void Clone(const Foo& rSource)
  {
    // Copy data from rSource to "this"
  }
  void Initialize()
  {
    // Initialize object state
  }
  void Destroy()
  {
    // Destroy anything created in Create() in reverse order.
  }
public:
  Foo()
  {
    Create();
    // If RAII (Resource Acquisition Is Initialization)
    Initialize();
  }
  Foo(const Foo& rSource)
  {
    Create();
    Clone();
  }
  virtual ~Foo()
  {
    try
    {
      Destroy();
    }
    catch(...)
    {
    }
  }

  Foo& Foo::operator=(const Foo& rSource)
  {
    if(this != &rSource)
    {
      Clone(rSource);
    }
    return *this;
  }
}

Directories must be executable

It is a known mistake but I always seem to run this command (or one like it) at some point. Especially likely to run it when I am in some type of hurry.

chmod -R 744 .

This sets everything to rwxr–r–, include directories, recursively, starting from the current directory. Obviously, this makes the path impossible to navigate for group users and everyone else that is not an owner

Therefore, to undo that mistake and to set directories back to being possible to traverse (ie executable); I have come up with these short commands

find . -type d -exec chmod 755 {} \;

you can all run the below command to chmod files only.

find . -type f -exec chmod 644 {} \;

Hopefully, now that I have told the world, I will never make this mistake again.

MySQL Export/Import and Replication

It is critical to know how to backup and restore a database via the command line and to work on production databases with real world data.  Like any relevant DBMS (Database Management System), MySQL provides tools for doing just that. In this article I go over some procedures I use to facilitate data snapshots and replication of an entire MySQL DBMS as well as discuss some effects of doing so.

Continue reading