Archive

Posts Tagged ‘Linux’

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 , ,

Memo: fast grep of the word in the directory

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

Linux, Memo , ,

Speed up your work in Vim

May 9th, 2008

If you don’t know what’s Vim, then:

  1. You’re Windows IDE’s fan
  2. You’ve never used Linux

An option “you’re using Emacs” is not included – you would have definetely known Vim. You’d hate it for the sake of “holly wars”.

I’m not an Emacs lover, neither those huge IDE’s with bunch of boxes, bookmarks, you name it. Most of these things are useless when you need to code something fast, so I just stuck with Vim: simple, light, fast, and have a lot of functionality. Here are just few tips of speeding up coding process I’ve been using lately:

If you got some repetitive function calls or anything you’re not bothered to print just fire up:

Comments:

:ab #cb /********************************
:ab #ce /*******************************/

Printing #cb or #ce will paste initial comment pattern.
:ab #r require_once();
:ab #i  include_once();

Minus another dozen of lines to be typed.

Text search:

You can :set incsearch which will enable incremental search for you, or use regexp, like:
:/\<agent\>/ will find you “agent” in current file.

Using ftp:


cmap ,r :Nread ftp://ftpdomain/public_html/index.html
cmap ,w :Nwrite ftp://ftpdomain/public_html/index.html

These are just basics, Bram Moolenaar, the developer of Vim, got a good article on how to optimize your work with Vim, and David Rayner with his page of Vim tips. Compulsory to learn for Vim beginners!

Linux , ,

KDE on Windows

January 27th, 2008

KDE on Windows XP

Good news, KDE team started migration of original KDE applications for Windows platform. Concerning windows.kde.org, users of Windows XP/2000/2003 can easily install famous apps like Konqueror, Kate and others on their machines, via KDE-installer.

If some of the applications don’t work from the beginning, just add KDEDIRS and Path in your Control Panel, as it’s described in the manual.

So far, I found only one minor thing: I couldn’t manage applications via Konqueror, however it needs some googling.

In general, lots of positive feelings for this great move of KDE, because some of the apps in KDE can’t be compared with Windows scanty alternatives.

Blogging, Links , , , ,

Linux Antivirus

January 17th, 2008

Here is a Linux Virus scanner for you:

!# /bin/bash
echo Linux virus scanner
sleep(1)
echo Scanning now...
sleep(10)
echo Still scanning...
sleep(10)
echo Almost done...
sleep(5)
echo Drum roll...
sleep(3)
echo No viruses found!!!
sleep(1)
echo Done

References go to Ubuntuforums

Updates: First add-on for Linux Antivirus released, just add few lines at the bottom of the code:

eject
play tada.wav

Blogging , ,

7.04 to 7.10 Ubuntu desktop

October 22nd, 2007

Heck! I was expecting some power consumption improvements, but still 4 hours XP vs. 2 hours Gusty.

Trying to make this post useful, follow these lines:

sudo aptitude update
sudo aptitude upgrade
sudo aptitude dist-upgrade

And remember: the more you misspell these three lines the longer upgrade will be! Be aware of grammar mistakes, folks!

Links , ,