Saturday, October 31, 2015

Nodejs v5 on ubuntu 14.04

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
node -v
v5.0.0

for the stable version:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/nodejs
for the lastest:

sudo n latest

To undo:

sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
sudo n rm 6.0.0     # replace number with version of Node that was installed
sudo npm uninstall -g n

How to add column descriptions (comments) in Doctrine2

You can add a comment to a column name or entire table with the "options" argument to the annotation; eg:
/**
 * @ORM\Column(type="string", options={"comment":"The string to show in the dropdown "})
 */
for a column, or for a table:
/**
 * @ORM\Entity
 * @ORM\Table(name="application", options={"comment":"Funding applications"});
 */
Note however this will not add comments to an existing table or column, you have to delete the table from the DB and rebuild it. If it's just adding comments, you could rename the table, create the new table, and import data from the original.

Monday, October 26, 2015

Disable internet connection from terminal!

The following command works for me like a charm if I want to disable any internet connection from terminal:

nmcli nm enable false

To enable it again:

nmcli nm enable true

Tuesday, August 25, 2015

Truncate logs

truncate logfile --size 0
For the entire file system:
find / -type f -name "*.log" -exec truncate --size 0 {} +

Mysql

SET GLOBAL slow_launch_time = 1;
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL log_queries_not_using_indexes = 'ON';
SET GLOBAL slow_query_log_file ='/var/lib/mysql/slow-query-log.log';
SET GLOBAL long_query_time = 1;
SHOW VARIABLES LIKE '%slow%';

#FLUSH LOGS;


SHOW GLOBAL STATUS LIKE 'Connections';
SHOW GLOBAL STATUS LIKE 'Threads_created';
SHOW GLOBAL STATUS LIKE 'Max_used_connections';

#Threads_created / Connections > 0.01
#increase thread_cache_size where thread_cache_size > Max_used_connections

Saturday, July 18, 2015

How To Properly Upgrade from Mint 17.1 (Rebecca) To Linux Mint 17.2 (Rafaela)

sudo apt-get update
sudo apt-get dist-upgrade
sudo cp /etc/apt/sources.list.d/official-package-repositories.list{,.bak}
sudo sed -i 's/rebecca/rafaela/g' /etc/apt/sources.list.d/official-package-repositories.list
sudo apt-get update
sudo apt-get dist-upgrade




Friday, July 17, 2015

optipng

sudo apt-get install optipng
optipng -i1 -o7 -v -full -sim pic.png

Friday, June 19, 2015

mod_rewrite to remove .php extension AND preserve GET parameters

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
#RewriteRule ^ %1 [R=302,L]
RewriteRule ^ %1 [R=301,L]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]

Thursday, May 07, 2015

Some effect with datatables

.highlight{
    background-color: rgba(255, 200, 50, 0.1) !important;
}
tbody tr:hover {
    background-color: rgba(255, 200, 50, 0.1) !important; 
}







$(document).ready(function() {
    var lastIdx = null;
    var table = $('table').DataTable();
    $('table tbody')
            .on( 'mouseover', 'td', function () {
                var colIdx = table.cell(this).index().column;

                if ( colIdx !== lastIdx ) {
                    $( table.cells().nodes() ).removeClass( 'highlight' );
                    $( table.column( colIdx ).nodes() ).addClass( 'highlight' );
                }
            } )
            .on( 'mouseleave', function () {
                $( table.cells().nodes() ).removeClass( 'highlight' );
            } );
} );


Monday, May 04, 2015

composer in production

Why
There is IMHO a good reason why Composer will use the --dev flag by default (on install andupdate) nowadays. Composer is mostly run in scenario's where this is desired behavior:
The basic Composer workflow is as follows:
  • A new project is started: composer.phar install --dev, json and lock files are commited to VCS.
  • Other developers start working on the project: checkout of VCS and composer.phar install --dev.
  • A developer adds dependancies: composer.phar require <package>, add --dev if you want the package in the require-dev section (and commit).
  • Others go along: (checkout and) composer.phar install --dev.
  • A developer wants newer versions of dependencies: composer.phar update --dev <package>(and commit).
  • Others go along: (checkout and) composer.phar install --dev.
  • Project is deployed: composer.phar install --no-dev
As you can see the --dev flag is used (far) more than the --no-dev flag, especially when the number of developers working on the project grows.
Production deploy
What's the correct way to deploy this without installing the "dev" dependencies?
Well, the composer.json and composer.lock file should be committed to VCS. Don't omit composer.lock because it contains important information on package-versions that should be used.
When performing a production deploy, you can pass the --no-dev flag to Composer:
composer.phar install --no-dev
The composer.lock file might contain information about dev-packages. This doesn't matter. The --no-dev flag will make sure those dev-packages are not installed.
When I say "production deploy", I mean a deploy that's aimed at being used in production. I'm not arguing whether a composer.phar install should be done on a production server, or on a staging server where things can be reviewed. That is not the scope of this answer. I'm merely pointing out how to composer.phar install without installing "dev" dependencies.
Offtopic
The --optimize-autoloader flag might also be desirable on production (it generates a class-map which will speed up autoloading in your application):
composer.phar install --no-dev --optimize-autoloader
Or when automated deployment is done:
composer.phar install --no-ansi --no-dev --no-interaction --no-progress --no-scripts --optimize-autoloader

Thursday, April 30, 2015

Tuesday, April 21, 2015

raw query in Doctrine 2

public function getAuthoritativeSportsRecords()
{   
    $sql = " 
        SELECT name,
               event_type,
               sport_type,
               level
          FROM vnn_sport
    ";

    $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
    $stmt->execute();
    return $stmt->fetchAll();
}   

Thursday, April 16, 2015

Datatables composer images, symfony

{% image '../vendor/datatables/datatables/media/images/sort_asc.png' output='vendor/datatables/datatables/media/images/sort_asc.png' %}{% endimage %}
{% image '../vendor/datatables/datatables/media/images/sort_asc_disabled.png' output='vendor/datatables/datatables/media/images/sort_asc_disabled.png' %}{% endimage %}
{% image '../vendor/datatables/datatables/media/images/sort_both.png' output='vendor/datatables/datatables/media/images/sort_both.png' %}{% endimage %}
{% image '../vendor/datatables/datatables/media/images/sort_desc.png' output='vendor/datatables/datatables/media/images/sort_desc.png' %}{% endimage %}
{% image '../vendor/datatables/datatables/media/images/sort_desc_disabled.png' output='vendor/datatables/datatables/media/images/sort_desc_disabled.png' %}{% endimage %}

Composer vendors symfony

http://stackoverflow.com/questions/11483137/it-is-possible-to-access-vendor-files-from-within-a-view-in-symfony-2-0
{% stylesheets '../vendor/twitter/bootstrap/bootstrap/css/bootstrap.min.css' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}

{% javascripts '../vendor/twitter/bootstrap/bootstrap/js/bootstrap.min.js' %}
    <script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}

Thursday, April 09, 2015

Some tips for Doctrine2 entities' generation from an existing database

So I began working on Symfony2 framework, i had to map an existing database with Doctrine2. First of all, keep in mind  that Doctrine2 gives its best for creating a schema, not for generating an object model from an existing one.

It's therefore important to "prepare" your database before generation unless you'll get an approximative model...
You must define a Primary Key on each table of your DB. It seems obvious but Doctrine2 will fail otherwise...

 Composite primary keys including only foreign keys is not yet fully supported by Doctrine2 (see documentation). Think about adding an auto-increment integer as PK and apply a UNIQUE index on foreign keys from old composite PK.

Natively, Doctrine2 doesn't natively resolve BIT, BINARY, VARBINARY, TINYBLOB, MEDIUMBLOB, BLOB, LONGBLOB, ENUM, SET, GEOMETRY, POINT, MULTIPOINT, LINESTRING, MULTILINESTRING, POLYGON and MULTIPOLYGON.

Important : Doctrine2 converts SQL type TINYINT to PHP type boolean. Use at least a SMALLINT if you want to mean an integer.

Doctrine automatically assignes IDs with generator (PHP equivalent to auto_increment) but it does it for all types of simple Primary Keys, even strings and foreign keys...

When you're satisfied of your schema, you can generate the metadatas with the command CLI interface :


First step : convert your mapping

$ php app/console doctrine:mapping:convert xml ./src/Xxx/YourBundle/Resources/config/doctrine/metadata/orm --from-database --force

Note : I prefer XML for mapping => DB model is independant from code. Use annotations if you create your schema from Doctrine Entities, not for "reverse engineering" (used term by Doctrine documentation).

You'll get some .orm.xml files describing your database model in ./src/Xxx/YourBundle/Resources/config/doctrine/metadata/orm. These files don't resolve namespaces of your application, that's why step 2 is needed.

Second step : import your mapping

$ php app/console doctrine:mapping:import XxxYourBundle xml

Some new .orm.xml files describing your database model in ./src/Xxx/YourBundle/Resources/config/doctrine. These files resolve namespaces of your application. Don't delete files generated during first step, you still need them to generate entities !

Third step : generate entities

$ php app/console doctrine:generate:entities XxxYourBundle

Entities PHP files are generated in ./src/Xxx/YourBundle/Entity.

Saturday, March 14, 2015

Symfony 2 - Duplicate an entity

public function duplicateAction(Request $request, $id){    $em = $this->getDoctrine()->getManager();    $entity = $em->getRepository('ABundle:B')->find($id);    if (!$entity) {        throw $this->createNotFoundException('Unable to find B entity.');    }    $new_entity = clone $entity;    $em = $this->getDoctrine()->getManager();    $em->persist($new_entity);    $em->flush();    return $this->indexAction();}

Monday, February 23, 2015

How to generate "bootstrap.php.cache"

If you ever need to generate the bootstrap.php.cache file for a Symfony2 Version higher or equal to 2.1, this will do the Job: 


php /vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php


Hope you save some time with this ;)

Wednesday, February 18, 2015

Friday, February 06, 2015

Install google-closure-linter on Ubuntu or closure-linter package in Ubuntu

sudo apt-get install build-essential
sudo apt-get install python-cheetah
wget http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz
or
sudo apt-get install closure-linter

Tuesday, January 27, 2015

Switch to UTF-8 charset in Mysql on Ubuntu

When installing Mysql on Ubuntu the default character set is probably latin-1. Since Ubuntu uses UTF-8 for most other things this may be little strange. But it is easy to change.


The Mysql configuration file /etc/mysql/my.cnf has a magic line:

!includedir /etc/mysql/conf.d/

This will make it include settings on the subdirectory conf.d. It's not recommended to change themy.cnf file directly since it will cause problems when upgrading Ubuntu/Mysql to a new version.

Create a new file: /etc/mysql/conf.d/utf8_charset.cnf with the following contents:

[mysqld]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake

[client]
default-character-set=utf8

Restart mysql and you will have UTF-8 as character set:


$ mysql -u root -p -e 'show variables like "%character%";show variables like "%collation%"';



+--------------------------+----------------------------+

| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+

if you want to change the DB
alter database <database> character set utf8 collate utf8_unicode_ci;

Monday, January 26, 2015

https://octobercms.com/

October is a free, open-source, self-hosted CMS platform based on the Laravel PHP Framework. It is a productivity tool for building modern websites based on flexible patterns and principals rooted in simplicity.

https://octobercms.com/

Sylius

Built on the shoulders of open source giants
Symfony2 as the enterprise-class PHP framework
Doctrine as ORM and database abstraction
Behat and phpspec for BDD

http://sylius.org/

Image Cropper

A simple jQuery image cropping plugin

http://fengyuanchen.github.io/cropper/

xfce4-screenshooter keyboard shortcut

sh -c 'xfce4-screenshooter --fullscreen --save "$HOME/Pictures/Screenshots/Screenshot_$(date +%Y-%m-%d_%H:%M:%S).png"' s...