MathChat

Finally i developed my Ruby on Rails application, A Web Chat for Mathematics! Its’ called MathChat

MathChat supports Latex commands to draw complex mathematical symbols. If you don’t heard about Latex, here is a little tutorial about it.

http://en.wikibooks.org/wiki/LaTeX/Mathematics


And here is a little guide to deploy and run your own MathChat server:

In order to install the dependencies of MathChat you must do the follow in your *unix system (tested on ubuntu 10.04 and 10.10):


~$ sudo apt-get install ruby build-essential libopenssl-ruby libsqlite3-dev rubygems ruby1.8-dev
~$ sudo gem install rubygems-update --version=1.3.7
~$ sudo gem install sqlite3-ruby
~$ sudo gem install -v=2.3.5 rails

That setup an environment to run MathChat and give you the posibility to continue developing the application!
If you know about ruby on rails you can modify and expand the application as you want. It’s really easy.

To run the MathChat server in localhost:3000 just do this inside the MathChat directory:

~$ ruby script/server

Then go to localhost:3000 in your browser (I suggest Google Chrome for better performance) and enjoy MathChat!


MathChat is now hosted at http://www.binpress.com/app/mathchat/147

OR

hg clone https://math-chat.googlecode.com/hg/ math-chat

And, finally a bunch of screenshots!

Regards, Juan Manuel

PHP Web Crawler

I Finished to write a Web Crawler in PHP.

Here’s a Tutorial about it. I hope it will be useful for you.

The web crawler is very easy to use. To run it, just do this in the console:

~$ php main.php

Inside the main directory of the application.

The configuration will be taken from the config.ini file. For example:

config.ini
=========================================
[connection]
host = “localhost:3307”
user = “root”
pass = “root”
db = “jm”

[params]
start_url = “http://www.google.com/”
max_depth = 0
log = “1”
=========================================

The first 4 parameters are the database connection. I assume this is know to you.

The start_url param is the url to start to craw. Note: The url must be complete! Don’t ignore the http:// or https:// if it correspond.

You can specify the maximum of recursive searches in the  max_depth param. 0 only crawls the start url. 1 crawls the start_url and all the urls inside the given url. 2 All the urls inside the urls given by previous and so on… Warning: A factor of 3 or greater can take for hours, days, month or years!

Finally the log parameter indicates if the application shows the crawled urls in the console.

The config.ini can be edited by the web UI:

It’s very intuitive and you eventually can start to crawl from it. You can also watch all that’s crawled to the moment clicking in the “see what’s crawled” button.

Finally I left a list of features about the PHP Web Crawler:

– The crawler can be run as multiple instances

– It can be run by a cron job.

– All the crawls are saved in a mysql database. It generates the table “urls” to store the crawls.

– For each url it saves the url of source, the url of the destiny and the anchor text.

– Validates the urls via a regular expression. It avoids the links to static data into the site. Including the unnecessary media files. Despite this I can’t ensure that the crawler avoids all the media files. That be more complex to validate.

And here is a demo of 6 processes crawling at the same time.

 

The crawler is now hosted at: http://www.binpress.com/app/php-web-crawler/113

 

Regards, Juan Manuel

Python Mini ORM

Recently I was researching on python ORMs like SqlAlchemy, SqlObject or the Django Object relational mapper. The truth is, and I read this from a remarked person on the area, that write an ORM from scratch is very simple! You don’t need to have a lot of knowledges about SQL, DataBases Engines or Data Persistance to make your own Object relational mapper…

Obviously I’m talking of a very simple ORM that implements the basics Concept of SQL to Objects. Don’t expect that a Basic ORM written from scratch scale-up like SqlAlchemy or the Django’s ORM. These are very mature projects with years of development and maintance.

Last days I Wrote a very simple ORM and I published it in pastebin.

I want to show you what you can do with this little toy:

 

A Select * from ‘Table’ and return a list of Table_row objects with the correspondent properties that match the table fields using a sqlite engine looks like this:

>>> import sqlite3

>>> from core import DataBase

>>> db = DataBase(provider=sqlite3, db='youdatabase.db')

>>> print db.Table("Person").rows

[<core.Person_Row object at 0x7fa522ad2050>, <core.Person_Row object at 0x7fa522ad2090>, <core.Person_Row object at 0x7fa522ad20d0>]

Awesome! Really? Yes, if you think that the ORM don’t have more than 160 lines of python code.

 

Let’s have more fun. A more Complex query can be:

>>> import sqlite3

>>> from core import DataBase

>>> db = DataBase(provider=sqlite3, db='youdatabase.db')

>>> print [s.album for s in db.Table("Songs").filter("id > 15").filter("year = 2000").order_by("song").rows]

[u'essential selection vol. one', u'The Beatles 1', u'Please']

It returns a list of Strings with the albums of the songs with id greater than 15 that belong to the 2000 year, order by the song name! Look you can use “s.album”. You have an Song_row Object matching the database table.

 

It’s simple to get the column names of the table wich you’re querying:

>>> import sqlite3

>>> from core import DataBase

>>> db = DataBase(provider=sqlite3, db='youdatabase.db')

>>> print [c for c in db.Table("Songs").columns]

[u'id', u'song', u'album', u'year']

That is all for this moment… you can also use Group by statements as easier as the examples in this post.

At the moment this toy ORM only work with import MySQLdb sqlite3 and psycopg2 modules but it’s easy to extend!

 

The project is hosted at GoogleCode and published also in pastebin. Feel Free to modify the code and get a lot of fun with it! Here are the links:

http://pastebin.com/7SZGzZJ2

svn checkout http://py-mini-orm.googlecode.com/svn/trunk/ py-mini-orm-read-only

 

Happy Coding =)

Regards, Juan Manuel