Saturday, November 20, 2010

Brian Bromberg Solo



Enjoy!

Victor Wooten - DMB concert (live)



Victor Wooten solo bass @ Live DMB Concert.

Thursday, November 11, 2010

Sync Google Calendar with your Gnome Desktop

This is pretty exciting for me. I just realized that I could sync my Ubuntu Gnome Desktop Calendar with my Google Calendar account. And also the great thing about it is that it is really easy to do.

First open your web google calendar account. On the left pane, under "My Calendar" and your email address, click 'Settings'. Then you will see the setting page. Click again your email address to get more detailed settings. On the bottom of this page you will see "Private Address". Copy the private ICAL url.
Once you have done that, open terminal and enter the following command:
$ /usr/lib/evolution-webcal/evolution-webcal YOUR_PRIVATE_ICAL_URL

Set the appropriate configuration if necessary, and you are done.

Now, to see the result, click on the Date Time info on the toolbar (above), and you should see the dates which you have activities (appointments) are marked bold. You should also see 'Appointments' list.

Enjoy managing your time and day with Google Calendar and Gnome Desktop.

Tuesday, September 14, 2010

Autostart Vino and Configure Local Connection Only

Continuing my previous post about vnc over ssh, here is a way to limit the connection to local only.

If you are using gnome, you can configure it via gconf-editor. Go to the following key: /desktop/gnome/remote_access/network_interface and set 'lo' as the value. This way, vino server will only listen to local (loopback) interface only.

Now, if you would like to have vino server ready on each time you logged in, you need to configure it from, System -> Preferences -> Desktop Session Settings, and enable Remote Desktop.

Remember to configure Remote Desktop itself, from System -> Preferences -> Remote Desktop Preferences and allow other users to view your dekstop.

Saturday, September 11, 2010

Install Windows XP from usb flash

I just finished installing windows xp on HP Mini 110 netbook. Since it does not have any optical drive, like any other netbook in general, I had to install it from usb flash.

Before you proceed you need to have and prepare the following files and apps:

  • windows xp installation (cd or iso)

  • usb flash (1 to 2GB)

  • wintoflash

  • sata windows xp driver if needed, for example sata driver (from HP)

  • nlite, if need to have sata driver ready during installation

  • winrar, to extract sata driver

  • If you have windows xp installation in iso format, you need to be able to mount it. One way to do it is by using daemon tools lite



A little bit more information about wintoflash, it needs .net framework to run. If you do not want to install .net framework, there are several portable wintoflash with .net framework built-in, just search and use it.


Scenario #1: Without SATA driver

  • Simply, load the windows xp installation cd, or mount the iso file.

  • Then, use wintoflash to create windows xp installation usb flash.

  • All you need to do in wintoflash is to choose the source drive (windows xp installation cd/iso) and choose the usb drive.

  • Restart your computer and boot from usb drive.

  • Choose text for 1st time boot, and GUI for 2nd and 3rd.



Scenario #2: With SATA driver

  • Insert windows installation cd or mount iso (using daemon tools lite)

  • Extract sata driver files using winrar

  • Run nlite, proceed until there is an option about driver integration

  • Choose insert and multiple drivers folder options, select all extracted sata driver files

  • Nlite will prepare windows installation files with sata driver in the target directory. Done with nlite.

  • Plug usb flash

  • Run wintoflash, choose the appropriate source installation folder from previous step, and the target drive (usb). Done with wintoflash

  • Restart computer and boot from usb flash.

  • Choose text for 1st time boot, and GUI for 2nd and 3rd.

Thursday, July 15, 2010

noVNC: HTML5 VNC Client

I have been playing around with Chromium OS (Google Chrome OS). The only thing I can do with it is pretty much just browsing. So, I had to find a way to remote my desktop computer somehow. Mostly, I use VNC for remote desktop.
So, I have to be able to perform remote desktop via web browser (Chromium) using VNC protocol. Fortunately, there is noVNC, which requires python (for websocket) and flash. Excellent, those things are already available with my default Chromium OS.

Here is how I did it:

1. Download noVNC from here.

2. Extract that file:
$ tar zxvf kanaka-noVNC-xxx.tar.gz

3. Change to the directory created in step #2.

4. Now, you have to move *.html files and includes directory in the same locations as web.py (in util directory).

5. Run the websocket proxy with the proper arguments, in my case:
$ python wsproxy.py -f 5901 desktop_pc_ip:5900
# 5901 is the port that I will use for the web vnc client.
# 5900 is the VNC Server port running in the target computer.

6. Run the web server:
$ python web.py 8080 # 8080 is the web server port

7. Go to the (Chromium) browser and enter the following in the url:
"localhost:8080/vnc.html"

8. After the web vnc client appears in the browser, enter the following data:
host: 127.0.0.1
port: 5901 # check with the local port in step #5
password:
then click "connect" button, and everything should work fine.

Now, I can do some other stuff other than just browsing, with my Chromium OS.

Wednesday, July 14, 2010

Google Chrome OS

Yesterday, I decided to test Google Chrome OS on my Dell Mini 9. After looking here and there on the internet, I found a way to do it.

I am pretty much impressed with the boot time. It is so fast. Well, actually it is obvious. If you have any linux distro and remove all unnecessary modules, services, etc, you will get fast boot time. Or even if you build your own GNU-Linux OS, where you only select all needed elements, it will be really light weight and fast.

I took Chromium OS from here. Gunzipped that file and wrote that image file to my 4GB USB Flash, using dd. Something like the following:
$ sudo dd if=ChromiumOS_x86.img of=/dev/sdb bs=4M

Since I had no idea what the username and password were, I had to hack a bit by manually adding my username and password, via my existing Linux OS. So, no more issue with the user and password for logging in.

The good thing about that particular build of Chromium OS, it has support for Broadcom WLAN (mine is BCM4213). I just needed to run the following command:
$ sudo /etc/install_wl.sh

Go ahead and take a look inside that script. Pretty much just remount the partition to read/write, then add necessary broadcom module, and done.
After that, I had to restart the computer again.

After restart, there was a bit delay with the AP detection. I even had to go to the console (ctrl-alt-F2) and perform the following, just to be sure:
$ sudo iwlist wlan0 scan

This particular build requires internet connection even from the beginning, otherwise you can not do anything, and just stuck with the network connection screen (the very first screen it shows).

After entering proper network connection information and my google account, I ended up with the browser, Chromium of course, which already supports flash. Totally awesome for browsing.

So far I haven't seen, found any awesome stuff, other than the fast boot time. So, in my opinion, from what I experienced so far, this is only useful for those who have permanent (fast) internet connection and only use web for most of their activities. Nothing much you can play around from the OS (Linux) side either. It does not even have python installed.
I really hope for Google Chrome OS has more features in it, because otherwise, it will be just Linux kernel with X Server and Chromium Browser. Also, at least they shoudl have python installed in Google Chrome OS.

Before I ended this post, I would like to share my test on my wife's Lenovo Ideapad S10-2. I used the same usb flash to boot that laptop, and got also fast boot time, and wifi connection.
I read some reviews that for some (unsupported) hardware(s), user have extremely slow system. So, I am glad I have dell mini 9 and Lenovo Ideapad S10-2 which are working quite well with Chromium OS.

Monday, July 12, 2010

Restore a Screwed-Up Terminal

To restore a screwed-up terminal, for example after "cat" a binary file, use the following command in the shell:

$ reset

The above command will restore your terminal to default setting.

Sunday, June 27, 2010

django localization

After digging into django source code, I found a way to format a number or into a proper localization format.

Here is how to do it.

>>> from django.utils import formats
>>> from decimal import Decimal
>>> formats.localize(Decimal(12342341))
u'12,342,341'

You can check out the source code of django.utils.formats, and you can also find some other functions to localize date/time format, and also to sanitize numbers which are localized.

So, remember the DRY principle, and make sure you don't reinvent the wheel by creating existing functionalities.

I'm enjoying django more and more.

Thursday, June 24, 2010

Python Idioms, Idiomatic Python

Get to know more about Python Idioms.

Just some samples of nice python idioms:

result = 'ok' if x > 10 else 'not ok'
result = [ 3 * d.Count for d in data if d.Count > 4 ]

Here are some links which I found very interesting:
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html
http://bayes.colorado.edu/PythonIdioms.html

I will find more links and add them to this post later on.

Use xrandr to set Monitor Screen Resolution

I had a problem with gdm and also with lxde desktop session screen resolution. This is probably problem which occurs on old monitors.
The problem is, in gdm login screen the screen resolution is set to 800x600, which is not good.
So, I found a way on how to set the screen resolution for gdm from this link.

Taken from that link, here is how to do it:
Setting xrandr commands in kdm/gdm startup scripts
Both KDM and GDM have startup scripts that are executed when X is initiated. For GDM, these are in /etc/gdm/ , while for KDM this is done at /etc/kde4/kdm/Xsetup. In either case, you can paste in an xrandr command line string into one of these scripts. For GDM, try putting them right before initctl -q emit login-session-start DISPLAY_MANAGER=gdm in /etc/gdm/Init/Default

Monday, June 21, 2010

Canon Pixma MP145

Here's the steps:

Download the following from canon website:
1. cnijfilter-common_2.80-1_i386.deb
2. cnijfilter-mp140series_2.80-1_i386.deb

There will be problem related with dependency if you want to install them directly (my case is with Ubuntu 10.04).
Both packages depend on libcupsys2, while in my version of Ubuntu it should be libcups2.

So, next step is to modify those packages to use the proper package dependency.

$ mkdir modified-deb
$ dpkg -x cnijfilter-common_2.80-1_i386.deb modified-deb/cnijfilter-common_2.80-1_i386
$ dpkg -e cnijfilter-common_2.80-1_i386.deb modified-deb/cnijfilter-common_2.80-1_i386/DEBIAN

after that, then edit modified-deb/cnijfilter-common_2.80-1_i386/DEBIAN/control and replace licupsys2 with libcups2.

Repackage the updated version:
$ cd modified-deb
$ dpkg -b cnijfilter-common_2.80-1_i386

Do the same thing with the other package, cnijfilter-mp140series_2.80-1_i386.deb.
Finally, install both packages, and you are done.

Wednesday, June 16, 2010

Scp in Nautilus

Performing scp in nautilus turns out to be so easy. Since I use custom port for my ssh server, I just need to enter the following in nautilus location (ctrl+L for shortcut):

ssh://server_ip:custom_port

Then nautilus will ask your username and password for ssh. That's it.

Django 1.2.1 Localization

I just finished playing around with django 1.2.1 localization. I did that because after finished upgrading to django 1.2.1, I was amazed with the Indonesian language localization in the admin page. Exactly what I need!
I had a bit trouble working with localization, which turned out that it is related with the language support of the OS, in my case, Ubuntu 10.04. Another thing is that I was doing this on ubuntu live-usb flash. I can take that usbflash, plug it in any computer, boot up, and continue my work.

First of all, go to the following directory and check whether your OS has support for your preferred language.

$ cd /var/lib/locales/supported.d
$ ls

In my case, I did not have 'id' in that directory. So, I had to perform the following:

$ sudo aptitude install language-pack-id-base language-pack-id

Then perform the following:

$ pwd
/var/lib/locales/supported.d
$ cat id # my preferred language
id_ID.UTF-8 UTF-8


After that let's perform some test in python.

>>> import locale
>>> from datetime import datetime
>>> locale.setlocale(locale.LC_ALL, 'id_ID.UTF-8')
'id_ID.UTF-8' # I took the id_ID.UTF-8 from the content of /var/lib/locales/supported.d/id
>>> datetime.now().strftime('%A %B')
'Rabu Juni'

Right on! Things are working as expected.

Now, it's time to use localization in django forms.
First set the following configuration in settings.py:
USE_L10N = True
USE_THOUSAND_SEPARATOR = True

Then, create a simple form which implements localization.

class TestForm(forms.Form):
deposit = forms.DecimalField(localize=True)
tanggal = forms.DateTimeField(localize=True)

...and you are done. All you need to do is just create a view which has an instance of TestForm and bind it a data (dictionary), and then render it.

The neat thing is when you want to display 'Decimal' data in that form, you will see the proper local thousand separator format being displayed. It will also take local format as an input and recognized and convert it properly.

Enjoy django 1.2.1!

Sunday, May 30, 2010

Exclude Pattern Matching in Linux

If you are using bash shell you can use extended pattern matching functionality.
For example you want to list files in a directory which does not match with certain pattern. Here is how you do it.

$ shopt extglob
extglob off
$ shopt -s extglob # Enable extglob
$ ls -l !(*.foo)

You can also use it with other commands, such as rm, cp, etc.

Thursday, April 8, 2010

Django + Eclipse + PyDev + Aptana

For those who likes Django, which IDE do you like the most for development? Of course this is subjective thing, and it's always interesting to see different answers to that question. Some people says vim, notepad++, some other likes commercial IDEs.
In this case, I prefer eclipse with pydev and aptana plugins.

Once you have Python, Django, and Eclipse installed in your system, it is time to install the necessary plugins.

First is to install PyDev plugin. Install new software in eclipse using this url http://pydev.org/updates.
Then of course configure PyDev to use the appropriate python interpreter that you already have. To do that go to eclipse preferences.

Next is to install Aptana Studio, using this url http://update.aptana.com/install/studio.

Now, you can create django project, either using eclipse's wizard, or using django-admin.py script and import it in your eclipse project.
If you use django orm you will notice that 'DoesNotExist' keyword is not recognized. To solve this matter, do the following:
go to eclipse preferences -> pydev -> editor -> code analysis -> Consider the following names as globals --> add 'DoesNotExist'

Then it is time to configure your project so you can run and debug it in eclipse.
To do that, you need to perform the following:
go to project properties -> run/debug settings -> new (python run)
In main tab:
set the project, choose by clicking the browse button.
set main module, choose by clicking the browse button and select the project's manage.py. When you are doen, it would show something like the following:
${workspace_loc:project/app/path/manage.py}

This step is important, if you are using Aptana Studio plugin. By default django will user port 8000 for it's web server, which conflicts with Aptana Studio plugin service. So it is better to use some other port for django web server.

Again, go to project properties -> run/debug settings.
In arguments tab:
runserver 8080 --noreload

Notice that I am using port 8080 for the web server.

In environment tab:
add new variable:
variable: DJANGO_SETTINGS_MODULE
value: settings

At this point you can test running your django project by using the run setting that configured previously. Enjoy debugging your django project in eclipse.

Monday, March 22, 2010

Text Processing and Data Extraction using sed and awk

Some weeks ago, my friend contacted me for a help. He needs to extract some data from a text file. I am familiar with this stuff, since in my old job I do this quite often. Like usual, the data was just a colon (:) separated file. He needs to extract all fields that starts or contains a particular text. It can appear in different column of the row.

So, I played around using awk, and got something like the following:
awk -F\: '/CSP/ { for(i=1;i<=NF;i++) { if($i ~ "CSP") print $i } }' raw_text_file.txt


Since not long before he asked, I had played around much with regex grouping in python. I just needed to translate the my python regex knowledge in sed. Not much work, of course. So, I came up with the following method, using sed:
sed -r 's/.*(CSP,[0-9]+[:;]).*/\1/g' raw_text_file.txt


Notes: "CSP" is the text that needed to be extracted from the text file, along with some other number(s) after that.

Lots of stuff can be done by regex.
Thanks to Dr.Bunker who taught me so much about regex.

Friday, March 12, 2010

Automatic Display Manager Login using nodm

My posting @ https://answers.launchpad.net/ubuntu/+question/101990

I tried your method and it worked. I have been playing around to get such result for two days. Well, actually there is a little bit of story before I get the result that I wanted. So, I tried some other similar method to Curtis', in my VirtualBox Ubuntu Guest OS. The strange thing is I kept getting problems. The X did not start, and the virtual console resolution got big and too wide.
I had a feeling that I might get different result in "real" system. So, I installed ubuntu 9.10 and applied Curtis' method. It worked. I am glad. What I noticed is that the X is running in virtual terminal #9 (instead of #7). No issue.

I have another method though. During my search, someone mentioned about 'nodm' for automatic display manager. Neat! Yesterday I tried it on VirtualBox with no success. Today I tested it in "real" system and all is well. I really recommend this method.
During 'nodm' installation, I had to remove existing display manager(s) first. Then, set the proper configuration in /etc/default/nodm. Enjoy!

Saturday, February 13, 2010

Python and CSS Selector

Python has a lot of awesome modules for working with html documents. My favorite one is lxml modules. Last time I wrote about xpath using that module.
Now, it is time for css selector using lxml.cssselect.

Straight to an example of using it:

from lxml.cssselect import CSSSelector
css_sel = CSSSelector('table.tableSchedule tr')
html_doc = lxml.html.fromstring(some_web_html_string)
row_els = css_sel(html_doc)
print row_els


Sweet and simple.

I am still playing around with it and found that using direct descendant css code is not possible. Something like the following:

css_sel = CSSSelector('table.tableSchedule > tobdy > tr > td')


Please leave a comment if you are able to use ">" in the css code part.

Friday, February 12, 2010

django deep serializers

Django has it's own very nice serialization module. A very useful tool to serialize models in django projects. There is limitation to it, though.
When one serialize a model (table) which has relationship (ForeignKey) to other model, then you will only get the foreign_key, instead the whole object. Something like the following:

[ {
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": 42
}
} ]



In some cases, deep serializing is often necessary. Now, let me introduce you to this magnificent python module which extends django's built-in serializers. DjangoFullSerializers.
With this, you can get something like the following:

[ {
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": [ {
"pk": 42,
"model": "store.author",
"fields": {
"name": "John Doe",
"title": "Dr."
}
} ]
' }
} ]


I have used it and really satisfied with the result. Many thanks to the developer.

Thursday, February 4, 2010

Send key in Linux (Ubuntu)

I have a dell mini 9 laptop which only have Fn keys from F1 to F10. Sometimes I need F11 key for fullscreen browsing, and maybe even F12 key, but they are missing. This little thing annoys me, so I was thinking about a way to send key in Linux.
I did not want to install any other piece of software for this little thing. So, I was thinking about using what is already there in my Ubuntu (default) installation.
xte is just the tool that I needed.
To give you an example, here is the command to send F11 key to active window.

$ xte "key F11"


Pretty neat.

Notes: I just figured out to use F11 and F12 in dell mini 9. Use Fn+z for F11, Fn+x for F12. I tested both keys in Ubuntu 9.04.

Monday, January 25, 2010

dos to *nix text file

One of annoyances when working in both Windows and Linux OS is the different format of the text files created.
In Linux OS, when you open a text file (using vi) which happened to be created within Windows OS, you will see a lot of "^M" character. Really annoying.

In the past I used dos2unix to convert, but I don't use it anymore since I could just use sed, instead.

Here's the command.

$ sed -i -e 's/\r//g' file_name


To make it even easier, I created a shell script which contain that command, like the following:

#!/bin/bash
sed -i -e 's/\r//g' $*


... and you're ready to go.

Tuesday, January 19, 2010

Serialize Form to JSON

I came across a handy javascript function to serialize form to JSON, taken from here

$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};


add above script to your document, then if you are using jQuery you can just do something like the following:

$("form#data").serializeObject();


and as per need, simply use json2.js to convert the (JSON) form object into string:
JSON.stringify($("form#invite_users").serializeObject());

Monday, January 11, 2010

Python and RS323 (ESC/POS) Receipt Printer

Currently, I am working a bit with RS323 (ESC/POS) Receipt Printer. The most interesting part working with it is I do not need to have a driver. This is very helpful because I am planning to use it with Linux OS.
I decided to use Python, so anytime I need to switch to Windows OS, nothing need to be changed in the code part.

Since the printer is using RS323 connection, I need to find the simplest way of communicating with that device in Python. With no effort I found pySerial. Taken from the website itself: This module encapsulates the access for the serial port. It provides backends for Python running on Windows, Linux, BSD (possibly any POSIX compliant system), Jython and IronPython (.NET and Mono). The module named "serial" automatically selects the appropriate backend.

After installing pySerial, I started to play around with it. It is really simple and straight-forward.
It took me sometimes to understand ESC/POS commands, since I was totally not familiar with it.

Just to give some idea on how simple it is, here is an example:

import serial
ser = serial.Serial(port='/dev/ttyS0', baudrate=19200)
ser.portstr #check which serial port
ser.write('Hello World!\n')
ser.close()


I spent sometimes trying to figure out how to work with ESC/POS. One of the issue is the baud rate setting. This must be configured properly otherwise the printer will not print the data properly.

Another thing is that the printer will not print anything if you don't tell it to print data in it's buffer. One way to do this is terminate any string/data you want to print with '\n' (or ASCII decimal 10).

Next step is to know what ESC/POS commands available for your type of printer. I downloaded some docs from the vendor's website, but unfortunately there are only minimum info about ESC/POS programming.
Fortunately, ESC/POS commands is pretty much a standard, so I found some other documents from different vendor, by googling it, and got more informations.

Another interesting thing is that when I tried to print several lines of data in Linux, somehow only partial string in certain line that was printed. Got me confused for a bit, then I realized that this is printer buffer issue. The buffer in the printer is too small for the amount and speed of the data I sent to it. In this case adjustment need to be done, so the printer buffer won't get overloaded and discarded the incoming data.

I don't really like current receipt printer that I work on. Minimum documentations, vendor specific power supply cable, and some other stuff.
I haven't search much about other receipt printer from other vendors, but I am pretty sure that there are some that are more portable to work with.