Firefox 9 is now available — but unlike its previous rapid release forebears where not a lot changed, a huge feature has landed with the new version: the JavaScript engine now has type inference enabled. This simple switch has resulted in a 20-30% JS execution speed increase (PDF), putting JaegerMonkey back in line with Chrome’s V8 engine, and even pulling ahead in some cases. If you switched away from Firefox to IE or Chrome for improved JS performance, now is probably the time to give Firefox another shot.

Repositories:

Official 64-bit and 32-bit Mozilla Firefox 9.0 packages are now available for the following Ubuntu distributions:

  • Ubuntu 11.10 (Oneiric Ocelot)
  • Ubuntu 11.04 (Natty Narwhal)

Installing Mozilla Firefox 9.0:

$ sudo add-apt-repository ppa:mozillateam/firefox-next
$ sudo apt-get update
$ sudo apt-get install firefox

References:

Python is a programming language that lets you work more quickly and integrate your systems more effectively.

I’ve been programming primarily in Python lately, and had the need to open a socket to a MySQL database to pull data. By default, older versions of Python does not currently have a mySQL library that can easily interact with MySQL databases. Rather than upgrading Python and possibly breaking your existing scripts, this article will teach you how to open a MySQL socket using MySQLdb from the DB-API.

DB-API’s design is similar to that used by Perl and Ruby DBI modules, the PHP PEAR DB class, and the Java JDBC interface: It uses a two-level architecture in which the top level provides an abstract interface that is similar for all supported database engines, and a lower level consisting of drivers for specific engines that handle engine-dependent details. This means, of course, that to use DB-API for writing Python scripts, you must have a driver for your particular database system. For MySQL, DB-API provides database access by means of the MySQLdb driver.

Install setuptools

First, we’ll need to install Python “setuptools” which allows us to easy install Python libraries. (official site: http://pypi.python.org/pypi/setuptools)

Install it with a package manager, or download the source from the official site.

RHEL/CentOS:

yum install python-setuptools

Debian/Ubuntu:

apt-get install python-setuptools

Install MySQLdb from DB-API

Download the latest version of MySQL-python from sourceforge.

Note: you must have mysql header libraries installed on the server you wish to install the library (these can be found in the ‘mysql-devel’ packages on most distributions)

Now unpack it on your server:

$ tar xfz MySQL-python-1.2.1.tar.gz
$ cd MySQL-python-1.2.1

You can edit site.cfg if necessary for your environment, but it is not required.

$ python setup.py build
$ sudo python setup.py install (or su first)

Import the library in your code

Now, all you need to do is “import MySQLdb” and open a connection:

This very simply Python script written by Paul DuBois (paul@kitebird.com) can be used as an example to open a MySQL connection and print the server’s version:

conn = MySQLdb.connect (host = “localhost”,
user = “testuser”,
passwd = “testpass”,
db = “test”)
cursor = conn.cursor ()
cursor.execute (“SELECT VERSION()”)
row = cursor.fetchone ()
print “server version:”, row[0]
cursor.close ()
conn.close ()

If you wanted to add in error handling for failures, you could wrap the connection
in a try: statement and then do something like this:

except MySQLdb.Error, e:
print “Error %d: %s” % (e.args[0], e.args[1])
sys.exit (1)

Query execution examples

Executing queries is very simple in MySQL Python. All you need to do is take your cursor object and call the ‘execute’ function. The execute function requires one parameter, the query. If the query contains any substitutions then a second parameter, a tuple, containing the values to substitute must be given.

Example 1: Create Table

cur.execute(“CREATE TABLE song ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, title TEXT NOT NULL )”)
In this example you can see how a basic query without any parameters is executed.

Example 2: Execute Insert / Single Substitution Query

songs = (‘Purple Haze’, ‘All Along the Watch Tower’, ‘Foxy Lady’)
for song in songs:
cur.execute(“INSERT INTO song (title) VALUES (%s)”, song)
print “Auto Increment ID: %s” % cur.lastrowid

In this example, you can see how a query is executed with parameters and you can see how to get the id generated from an auto increment column.

Example 3: Multiple Substitution Query

cur.execute(“SELECT * FROM song WHERE id = %s or id = %s”, (1,2))

It is important to note that when there are multiple parameters to substitue, you must use a tuple to enclose all of the parameters that need to be passed. The parameters are then substituted from left to right with tupe[0] being the left most substitution and tuple[n] being the right most substitution.

Example 4: Execute Select

numrows = cur.execute(“SELECT * FROM song”)
print “Selected %s rows” % numrows
print “Selected %s rows” % cur.rowcount

From this you can see that executing select queries is very easy. There are two ways you can get the number of rows the query returned. The MySQLdb specific way is to save the return value from the execute statement. This is NOT the preferred way. You should use the second method which is the Python DB-API 2.0 way because it will make it easier if you ever have to change databases. Both method’s are illustrated in this example.

This is too complicated for me


Well, maybe you shouldn’t be coding in Python then. If you want the easy way out, install the latest version of Python which comes with MySQL support out of the box.

I recently stumbled upon an awesome tool called Namebench. Namebench it’s a small program wrote in python that search for the fastest DNS server near to you. Namebench runs benchmarks using your web browser history, tcpdump output, or standardized datasets in order to provide an individualized recommendation. Namebench is completely free and does not modify your system in any way. It’s currently a “Google” project.

The source are available on the official site, as wrote this is a python program so you should be able to run it from the command line without any additional package, if you want also the GUI you need also the package python-tk, this is usually available in all the main repositories of the principal distributions.

On Ubuntu 11.04, you can easily install it with:

$ sudo aptitude install namebench
The following NEW packages will be installed:
blt{a} namebench python-dnspython{a} python-graphy{a} python-jinja2{a} python-tk{a} tk8.5{a}
0 packages upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,234 kB of archives. After unpacking 11.1 MB will be used.

Run it from any command line or with a launcher. The nameservers field will already be populated with your current DNS servers taken from your resolv.conf.

In Query Data Source you can choose where to take the DNS names to be tested, from your browser history, Top 2000 Alexa sites or do other latency tests.

Once you have selected your options just click on Start Benchmark and wait, it took around 10 minutes on my computer to run all the the tests. For geeks, you’ll want to run this in a terminal and watch the output. At the end you’ll have a page with all the results and some nice graphs, but you are just interested at the information at the top. On the left you can see an estimation of how much you can gain in using the DNS server listed on the right side.

Now, modify your configuration…

Now that you know which DNS server to use you just need to change your resolv configuration file. On a terminal, simply edit /etc/resolv.conf.

In this file put the same IP addresses that tested best in the results of your benchmark, something like:

nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 4.2.2.1

I’m a huge fan of the oldschool “patch” command, and sometimes in the wild I use Gitorious’ “raw diff” view which puts the changes in easy to read patch format. However, you can also do this on the command line to create a patch file that can be applied using “patch -p0 < patchfile".

git diff –no-prefix > patchfile

When you want to apply the patch to your old local copy:

patch -p0 < patchfile

Or, if you have an existing “git diff” patch file that was created without the “–no-prefix” option, you can apply that patch and ignore the default a/ b/ source prefixes with:

patch -p1 < patchfile

I just upgraded to Firefox 6 on Ubuntu. The new version doesn’t have any major interface changes but is 20% faster than Firefox 5. Startup time has also been improved especially for those like me with a lot of tabs and groups. Firefox 6 uses about 8% less resources than the older version so it doesn’t torture your resources as much. Firefox 6 handles zoom better and looks a lot cleaner when you zoom in on a page.

It’s this easy:

* sudo add-apt-repository ppa:mozillateam/firefox-stable
* sudo apt-get update
* sudo apt-get dist-upgrade

Enjoy!

To migrate from Virtuozzo VPS to OpenVZ you must “rsync” root area to private area to avoid incompatibility of OpenVZ and Virtuozzo Cache Templates.

1. Create your VPS with id 3 using your desired template (for example)

# vzctl create 3 –ostemplate ubuntu-11.04-x86_64 –conf unlimited
Creating container private area (ubuntu-11.04-x86_64)
Performing postcreate actions
Saved parameters for CT 3
Container private area was created

2. Start your VPS

# vzctl start 3
Starting VPS …
VPS is mounted
Setup slm memory limit
Adding port redirection to VPS(1): 4643 8443
VPS start in progress…

3. Now on Virtuozzo we have to stop and mount VPS

# vzctl stop 3
Stopping VPS …
VPS was stopped
VPS is unmounted

# vzctl mount 3
VPS is mounted

4. Now we have to make a migration of files with Rsync to OpenVZ Node

# rsync -a -e ssh /vz/root/3 root@OpenVZ_node_IP:/vz/private/
# rsync -a -e ssh /etc/sysconfig/vz-scripts/3.conf root@OpenVZ_node_IP:/etc/sysconfig/vz-scripts/

5. On OpenVZ System, we now start and enter on your OpenVZ node to see if migration works correctly:

# vzctl start 3
Starting VPS …
Initializing quota …
VPS is mounted
VPS start in progress…

# vzctl enter 3
entered into VPS 3

6. Success!

Graphite is a highly scalable real-time graphing system. We use it to graph all sorts of metrics. Basically, you write an application that collects numeric time-series data that you are interested in graphing, and send it to Graphite’s processing backend, carbon, which stores the data in Graphite’s specialized database. The data can then be visualized through graphite’s web interfaces. This tutorial expects that you are using a RHEL/CentOS based server.


Click here for the full Tutorial




Git is a distributed revision control system with an emphasis on speed. Git was initially designed and developed by Linus Torvalds for Linux kernel development. This guide will walk you through the basics of getting up and running with git.

First, you’ll need to install the client. If you’re using Ubuntu, you’ll want apt-get. Obviously RHEL based systems, use yum. If you do not have either, you’re hopefully smart enough to install git from source.

# apt-get install git
or
# yum -y install git

Great. Assuming that went successfully, you should now be able to run “git” and see the usage output.

Creating new repositories:

# mkdir myrepo
# cd myrepo
# git –bare init

Initialize and Commit

If you have an existing project in a folder, you can commit this as an initial import into your new repository. To do this, cd into the folder in question and do the following:

# git init
# git add .
# git commit -a -m ‘my first push’
# git remote add origin git@your.server.name:myrepo
# git push origin master

Creating an SSH key

You’ll want to create an SSH key to allow you to quickly pull and push to your remote repository.

# ssh-keygen -t dsa
# scp .ssh/id_dsa.pub git@your.server.name:
# ssh git@your.server.name
# cat id_dsa.pub >> .ssh/authorized_keys
# chmod 644 .ssh/authorized_keys

Many folks will know this in many other programming languages (C, C++, etc) as a “pointer”, but what if you’re a bash kid at heart and you want to define a variable within a variable?

I encountered this exact quandary today while coding a pretty sophisticated script which reaches back into the past for data. The script would simply take the current day and subtract to go “back in time”. The problem arose in the beginning of the month, when reaching back 4 days from the 3rd would give you a value of -1. I coded a workaround, using standardized variables with incremental numbers and a for loop. At that point, I had to find a way to tell the called function that if we’re in a day that’s “-lt 10″ (less than 10) to be a tad bit smarter.

for TIMETRAVEL in {1..8}
do
getdaydata $TIMETRAVEL
done

So, the $TIMETRAVEL variable is going be 1 through 8 (1,2,3,4,5,6,7,8). The function “getdaydata” is getting passed each number between 1 and 8. The function then needed to take this data and formulate a new variable “pointing” to the previously defined variable. It took a bit of fiddling, but here’s how I did it:

eval HISTMONTH=\$BACK${TIMETRAVEL}MON
eval HISTDAY=\$BACK${TIMETRAVEL}DAY

Using eval, I’m able to build and define “$HISTMONTH” and “$HISTDAY” with previously defined variables within the getdaydata() function.

Microsoft developing apps for Linux

Posted: 30th June 2011 by kire in comedy & funny ha ha