Archive

Author Archive

Strange ArchLinux Error

May 25th, 2010 Comments off

Arch Linux is a lightweight and simple distribution as they claim on the website. I am interested in a rolling release system without the headaches of Gentoo. The first setup was strange, I have no problems with an ugly console GUI but the entire experience was counterintuitive.

On example that gave me some headaches was at “Configure System” step. There was a strange error “Failed to import current network settings into target system” and all configuration files were empty. It took me sometime to figure the cause and here is this post in case somebody else has this problem. There was an error downloading one of the packages (dhcpd) and the setup program just continued without a proper notification. To recover from this you have to go back to the “Install Packages” step (only the missing packages are downloaded) until everything is downloaded.

There were a lot of small things that added up and in the end too many headaches just for a basic setup. I will check it again in after some time passes and maybe it will get better.

Categories: Linux Tags: ,

Today’s Date

February 7th, 2010 Comments off

The computer clock was way in the past (some CMOS problems) so windows Internet Time did not allow for an update. I googled “what date is today” and the first two sites in the serp use javascript to display the current date and a friendly invitation to buy ads on the website. Javascript is client side so the current date is taken from the same computer (with the date off). I get the same date as the computer is telling me so the website does not solve my problem and I am off to another website: no time for ads and even if I click something there is a big chance that the tracking will be confused. This is a case where you get #1 in google and you just waste your website bandwidth.

Categories: Business Tags:

Pushing Bits and Steel

January 15th, 2010 Comments off

I enjoy coding, I hardly see myself doing anything else for a living. I get satisfaction from pushing bits, transforming data and most of my work is 100% virtual. I am very proud of some of my code that runs uninterrupted for years or that I get to work with genetic algorithms and neural networks to solve some obscure, math problem. I have an almost ideal geeky job. It is quite difficult to explain what I do to regular people and the fact that I usually work on backend stuff does not help at all.

I am working on a small project – nothing complicated (some php&mysql stuff). It is the type of project where most of the challenge is in getting the requirements and helping the client to define the job. This particular case is even easier as the client has good IT skills and knows what he wants.

Today I got a pleasant surprise. He made a small movie about his work. It takes a lot of effort, technology and coordination to load a huge ship with heavy steel coils and keep track of everything in an environment that leaves little room for mistakes. He integrated everything (including my work) to make things run efficiently and the result is something to be proud of.

I got a very pleasant feeling to see how my work touches the real world in such a raw way (tons of steel, a big ship and the ocean …) and it is an interesting change from usual 100% virtual stuff. This movie changed the project from a simple job to something a bit special.

Categories: Business Tags:

Cygwin update

December 24th, 2009 Comments off

Cygwin is one way to have a Linux like environment on Windows. It is a superior alternative to the command prompt, it is great for occasional text processing. I used the included ssh client to connect to remote linux servers and it works well with a little exception:  many programs using more advanced terminal capabilities had weird artifacts, characters out of place, etc. Once, I tried to look for a fix, some terminal settings on client side or server side but nothing worked. Today I updated to the new Cygwin (1.7.1-1) and the issue was solved. Here is a screenshot of Midnight Commander running on a remote linux server.

Midnight Commander (mc)

I did not use it for some time but I am glad to see it working.

Categories: Software Tags: , ,

How to Create a Pdf in Php Using Tcpdf

December 15th, 2009 Comments off

There are several ways to generate PDF files in PHP. Each has its strengths and weaknesses. TCPDF strikes a good balance although it is far from ideal.

The best way to transform some web page to php is to let the user print it. With some free software like PDFCreator, you can get far better results than anything you can achieve using the available php libraries. Sometimes a client really wants this option or you need to generate some kind of report on the fly. This is when TCPDF is a good choice.

There is no special handling to use the library. You can download it, unpack it and include it in your project. For some advanced features, you might need to allow writing in the cache and images folders. To use it, you include the tcpdf.php file and some configuration file. You will need to make a custom configuration for more advanced features but the default one will work in most cases.

require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

If you use the library from a cronjob or command line you might get this error: PHP Notice:  Undefined variable: k_path_url in tcpdf\config\tcpdf_config.php on line 75

This is where a custom configuration file is useful but the fastest way to fix it is to just initialize that variable ahead of the config file. It will work for most of the tasks.

$k_path_url='';
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

The functionality is available using the TCPDF class. I think the OOP approach stops here because there are no other classes used (with a minor exception) and I assume the author took this path to compensate for the lack of name spaces in PHP.

The flow is simple: create a TCPDF class, call its methods to generate pages, text and drawings and then save the content. Here is an example:

<!--?php
require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');
 
// create new PDF document
$pdf = new TCPDF(); 
 
// set font
$pdf--->SetFont('times', '', 16);
 
// add a page
$pdf-&gt;AddPage();
 
// print a line
$pdf-&gt;Cell(0, 0, 'Some text');
 
// print html formated text
$pdf-&gt;writeHtml('Html text:
<b>Bold</b>');
 
// draw a circle
$pdf-&gt;Circle(30, 30, 10);
 
//Close and output PDF document
$pdf-&gt;Output('out.pdf', 'F');

The library includes a set of examples to demonstrate what it can do.

A TCPDF object maintains internal coordinates used to write text and html with Cell and writeHtml. These methods (and some other related) use these coordinates to maintain the flow of text on the page and add new pages if needed.  They also take into consideration the page margins and headers. The drawing functions are relative to the origin of the page and do not use the Cell coordinates system. This will complicate the job for reports requiring a good layout and a lot of drawing.

The html support is limited. The html needs to be well formatted and only a limited set of tags is supported. There is no error handling for unsupported html so in the best case you will only get some strange php warnings like division by zero and others. You will have to specify the width of the table cells to maintain a minimal control of the layout because the tables are not rendered/positioned as in an usual browser.  I advise against using tables to control the layout of the pdf pages. I assume you read something similar as a web developer.

As a conclusion, I avoid generating complex PDF files in php. TCPDF is the best for the task but it has limited functionality, a poor API and little documentation.

Categories: Programming Tags: , ,

Canon CanoScan LiDE 100 Review

October 7th, 2009 Comments off

Yesterday I needed a scanner for a small job. I was in a bit of a hurry so I just entered an online shop that I used before. Canon CanoScan LiDE 100 had a couple of good reviews and it was cheap. I made a quick search about it, I found out that it has no drivers for Linux and Canon is not so open source friendly. I intend to use the scanner with Windows XP; it is not an essential hardware so I placed an order.  The delivery was today, 30 minutes ahead of the announced hour (I was impressed).

It came with in a shiny package.  It contained the scanner, an USB cable, a CD with drivers and software and some short instructions. I installed the driver and software from the CD.  Obviously, everything has to go to the C drive and there is the now more and more usual application to snoop and report everything you do with the scanner via internet to Canon plus something to run at startup.

I restarted the computer, I logged in and I got a nice blue screen: PFN_LIST_CORRUPT (0x0000004E). That is the Windows way of saying that you have a driver with some bugs; it has to stop to avoid additional mess. My heart filled with warm thoughts toward Canon and I restarted the computer (second time’s a charm). Everything is fine and the system is stable. I unlock the scanner, I plug it in the computer, Windows sees the device and everything is fine.

I started MP Navigator EX (the software) and tried to scan something. ScanGear (that would be the driver) informed me:

Cannot communicate with scanner.
Cable may be disconnected or scanner may be turned off.
Check status.
Scanner driver will be closed.

CanoScan_LiDE_100_Error

The cable looks properly plugged but indeed the scanner does not light up or makes any noises. It has no power off button and nothing is mentioned in the instructions. I do not know where or what status should I check and I cannot really understand “Scanner driver will be closed.”

I remembered the previous crash so I uninstalled everything, cleaned the registry and installed everything again.  It did crash as it did the first time but I got the same error.

I discover many people with this problem after some Google searches. I tried different things, including the latest drivers and software from the not so friendly Canon website, I checked that WIA (Windows Image Acquisition) service is running, I unplugged all other USB devices, I changed the ports but nothing worked.

I was convinced the scanner is broken and I was ready to call the shop and complain about it but I have another Windows computer (same Windows XP SP3 with latest patches). I installed the driver and software from the website. I plugged the scanner and some noise came out of it. The software gave me a different message this time about calibration in I scanned the first image, a post card:PostCard

The scanner works fine, the post card is weird.

My guess is that there is some conflict with some other existing hardware or software on the first computer. There was not help in detecting what was the problem.

My conclusions:

  • research a bit more for future purchases. Three reviews on a shopping site do not say much.
  • think twice about buying Canon products.
  • think twice about buying hardware without Linux drivers. This might be biased but I noticed that well documented hardware has Linux drivers (usually made by the community) and good Windows drivers. This scanner had little to no documentation and troubleshooting information.

My Blog

September 21st, 2009 Comments off

This is the real first post on this blog.  The old page was stale and mostly just a place to give my contact info.  The new website should help my business. What I want from this blog:

  • a place to collect my thoughts
  • note some tips/tricks for future reference
  • give a chance to prospective clients to know how I think
  • get some page rank and inbound links to my websites

All this can be achieved with some extra work:

  • I have to keep this blog updated (an estimated 60% to 80% of the blogs are abandoned or not updated in the first two months)
  • maintain another application on this server
  • fight blog spam
  • write coherent and intelligent posts in English

I have zero readers, zero page rank and zero interesting posts. I hope the situation will be better in year from now.

Categories: Business Tags: ,