Archive

Archive for the ‘Memo’ Category

Perl, from Excel to MySQL

March 10th, 2010

One of the reasons I like Perl – it’s really fast on solving daily routines. The request was to get a list of shipping flags from one of the websites to Excel and paste it to the site’s database. Quick and dirty solution:

#!/usr/bin/perl
 
use strict;
use warnings;
use DBI;
use Spreadsheet::ParseExcel;
 
my $file = 'flags.xls';
 
my $xl_parser = Spreadsheet::ParseExcel->new();
 
my $workbook = $xl_parser->Parse($file);
my $worksheet = $workbook->worksheet('Sheet1');
 
my ($c_min,$c_max) = $worksheet->col_range();
my ($r_min,$r_max) = $worksheet->row_range();
 
my @flags;  # used for storing an array of flags;
 
for my $row($r_min..$r_max) {
 
    for my $col($c_min..$c_max) {
 
        my $cell = $worksheet->get_cell($row,$col);
        my $val = $cell->value;
 
        $val =~ s/^\s+(.*?)\s$//g;
 
        push @flags, $val;
        #some extras on different cells/etc/
 
    }   
}
 
my $dsn = "DBI:mysql:database=db_blah;host=host;port=blah_port";
my $dbh = DBI->connect( $dsn, 'usr_blah', 'pwd_blah') || die("Couldn't connect to database\n");
 
 
$dbh->do("INSERT INTO flags(name) VALUES(".$dbh->quote($_).")") for @flags;

Linux, Memo , ,

service mysqld restart: no file or directory

January 5th, 2010

rpm -qa | grep mysql (find out the version of mysql you got)Somehow managed to break mysqld file (wow! applauses).

Errors received from ‘mysql -u <username> -p <pass>’:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

On using ‘rpm -e mysql-server’ was getting:

error reading information on service mysqld: No such file or directory
error: %preun(mysql-server-3.23.58-4) scriptlet failed, exit status 1

The solution ended up in:

  • rpm -qa | grep mysql (find out the version of mysql you got)
  • Get the right version of you RPM
  • rpm -Uhv –force mysql-server-xx.x.rpm
  • service mysqld restart

Linux, Memo

IE7 “operation aborted” error

November 23rd, 2009

Once you have “Operation aborted” error in IE7 for the website that means:

  1. You’ve placed JS file in the head of the document.
  2. This script tries to work with DOM with appendChild, createElement methods that drive IE crazy!

Solution is simple – move the JS file out of the head-tag at the bottom as (YDN advices), or at least – inside its container. For example, body-tag.

Memo

Memo: SVN creation, trunks and tags

November 3rd, 2009

1. Trunks

svnadmin create --fs-type fsfs /svn
cd /svn
svn mkdir file:///svn/<project> -m "creating project directory"
svn import /dir/of/project_files file:///svn/<project>/trunk -m "initial import"
svn checkout file:///svn/<project>

2. Creating Tags

cd /svn/<project>
svn mkdir tags
svn copy trunk/ tags/<version_tag> 
svn ci -m "version tagged"
cd /svn/<project>
svn checkout file:///svn/<project>/tags/<version_tag>

Memo

Memo: fast grep of the word in the directory

November 2nd, 2009
 find ./ | xargs grep -i search_string

Linux, Memo , ,