Are you looking for my non-technical blog?

This is now my technical-only blog, my non-technical blog is here.
Showing posts with label Computers. Show all posts
Showing posts with label Computers. Show all posts

12 January 2006

Sqlite - Date and Time Data Types

SQLite handles dates quite strangely. If you create a table and put a date in it, the only way SQLite will take the input is "2004-06-01 12:00:00" anything else it won't recognize as a date and thus none of the date functions will work. Assuming you have a date entered propely (like above) you get date information from the db like so.
SELECT date(DateField) FROM Table; SELECT time(DateField) FROM Table; SELECT datetime(DateField) FROM Table;
If you want unix time (seconds since the epoch) you have to format the output.
SELECT strftime("%s",DateField) FROM Table;
However that will return the time in UTC which is probably not what you want (it's not what I wanted). I want it to compensate for my local timezone and thus you have to tell it to use your timezone.
SELECT strftime("%s",DateField,'localtime') FROM Table;

Related Posts:
Green Data: Pysqlite

Sources: Perturb.org , Sqlite Wiki
Tags: , ,

07 January 2006

Writing Arabic on Ubuntu

بسم الله الرحمن الرحيم
To write Arabic on Ubuntu, first make sure that you have Arabic Language Pack (use Synaptic Package Manager to find "language-pack-ar", and "language-pack-ar-base") I also have "ttf-arabeyes" and "libfribidi0" installed here. By the way there is a package called "language-support-ar" that I think it includes all of the above stuff. Then go to System->Preferences->Keyboard and from the "Layouts" tab add the "Arabi/qwerty" layout. Now right click on an empty area in the "Panel" (The bar at the bottom of your screen) and choose "Add to Pannel" and add the "Keyboard Indicator" and here you go.

Tags: , ,

PyFusker

Python implementation of Fusker Introduction: Most probably you are redirected from Wikipedia to this page, so please if you have any comment on the code just leave it here so that I can improve it. Also if you can help me know why are people interested in the fusker technology that much, and what web sites do you usually fusker.
The Python Code
#!/usr/bin/python
""" PyFusker """
""" Author: Tarek Amr """
""" Version: 0.1 """
""" File: pyfusker.py """
""" Date: 07 January 2006 """
""" Replce [TAB] with \t """
class Fusker:
[TAB]def __init__(self, url):
[TAB][TAB]self.url = url
[TAB][TAB]self.urls = []
[TAB][TAB]self._generate()
[TAB]def _generate(self):
[TAB][TAB]comp = re.compile("\\[.+\\]")
[TAB][TAB]x = comp.findall(self.url)
[TAB][TAB]if not x:
[TAB][TAB][TAB]print "Url parsing error!"
[TAB][TAB][TAB]sys.exit()
[TAB][TAB]try:
[TAB][TAB][TAB]x[0] = x[0].strip("[")
[TAB][TAB][TAB]x[0] = x[0].strip("]")
[TAB][TAB][TAB]x1,x2 = x[0].split("-")
[TAB][TAB][TAB]x1 = string.atoi(x1)
[TAB][TAB][TAB]x2 = string.atoi(x2)
[TAB][TAB]except:
[TAB][TAB][TAB]print "Url parsing error!"
[TAB][TAB][TAB]sys.exit()
[TAB][TAB]if x1 > x2:
[TAB][TAB][TAB]print "Invalid range"
[TAB][TAB][TAB]sys.exit()
[TAB][TAB]temp_url = comp.split(url)
[TAB][TAB]i = x1
[TAB][TAB]while i < x2 :
[TAB][TAB][TAB]self.urls.append(string.join(temp_url,"%s" % i))
[TAB][TAB][TAB]i = i + 1
[TAB][TAB]return self.urls
[TAB]def list_urls(self):
[TAB][TAB]print self.urls
[TAB]def download_urls(self):
[TAB][TAB]for u in self.urls:
[TAB][TAB][TAB]try:
[TAB][TAB][TAB][TAB]print "Downloading ... ", u
[TAB][TAB][TAB][TAB]os.system("wget %s" % u)
[TAB][TAB][TAB]except:
[TAB][TAB][TAB][TAB]print "Wget Error!"
[TAB][TAB][TAB][TAB]continue
if __name__ == "__main__":
[TAB]try:
[TAB][TAB]url = sys.argv[1]
[TAB]except:
[TAB][TAB]print "Usage: python fusker.py http://www.website.com/img[01-06].jpg"
[TAB][TAB]sys.exit()
[TAB]f = Fusker(url)
[TAB]f.download_urls()
Tags: , ,

25 December 2005

pysqlite

SQLite is a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine. While pysqlite is a Python DB-API 2.0 interface for it. So in order to install pysqlite you have to have sqlite installed. But unfortunately when trying to install sqlite using apt-get it seems that some header files were missing that prevented pysqlite from being installed properly. So after installing sqlite from source, I was able to install pysqlite successfully.

Tags: , ,

16 December 2005

Python - libgmail Tutorial

This is a short tutorla about libgmail. Which is a Library to provide access to Gmail via Python. Tabs are important in python as they indicate the different code blocks, since they do not have "{" and "}" like those in C and C++. So I'll replace the tabs here with [TAB], since it's hard to write the proper format in HTML.

First of all lets see how can we get the libgmail help, a.k.a man pages:
>>>import libgmail
>>>help(libgmail)
Then lets see how can we retrieve the messages in our the inbox:
>>>import libgmail
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>folder = ga.getMessagesByFolder("inbox", True)
>>>for thread in folder:
>>>[TAB]print "Thread:", thread.id, "Subject:", thread.subject
>>>[TAB]for msg in thread:
>>>[TAB][TAB]print "Msg:", msg.id, ",Author", msg.author, ",Subject:", msg.subject
Now lets say we want to print all the attached files in all the messages labled by "projectx"
>>>import libgmail
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>folder = ga.getMessagesByLabel("projectx", True)
>>>for tread in folder:
>>>[TAB]for msg in thread:
>>>[TAB][TAB]for attach in msg.attachments:
>>>[TAB][TAB][TAB]print attach._getContent()
You may also send a message this way:
>>>import libgmail
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>msg=libgmail.GmailComposedMessage("friend@gmail.com", "SubjectHere", "BodyHere")
>>>ga.sendMessage(msg)
To send attachmented files into the message:
>>>import libgmail
>>>ga = libgmail.GmailAccount("username@gmail.com", "password")
>>>ga.login()
>>>myFiles = ["/file1", "/file2", "/file3"]
>>>msg=libgmail.GmailComposedMessage("friend@gmail.com", "SubjectHere", "BodyHere", filenames=myFiles)
>>>ga.sendMessage(msg)
Finally I've noticed that sometimes the sendMessage() function fails - returns "HTTP Error 404: Not Found", and hope that they are going fix it soon. Actually the function fails on the first time but when you call it again it works, so you may use a "try-except" statement like the one below:
>>>try:
>>>[TAB]ga.sendMessage(msg)
>>>except:
>>>[TAB]ga.sendMessage(msg)

Tags: , ,

15 December 2005

C - Hex Dump Function

Every sniffer has a hex dump function in order to print the captured packets to the user, so this is a hex dump function I made ... mycap_dump()

Tags: , ,

31 July 2005

OpenSSL: Creating Digital Certificate Tutorial

Here is the way to - HOWTO - create a Digital Certificate using OpenSSL software.
First of all install OpenSSL on you PC, and add its bin file to your executables path.

Create your Own CA
Then create some directory to be your CA directory (let's call it demoCA)
Now create the following 3 directories in demoCA (requests, certs, and keys) and create the following to files (database.txt, and serial.txt) and open serial.txt and write 01 in it. Also don't forget to copy the file openssl.conf there too.
Now you need to create your CA key:
"openssl genrsa -des3 -out keys/ca.key 1024"
Create a master certificate based on this key, to use when signing other certificates:
"openssl req -config openssl.conf -new -x509 -days 1001 -key keys/ca.key -out certs/ca.cer"

Create the Digital Certificate
Generate private key for the certificate:
"openssl genrsa -des3 -out keys/foo-key.pem 2048"
Create a certificate request:
"openssl req -new -key keys/foo-key.pem -out requests/foo-req.csr"
Sign the certificate by the CA:
"openssl ca -policy policy_anything -config openssl.conf -cert certs/ca.cer -in requests/foo-req.csr -keyfile keys/ca.key -days 3650 -out certs/foo-cert.cer"
Convert the certificate format to x509 to be used by Windows Internet Explorer
"openssl x509 -in certs/foo-cert.cer -out certs/foo-cert-509.cer"

Note1: For windows users replace all "/" with "\"
Note2: You can get openssl.conf from anywhere, just google for it.
Note: This is how to use a self signed certificate on a Netscreen firewall

Tags: , , , ,

11 July 2005

Linux USB to Serial to Console NetScreen Firewall

I have Linux installed on my laptop, and the laptop does not have serial port that's why I am using a usb2serial in order to console any external devices. So here is the configuration I done on my Ubuntu linux 5.04 in order to console NetScreen firewall (this can be used with many other devices as well).

First of all I installed minicom then configured it as follows:
Ctrl+A then press Z then O, then choose "Serial port setup", then press A and configure " Serial Device : /dev/ttyUSB0" then press enter and press E and configure "Bps/Par/Bits: 9600 8N1" then press enter and save setup as default and exit and here we go.

Tags: , , ,

30 June 2005

TAR.GZ

Many people keep on asking how to archive and compress a folder on a UNIX/Linux system.

Suppose you have a directory /usr/myDir and want to compress it to myDir.tar.gz
# tar –cvf myDir.tar /usr/myDir
# gzip myDir.tar

And to unzip and untar a ".tar.gz" file type
# tar -zxvf myDir.tar.gz