Pages

Thursday, June 2, 2016

MySQL CSV import using command line client

If you need to import a large CSV file into mysql DB of a remote/live server and you have access to ssh to that server (or even in your local machine also), you can use a sqlyog or some other program for that.

An alternative is to upload the CSV file on server and using mysql command line client of the server by issuing the below mysql commands.


>>>  use DATABASENAME;

 >>> Load data infile '<PHYSICAL PATH OF THE .CSV FILE>' into table < TABLE NAME >;


e.g.

Load data infile '/tmp/customer.csv' into table customer;


If variable "secure_file_priv" is set [ show variable like 'secure_file%' ], specifying local my work:

 >>> Load data local  infile '<PHYSICAL PATH OF THE .CSV FILE>' into table < TABLE NAME >;


For windows, new line characters may need to be specified:

 >>> Load data local  infile '<PHYSICAL PATH OF THE .CSV FILE>' into table < TABLE NAME > lines terminated by '\r\n';


To load data for selected fields, field names come at the end:

 >>> Load data local  infile '<PHYSICAL PATH OF THE .CSV FILE>' into table < TABLE NAME > lines terminated by '\r\n' (column1, column2 ... ) ;




Monday, May 23, 2016

Cakephp 2.x site wide view variables

This trick is for old cakephp 2.x versions.

There may have many elegant ways, but I discover it simple and easy for me.

In app/Config/core.php
I put some variables used in multiple places site wide e.g. title, logo or something else like this:


Configure::write('View.title', 'Test Title');
Configure::write('View.logo', 'logo.png');


From the view ( .ctp), I called them like:

<title>
 <?php echo Configure::read('View.title'), ' :', $title_for_layout; ?>
</title>
I can use Configure.read in multiple .ctp files and if I need to change any variable value, I shall just do it in app/Config/core.php and done even if 100 .ctp files have used it.

It is a good software engineering practice.

If any specific .ctp needs to have different value, well option is always open to customize that single one keeping rest of 99 files reading the common Config value.

Thursday, May 5, 2016

Ubuntu No Sound problem fixing

If a terminal (gnome-terminal or xterm whatever is available) type:

aplay -l


If you see this:
aplay: device_list:221: no soundcard found...
Then type

sudo aplay -l

The output of that command should look something like this:
 
**** List of PLAYBACK Hardware Devices ****
card 0: Intel [HDA Intel], device 0: ALC861VD Analog [ALC861VD Analog]
  Subdevices: 0/1
  Subdevice #0: subdevice #0
It means your sound card is okay and your problem may solve easily by adding your username into audio group. Now type
grep ^audio /etc/group

to check if your username is there, if not add it:
sudo addgroup <username> audio
 <username> will be your login name ( whoami or w will reveal your username if you are not sure)

You can also do:

sudo addgroup `whoami` audio
 Note the inverted single quote ( ` ), it is crucial.


For more complex issues please visit official ubuntu sound troubleshooting help

Monday, April 11, 2016

Monitoring a directory for new files in Ubuntu

In Linux `inotify` API provides functionality for file systems events.

Based on this API, in Ubuntu, the service/daemon inoticoming has been developed.

inoticoming is a daemon to watch a directory with Linux's inotify
 framework and trigger actions once files with specific names are placed
 in there.

inoticoming "<path_to_target_folder>" <full_path_of_triggered_script> {} "<path_to_target_folder>" \;

The backslash (\) is the part of the command.


source