AWS Builders day 2018

AWS Builders day, December 2018, London

 

I’ve attended few AWS events in the last couple of years in different countries, yet the best experience I had was in the AWS builders day this December 2018 in London.

The difference is this time, is I aimed for the workshops, not the sessions. I went for the AI / ML workshops, and it was a good deviation from the type of technologies I use day to day.

The reason I like this experience is that it was some sort of hands-on training, I guess if I had that much information in a session it wouldn’t stick to my mind the way it did when I applied all the examples by hand.

You can find the materials for these workshops in this GitHub repo, https://github.com/me2resh/AI_ML_Workshops, unlike many tutorials these work as expected if you follow all the steps.

Going through the examples you will cover different aws tools like: aws rekognition, aws lexaws ec2, aws s3, amazon machine learning, aws sagemaker, deep learning AMI, apache MXNet, and Jupyter Notebook.

I hope you will find the material as enjoyable as I did, and if you have any similar resources, please share them in the comments.

There is a better way to implement X

One of the code reviews comments that I’ve been seeing recently is “There is a better way to do this” and without further explanation.

By far this is one of the killer comments you can leave to someone. It is not only telling the coder that his code is not the best. but also leaving him with two challenging questions.

  • What is wrong about this implementation?
  • What are those better ways?

My advice to any reviewer who writes such comment, Try to write a more constructive review. One of the goals of code review is to identify the problems in the code and propose better ideas for implementation. so If you see something that is not at its best. Identify why it is not. and what are the better ways to implements it? always give the requestor something to learn, and go home with.

And If you are requesting a review then received this comment, don’t be defensive about your code. just take a deep breath, and ask the 2 questions above.

The blog is Back

After almost 4 years and a half since my last post, and a long period of taking the blog offline. I managed to revive it from the ashes and bring it up again.

More to follow…..

Adding custom mapping types in doctrine

While working in some enhancements for my startup Careerise, I had an issue with doctrine not recognising the mysql data type “blob“.

The error I was getting while running doctrine diff was :

[Doctrine\DBAL\DBALException]                                                                    
  Unknown database type blob requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

In order to overcome the issue, I had to add the blob data type to doctrine.

Step 1 :

Creating a class to handle the blob type.

path : Doctrine/DBAL/Types/BlobType.php

file content :

<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
 * Type that maps a database BLOB to an encoded base64 value
 *
 * @author Ahmed
 *        
 */

class BlobType extends Type
{

    public function getName ()
    {
        return TYPE::BLOB;
    }

    public function getSQLDeclaration (array $fieldDeclaration,
            AbstractPlatform $platform)
    {
        return $platform-&gt;getDoctrineTypeMapping('BLOB');
    }

    public function convertToDatabaseValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_encode($value);
    }

    public function convertToPHPValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_decode($value);
    }
}

Step 2: Add the blob type name to the Type abstract class

File Path : Doctrine/DBAL/Types/Type.php

    const BLOB = 'blob';

Step 3: Modify the DoctrineTypeMappings for mysql

File Path: Doctrine/DBAL/Platforms/MySqlPlatform.php

Append the blob type to the end of the array, ex :

protected function initializeDoctrineTypeMappings()
    {
        $this->doctrineTypeMapping = array(
            'tinyint'       => 'boolean',
            'smallint'      => 'smallint',
            'mediumint'     => 'integer',
            'int'           => 'integer',
            'integer'       => 'integer',
            'bigint'        => 'bigint',
            'tinytext'      => 'text',
            'mediumtext'    => 'text',
            'longtext'      => 'text',
            'text'          => 'text',
            'varchar'       => 'string',
            'string'        => 'string',
            'char'          => 'string',
            'date'          => 'date',
            'datetime'      => 'datetime',
            'timestamp'     => 'datetime',
            'time'          => 'time',
            'float'         => 'float',
            'double'        => 'float',
            'real'          => 'float',
            'decimal'       => 'decimal',
            'numeric'       => 'decimal',
            'year'          => 'date',
            'blob'          => 'blob',
        );
    }

now doctrine will be able to recognise the mysql data type blob.

the documentation here was helpful in some of the steps above : Custom Mapping Types

How to reduce your virtualbox linux virtual machine size

After using a linux virtual machine that has been configured with dynamically expanding drive, the size gets larger even if you remove files from it.

Here is the steps to shrink your linux virtual machine size :

1- Remove any unnecessary files you don’t need from the virtual machine.

2- Fill the unused spaces on it with zeros.

  • Open the virtual machine.
  • Install zero free
sudo apt-get install zerofree
  • Reboot the machine in repair mode, and login to root shell
  • Kill any processes using the hard disk.
service rsyslog stop
service network-manager stop
killall dhclient
  • list your virtual machine harddisks
df
  • Unmount and Fill all the unused spaces for each physical drive on the machine with zeros.
mount -n -o remount,ro -t ext3 /dev/sda1 /
zerofree /dev/sda1
  • Shutdown the machine.

3- Clone the old HD file into a new shrinked one

VBoxManage clonehd oldHd.vdi newHd.vdi

4- Now add the new cloned HD file as the new HD for the machine and test it.

5- Remove your old HD file.

 

Second life and Virtual Worlds on the web

I had had the chance to do some investigations on how to create a second life similar application that run on the web, and allows people to communicate, chat, and interact in different ways.

The applications of such tools can be virtual meeting rooms, small virtual world for people to share or discuss some cause or idea. there is also the fun part where people can interact as in a game, purchase items, go to virtual malls, etc.

Here is some links to the wikis of tools that can create virtual worlds:

http://en.wikipedia.org/wiki/RedDwarf_Server

http://en.wikipedia.org/wiki/Project_Darkstar

http://en.wikipedia.org/wiki/Croquet_project

http://en.wikipedia.org/wiki/Open_Wonderland

http://en.wikipedia.org/wiki/GForge

http://en.wikipedia.org/wiki/OpenSimulator

I hope those would be useful for any one interested in virtual world applications, Have any urls to add to those, please let me know .

Using Juniper Network on Ubuntu 32 and 64 bit without Firefox

Lately i have moved from Ubuntu 32bit to 64bit to make use of the 8G memory, and since I have been struggling to get our juniper vpn connection working, turned out it is not compatible with 64bit binaries of java and firefox.

I found this great tutorial here to have the juniper network VPN working from command line http://mad-scientist.us/juniper.html

the only disadvantage of this is you won’t have a status window to monitor the connection activity.

This has been tested on Ubuntu 10.10 maverick.

Speed your internet browsing on Ubuntu using local DNS Cache

Use these steps to speed your internet browsing requests on Ubuntu, by enabling local DNS cache :

1- Run this command to install dnsmasq package

sudo apt-get install dnsmasq

2- Modify the file :

sudo gedit /etc/dnsmasq.conf

change the line :

#listen-address=

To :

listen-address=127.0.0.1

3- Modify the file :

sudo gedit /etc/dhcp3/dhclient.conf

Ucomment the line :

prepend domain-name-servers 127.0.0.1;

4- Add the DNS 127.0.0.1 to your connection through your connection manager

Your DNS servers should be :

127.0.0.1,8.8.8.8,4.2.2.4

5- Restart your connection

sudo /etc/init.d/networking restart

To check if it is working issue the following command twice:

dig php-architect.com | grep 'Query'

first response will be like :

;; Query time: 96 msec

run the previous command again

dig php-architect.com | grep 'Query'

Response now should be :

;; Query time: 0 msec

This will speed your browsing especially in pages with many HTTP requests.

Backup or Export, Compress and upload mysql database to remote host

This is a handy command that i use to backup or export, compress and upload a mysql database to my remote host, very handy when you wanna upload your development database to the remote host after some changes.

/usr/mysql/bin/mysqldump --opt -uUsername -pPassword Databasename  | gzip -c | ssh -q user@remote-host.com 'cat > ~/Databasename.sql.gz'

Replace the following :

  • /usr/mysql/bin/mysqldump : The path for mysqldump on your localmachine
  • Username : Username for local mysql database.
  • Password : Password for local mysql database.
  • Databasename : Name of the database to export.
  • user@remote-host.com : the user and the IP or the address of the remote host.

the above command will upload the compressed database to your home directory on the remote host, to change the directoy, replace ~/ with the path you want.

Virtualbox hidden gems, VBoxManage

Virtual box has this little secret, the Command Line interface (CLI), this is very useful for users who wants to manage their virtual boxes on headless servers.

Question is why using command line while you have a nice easy to use GUI, the answer is POWER. you can do anything with the virtual box command line, you can create virtual machines, modify their settings, take snapshots, start and shutdown them.

VBoxManage supports everything the graphical user interface does, and much more.

VBoxManage has its share of Virtual Box documentation, you can find it here http://www.virtualbox.org/manual/ch08.html