Archive

Posts Tagged ‘python’

Firts Week August

August 8th, 2010 Albertux 3 comments

First Week August

I know the last month was fucking lazy, but August I think is different, the first week:


CentOS 5.5 setup on VirtualBox with LAMP

Download the netinstall ISO from mirrors:
- CentOS-5.5-i386-netinstall.iso
- CentOS-5.5-x86_64-netinstall.iso

[HTTP Setup]
Website name: mirror.centos.org
CentOS Directory: centos/5.5/os/i386

After many screens select only server

Set up LAMP on CentOS 5.5 Server:

yum install mysql-server # mysql server
yum install php-mysql # php with mysql
/etc/init.d/mysqld start # start mysql (password empty)
# put mysqld and httpd in run levels
chkconfig mysqld --level 2345 on
chkconfig httpd --level 2345 on # httpd is all ready

If you want to start CentOS on background:

# Port forward SSH to 2222 localhost:
VBoxManage modifyvm "CentOS" --natpf1 "guestsssh,tcp,,2222,,22"
# Port forward HTTP to 8080 localhost:
VBoxManage modifyvm "CentOS" --natpf1 "guestshttp,tcp,,8080,,80"
# bash aliases
alias start_centos='VBoxManage startvm "CentOS" --type headless'
alias centos='ssh -p 2222 root@localhost'

Make twitter useful:

#  goto http://code.google.com/p/python-twitter/ on ubuntu:
apt-get install python-twitter
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Albertux (Alberto Isaac Ayala Esquivias)
import re, twitter
import subprocess
####################
# TWITTER  ACCOUNT #
username='_________'
password='_________'
####################
####################
# EXECUTE COMMANDS #
start = ["command","param1","param2"]
stop = ["command","param1","param2"]
####################
####################
api = twitter.Api(username, password)
statuses = api.GetUserTimeline(USER_YOU_FOLLOW)
msgs = [s.text for s in statuses]
last_msg = msgs[0]
flag = re.findall(r"REGEX",last_msg,re.I)
if len(flag) > 0:
    subprocess.call(stop)
else:
    subprocess.call(start)

using bash:

 watch -n 60 ./twitter_check

3taps heartbeater (latency of post):


Myself:




Dr Martin Luther King Jr Pics:


Hackerdojo pics:





Random pics:
P0rn knowledge:

Damn I lost this pin of #hackerdojo :’(


Personal projects:

FTP for Developers

January 29th, 2009 Albertux 2 comments

FTP for Developers

This examples upload a simple text file for a better implementations read the API or documentation for each language or command

Curl:

curl -T filename -u username:password ftp://hostname/filename

Perl:

use Net::FTP;
$hostname = "localhost";
$username = "user";
$password = "pass";
$filename = "file.txt";
$ftp = Net::FTP->new($hostname);
$ftp->login($username,$password);
$ftp->put($filename);
$ftp->quit;

To handle errors use “or die $@” (“$ftp>message” only if login success)

PHP:

<?php
$hostname = "localhost";
$username = "user";
$password = "pass";
$filename = "file.txt";
$conn = ftp_connect($hostname);
ftp_login($conn, $username, $password);
ftp_put($conn,$filename,$filename,FTP_ASCII);
ftp_close($conn);
?>

To handle erros you can use “if(!function)”

Python:

import ftplib
hostname = "localhost"
username = "user"
password = "pass"
filename = "file.txt"
ftp = ftplib.FTP(hostname)
ftp.login(username, password)
ftp.storlines("STOR " + filename, open(filename))
ftp.quit()

To handle errors use “try” and “except” and “else”

Ruby:

require 'net/ftp'
host = 'localhost'
user = 'user'
pass = 'pass'
file = 'file.txt'
ftp = Net::FTP.new(hostname)
ftp.login(username,password)
ftp.puttextfile(filename)
ftp.close

To handle errors use “begin”, “rescue”, “else”, “ensure” and “end”.

Win32 batch:

ftp -s:settings.txt hostname

settings.txt:

username
password
put filename
bye

To handle errors use “if not %errorlevel%==0 goto :error”

Categories: network, unix/linux, web, windows Tags: , , , , ,

Python and NetBeans

January 23rd, 2009 Albertux 1 comment

Python and NetBeans

Menu => Tools => Plugins


New Python Project:




Jython ( http://www.jython.org )
Python ( http://www.python.org )

Categories: unix/linux, windows Tags: ,

Python 3.0 Final Released

December 4th, 2008 Albertux No comments

Python 3.0 Final Released

Python 3.0 (a.k.a. “Python 3000″ or “Py3k”) is a new version of the language that is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially how built-in objects like dictionaries and strings work, have changed considerably, and a lot of deprecated features have finally been removed. Also, the standard library has been reorganized in a few prominent places.

What’s New and download.

Categories: Uncategorized Tags:

TODO LIST 2009

December 1st, 2008 Albertux No comments

TODO LIST 2009

Read/Learn/Practice:

Python 2.6 (What’s New)

Perl 5 (Modules, Packages)

PHP (Changes, and news)

COBOL

.NET (C#, LINQ, (ok VB but not much))

Java (Im interested on Mobil Applications)

Haskell

Ruby (Im interested on Rails)

Parrot and Pugs

Gnu/Linux (Services and Bash)

BSD and OpenSolaris

Personal Projects 2009:

BSE (Blog’s Search Engine) (http://BSE.AyalaSoft.com)

Invoices PHP (Now is part of a Intranet) (http://valuacion.com.mx)

Forming one’s own business

And others ….

Lambda Functions on PHP 5.3.0:

 $lambda = function () { echo "Hello World!\n"; };

Parrot “Hello World” example:

.sub main
      print "Hello World!\n";
.end

COBOL “Hello World” example:

* Hello World Program
* GPL Copyleft Jonathan Riddell 2001
	IDENTIFICATION DIVISION.
	PROGRAM-ID.    hello.
	ENVIRONMENT DIVISION.
	DATA DIVISION.
 
	PROCEDURE DIVISION.
		DISPLAY "Hello ," WITH NO ADVANCING
		DISPLAY "World!"
		STOP RUN.

Haskell “Hello World” example:

putStrLn "Hello World!"