Archive for the ‘ Examples ’ Category

Swarming

Posted in Examples, Swarming on October 13th, 2012 by sinica – Be the first to comment

SwarmESB is our new open source project implementing an innovative approach for the software architecture you could reuse when creating a new multi-tenant system that will transparently acquire the benefits of scalability, high availability, highly parallel computing and loose coupling usually obtained with asynchronous messages, message queues, pub/sub channels, message and service buses. While this project is build using Node.js and Redis, this project will present “swarming” as a new fundamental concept, comparable, but from the code maintainability perspective a lot simpler than direct usage of Enterprise Integration Patterns or than the Actor model used in Scala and Erlang.

Backup linux server

Posted in Examples, Q&A on September 13th, 2010 by cmanolescu – 1 Comment

A simple way to backup your server.

Backup mysql database:

mysqldump -u $mysqlUser -p$mysqlPassword database > dump.sql

or you can dump all databases to a single sql file

mysqldump -u $mysqlUser -p$mysqlPassword --all-databases > dump.sql

Backup postgresql database:

pg_dumpall -U user > dump.sql

but because this will execute on server there will be no user interaction so for this to work you need to create a .pgpass file in your home directory.
NOTE: make sure it has permission 600 or else it will be ignored.

cat > ~/.pgpass << ^D
host:port:*:user:password
^D
chmod 600 ~/.pgpass

You may need a remote server where to store your backup and you also want to connect without providing a password (a good tutorial can be found here).
NOTE:
a) make sure ~/.ssh exists on remote server and it has permissions 700
b) use “-p port” if ssh is not on the default port

ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub "-p port remoteUser@remoteHost"

An easy way to backup your files on a remote server is to use rsync

rsync -e "ssh -p remotePort" -avrp localPath remoteUser@remoteHost:remotePath

Create cron job

cat > /etc/cron.weekly/remote_backup << ^D
#!/bin/sh
######### Start backup script #########

######### End backup script ##########
^D
chmod 700 /etc/cron.weekly/remote_backup

Backup a folder to a tar archive

tar zcvf /archive/etc.tgz /etc/

or backup the entire server

tar -zcvpf /archive/full-backup-`date '+%d-%B-%Y'`.tar.gz \
    --directory / --exclude=archive --exclude=mnt --exclude=proc --exclude=var/spool/squid

Download complete backup script

References to class members in PHP

Posted in Examples, php code on August 27th, 2010 by sinica – Be the first to comment Tags: ,

We have decided to switch the server-side of Quark Framework 2.0  to the php language. The main reason is that PHP is everywhere,many programmers (and even non programmers) can deal with  it and we can be more agile with PHP than with java. Also the hosting costs for SaaS are lower with PHP.  I did programming for more then 14 years in strongly typed  languages like C,C++,Java,C#,Action Script and I hate that I don’t have types for parameters in php  and I don’t like how strange is PHP occasionally (php references are unlike others in any decent language I’ve ever used, the insane and ugly $this-> is annoying etc ). I’m not a big fan of Php but for what we need it is a rational choice (Don’t forget the unit tests or you are doooomed :) )

Anyway,PHP is serving us well and I’ve decided to share here a small php class that will act like a sort of reference to function members. A closure could solve sometimes the same problem (sort of) but it will not make the code clearer. And it will not work for calling members from another class/instance.

class FunctionRef
{
 	protected $mythis;
 	protected $myFunction;

	public function __construct($mythis,$myFunction)
	 {
	 	$this->mythis = $mythis;
	 	$this->myFunction = $myFunction;
	 }

	 public function call()
	 {
	 	$args = func_get_args();
	 	call_user_func_array(array(&$this->mythis, $this->myFunction), $args);
	 }
}

If you know a better way on doing this in PHP, I will be glad to know.