Archivo

Entradas Etiquetadas ‘perl’

Using Windows ? Don’t Kill Yourself

lunes, 27 de octubre de 2008 Sin comentarios

Using Windows ? Don’t Kill Yourself

Supose you are Linux user and you have a Windows system.

Alternatives: Cygwin, Mingw or Colinux

You need some (or all) of this interpreters:
Perl, PHP, Python and Ruby

Modify the %PATH%

Example you have a bin dir, on C:\ to include the executables on the %PATH% do this:

1
set PATH=%PATH%;C:\bin\

On Windows Vista, you can use your mouse:

computer > properties > Advances system settings > (continue) > Advanced > Enviroment Variables > System Variables > Path (edit)

Example run Kompozer on cmd.exe but no modify %PATH%

1
2
: kompozer.bat save on %WINDIR%
@"C:\Program Files\Kompozer\kompozer.exe"

Doble click on your scripts to run:

1
2
3
4
5
6
7
8
: Perl Scripts
 assoc .pl=Perl.File
 ftype Perl.File=C:\strawberry\perl\bin\perl.exe "%1" %*
 set PATHEXT=%PATHEXT%;.pl
: Python Scripts
 assoc .py=Python.File
 ftype Python.File=C:\Python26\python.exe "%1" %*
 set PATHEXT=%PATHEXT%;.py

Note:
On Windows Vista you need run cmd.exe as Administrator don’t work as normal user

Apache, PHP and MySQL ?
XAMPP and Server2Go

Notes:
XAMPP: simple, quick and easy install.
Server2Go: is great to make CD demo of a Web Application.

Using Perl or Python as CGI on Windows ?

Using Python 2.6

1
#!\python26\python.exe

Using Strawberry Perl:

1
#!\strawberry\perl\bin\perl.exe

Now your script works on http://localhost/cgi-bin/script.cgi

Categories: develop, unix/linux, windows Tags: , , , , ,

PDF Libraries

jueves, 2 de octubre de 2008 1 comentario

PDF Libraries

Sometimes we need create or export data into a PDF:

.NET:
http://www.pdfsharp.com, http://www.codeplex.com/Print2Pdf

C++:
http://libharu.org

Perl:
http://search.cpan.org/~markusb/PDF-Create/lib/PDF/Create.pm

sudo perl -MCPAN -e 'install PDF::Create'

PHP:
http://www.fpdf.org, http://www.digitaljunkies.ca/dompdf, http://pear.php.net/package/File_PDF

Python:
http://www.reportlab.org

wget -c http://www.reportlab.org/ftp/ReportLab_2_2.tgz
tar xvzf ReportLab_2_2.tgz
cd ReportLab_2_2
sudo python setup.py install

Java:
http://www.lowagie.com/iText, http://www.pdfbox.org

Ruby:
http://ruby-pdf.rubyforge.org/pdf-writer

sudo gem install pdf-writer
Categories: develop Tags: , , , , , ,

YouTube++ Download and Converter

lunes, 15 de septiembre de 2008 Sin comentarios

YouTube++ Download and Converter

Necesitas: Perl, wget, ffmpeg y este script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/perl
use LWP::Simple;
print "YouTube++ (URL's to MP3's) By Albertux\n[http://albertux.ayalasoft.com]\n";
 
$total = @ARGV;
 
if ($total==0) {
 
	print "\nExample: ~\$ youtube\+\+ url1 url2 url3 ...\n";
 
} else {
 
	foreach(@ARGV) {
 
		$URL = $_;
		$aux = index($URL,"?v=");
		$a = substr $URL,$aux+3,11;
		$content = get($URL);
		@lines = split("\n",$content);
 
		foreach(@lines) {
			my $aux = index($_,"&t=");
			if ($aux > -1) { 
				$t = substr $_, $aux+3,32;
			}
		}
		system "wget -c -O \"$a.flv\" \"http://youtube.com/get_video?video_id=$a&t=$t\"";
		system "ffmpeg -i \"$a.flv\" -ab 128k \"$a.mp3\"";
	}
}
print "\nFeedback to: <albertoi7\@gmail.com>\n";

Ejemplo tu tienes un archivo con las urls de algunos videos (YouTubeUrls.txt):

http://www.youtube.com/watch?v=-j39ABZyzek
http://www.youtube.com/watch?v=5cGvzApDZKI
http://www.youtube.com/watch?v=w1mgEQTMVB8
...

Este script bajara todos los archivos flv y los convertira a mp3.

youtube++ `cat YouTubeUrls.txt`
Categories: unix/linux, web Tags: ,

Safe and Dirty Remote XMLHttpRequest

miércoles, 27 de agosto de 2008 2 comentarios

Safe and Dirty Remote XMLHttpRequest Algunas veces necesitamos que el XMLHttpRequest funcione en diferentes dominios, una solucion simple, necesitas JavaScript y Perl:

El XMLHttpRequest(); ejemplo:

var req = new XMLHttpRequest() // IE7, Firefox, Safari, Opera
req.open('GET', 'http://localhost/cgi-bin/remote.pl?url='+url, false);
req.send(null);

Para hacer que funcione usamos remote.pl:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl
use LWP::UserAgent;
use CGI qw(:standard);
print "Content-type: text/plain\n";
my $url = param ('url');
$ua = LWP::UserAgent->new;
$ua->agent("Mozilla/8.0");
$req = HTTP::Request->new(GET => $url);
$req->header('Accept' => 'text/html');
$res =$ua->request($req);
if ($res->is_success) {
	$page = $res->content;
} else {
	$page = "error";
} print $page;

Aqui un ejemplo:

El remote.pl se puede implementar mucho mejor (metodos GET y POST, parametros y sus valores).

Categories: develop, web Tags: ,

Standalone Executable Perl script

martes, 19 de agosto de 2008 1 comentario

Standalone Executable Perl script

Necesitamos PAR::Packer un modulo de Perl

En GNU/Linux Perl ya esta instalado, en Win32 es necesario instalar Strawberry Perl (ActivePerl no funciona).

Ahora en tu linea de comandos (cmd.exe/bash):

cpan -i pp

Decimos que si a todas las preguntas (Par::Packer necesita otros modulos para funcionar)

Ahora tu puedes generar un ejecutable de un script de perl usando esto:

pp -o standalone myscript.pl

Nota: en Win32 cambias standalone por standalone.exe (toma mas tiempo generar un ejecutable en Win32).

Categories: develop Tags: ,

Switch to our mobile site