About Saïd

Software developer.

Challenge: can you implement your own small database engine ?

A Simple and Efficient Implementation for Small Databases by Andrew D. Birreil Michael B. Jones Edward P. Wobber*


Based on that paper, you can write a small database engine. I suggest you to add a CLI tool,  a SQL parser and executor .. for example!

You could take a look at the SQLite code source to get ideas how this is implemented. By doing that, you get a better understanding how databases work.

If you did, please comment 🙂

Postgresql-Get the number of rows affected

You will find a way below to get the number of rows affected by an UPDATE or a DELETE statement.

CREATE FUNCTION update_foobar(id INT, field1 VARCHAR(40))
LANGUAGE plpgsql
AS $$
    -- some variables declarations
    -- then 
    RETURN ru;
$$ ;

Setup sftp server on debian8 (chroot)

Let’s start by:

su -
groupadd sftp_users
usermod -G sftp_users my_username


emacs /etc/ssh/sshd_config
# Search the line below and replace it
Subsystem sftp /usr/lib/openssh/sftp-server
# by this one
Subsystem sftp internal-sftp
# Now each time that a user connects from the sftp group, 
# we are gonna apply theses rules:
Match Group sftp_users
 X11Forwarding no
 AllowTcpForwarding no
 ChrootDirectory /home
 ForceCommand internal-sftp


systemctl restart ssh


Edit: If you need to remove a user from a group:

gpasswd -d user group

or debian includes a tool:

deluser user group


SQL – From timestamptz A to timestamptz B

For PostgreSQL (tested on 9.4)

CREATE TABLE tests(id serial not null, created_on timestamptz);
INSERT INTO tests (created_on) VALUES (now());
2016-02-16 19:26:13.823126-05

I guess you have configured your timezone in your postgresql.conf file. I have for information ‘America/Toronto’.

SELECT created_on  AT TIME ZONE ‘Europe/Paris’ FROM tests;
2016-02-17 01:26:13.823126

shell – code de retour par une commande

Comment lire le code de retour d’une commande comme pwd ?

chaque commande executée vous renverra un code d’erreur situé entre 0 et 255. 0 pour opération réussie, sinon toute autre chiffre signifiera qu’une erreur s’est déroulée lors de l’exécution.

Le code de retour est disponible dans cette variable:


Pour exemple

~ pwd toto
pwd: too many arguments
~ echo $?
~ 1

~ pwd
~ /home/user
~ echo $?
~ 0

Stay tuned