Tools & Showcase

August 24, 2010

No carpenter ever says he knows to use a hammer or rates himself 9/10. But rather he showcases his work! Why is it so much different when it comes to the IT field. I know drupal, I know joomla, I know perl! They are are just tools! What matters is what you can do with them. As carpentry is the only thing necessary for a carpenter before learning any tools, shouldnt developers first learn to be  good programmers?

  • Share/Bookmark

Shell for Catalyst

April 21, 2010

Most modern MVC frameworks come with a shell (REPL) that makes debugging and development a lot easier. In catalyst this is not out of the box.

However below is a script that you can add to the script directory. This will connect to your schema directly. There is a catalystx plugin CatalystX::REPL that uses moose which is far more helpful. However I will update on that once I have tried it.  For now that script to get an interactive shell to play with your models.

use Devel::REPL;
my $repl = Devel::REPL->new;
$repl->load_plugin(‘LexEnv’);
$repl->lexical_environment->do(<<’CODEZ’);
use FindBin;
use lib “$FindBin::Bin/../lib”;
use Cl::Model::Cl;

my $modelconfig = Cl::Model::Cl->config;
my $schema_class = $modelconfig->{schema_class};
my $dsn = $modelconfig->{connect_info}->{dsn};
my $user = $modelconfig->{connect_info}->{user};
my $password = $modelconfig->{connect_info}->{password};

eval “use $schema_class”;
my $s = $schema_class->connect($dsn,$user,$password);

CODEZ

$repl->run;

  • Share/Bookmark

I have attached a perl script to convert HTML to PDF

htmltopdf

Following is the code for the same

use HTML::HTMLDoc;

my $htmldoc = new HTML::HTMLDoc();
$htmldoc->set_input_file(“source.html”); # alternative to use a present file from your fs
my $pdf = $htmldoc->generate_pdf();
$pdf->to_file(‘foo.pdf’);

It actually works perfectly fine even if the HTML is not w3 validated. Neat if you have to convert HTML that was not created by you on the fly to PDF.

I also acknowledge that the same code is there in the CPAN’s synopsis of the module used. But it took me a few hours to locate it and to pick from the zillion other modules available there. Hope someone finds it useful.

If you are wondering why I posted this at such an ODD time. I was clearning out my notes and inbox items and saw a note to myself to post this in a blog. Horrors of GTD when the weekly reviews are not done! And as always if the task aint more than 2 mins, it aint worth putting in a to do list. And hence the post.

  • Share/Bookmark

Ning, PHP & FLash

September 21, 2008

Javascript(Jquery) -> PHP(same domain) -> flash -> PHP(same domain) -> PHP(remote server)

Ever had to make so many calls to display a simple flash object?

It was saturday and I was enjoying the leisure of being at home. When I got a call from an old prospective client. It was an emergency and deliveries had to be made the very night. It had something to do with Ning. Though I have never worked on ning before, the idea of doing a cross-site script sounded like fun! The client wanted a block within Ning to pass user data two ways to a flash object. The bottle neck is, the block understands only HTML. Ths was fixed using javascript to load a PHP  using AJAX request. The PHP file  being in the same server as Ning had access to the user’s session using Ning’s API. Then the PHP script rendered the flash object injecting the appropriate variables using query string. The second bottle neck was this, the flash script has to pass values to a php script that saves something in a database. We couldnt use mysql_connect as those libraries were not available in the ning server. So we had to call an external PHP script  in another server which can manipulate DB. Another bottleneck, when I realized flash has security restrictions on calling scripts from other site. Time for php proxy :)

So in the end the complete flow looked like the following

Javascript(Jquery) -> PHP(same domain) -> flash -> PHP(same domain) -> PHP(remote server) -> MYSQL

The whole experience was so exciting that I am writing this, just a few minutes after completion :)

  • Share/Bookmark

Today I figured all over again for the nth time, how to go online using a tata indicom cdma modem.
I was using the usb modem and following are the steps to do the same.

  1. Install wvdial
  2. edit /etc/wvdial.conf to contain the following
[Dialer Defaults]
Init2 = AT+CRM=1
Modem Type = USB Modem
Phone = #777
ISDN = 0
Dial Command = ATDT
Username = internet
Init1 = ATZ
Password = internet
Modem = /dev/ttyACM0
Baud = 115200
stupid mode = 1

3.  wvdial as root

Note :

To install wvdial

in debian – apt-get install wvdial
in suse – zypper install wvdial

If your OS does not load the driver for your modem

To load the driver for the modem

lsusb

and you will see something like this

Bus 005 Device 002: ID 1b7d:070a

then do a,

modprobe usbserial vendor=0x1b7d product=0x070a

Note that the vendor and product values are from 1b7d:070a in the above line with 0x appended.

  • Share/Bookmark