From bit to a heart beat

insane innovations from a sane insanity

Wed Oct 7

Creating a dropdown with country names in web2py

There are many ways to create a dropdown that includes all countries in web2py but the most pythonic way goes like this:

Create a module (let’s name it countries.py) and put a list of countries :

COUNTRIES=(‘United States’, ‘Afghanistan’, ‘Albania’, ‘Algeria’, ‘Andorra’, ‘Angola’, ‘Antigua and Barbuda’, ‘Argentina’, ‘Armenia’, ‘Australia’, ‘Austria’, ‘Azerbaijan’, ‘Bahamas’, ‘Bahrain’, ‘Bangladesh’, ‘Barbados’, ‘Belarus’, ‘Belgium’, ‘Belize’, ‘Benin’, ‘Bhutan’, ‘Bolivia’, ‘Bosnia and Herzegovina’, ‘Botswana’, ‘Brazil’, ‘Brunei’, ‘Bulgaria’, ‘Burkina Faso’, ‘Burundi’, ‘Cambodia’, ‘Cameroon’, ‘Canada’, ‘Cape Verde’, ‘Central African Republic’, ‘Chad’, ‘Chile’, ‘China’, ‘Colombia’, ‘Comoros’, ‘Congo’, ‘Costa Rica’, “Côte d’Ivoire”, ‘Croatia’, ‘Cuba’, ‘Cyprus’, ‘Czech Republic’, ‘Denmark’, ‘Djibouti’, ‘Dominica’, ‘Dominican Republic’, ‘East Timor’, ‘Ecuador’, ‘Egypt’, ‘El Salvador’, ‘Equatorial Guinea’, ‘Eritrea’, ‘Estonia’, ‘Ethiopia’, ‘Fiji’, ‘Finland’, ‘France’, ‘Gabon’, ‘Gambia’, ‘Georgia’, ‘Germany’, ‘Ghana’, ‘Greece’, ‘Grenada’, ‘Guatemala’, ‘Guinea’, ‘Guinea-Bissau’, ‘Guyana’, ‘Haiti’, ‘Honduras’, ‘Hong Kong’, ‘Hungary’, ‘Iceland’, ‘India’, ‘Indonesia’, ‘Iran’, ‘Iraq’, ‘Ireland’, ‘Israel’, ‘Italy’, ‘Jamaica’, ‘Japan’, ‘Jordan’, ‘Kazakhstan’, ‘Kenya’, ‘Kiribati’, ‘North Korea’,’South Korea’, ‘Kuwait’, ‘Kyrgyzstan’, ‘Laos’, ‘Latvia’, ‘Lebanon’, ‘Lesotho’, ‘Liberia’, ‘Libya’, ‘Liechtenstein’, ‘Lithuania’, ‘Luxembourg’, ‘FYROM’, ‘Madagascar’, ‘Malawi’, ‘Malaysia’, ‘Maldives’, ‘Mali’, ‘Malta’, ‘Marshall Islands’, ‘Mauritania’, ‘Mauritius’, ‘Mexico’, ‘Micronesia’, ‘Moldova’, ‘Monaco’, ‘Mongolia’, ‘Montenegro’, ‘Morocco’, ‘Mozambique’, ‘Myanmar’, ‘Namibia’, ‘Nauru’, ‘Nepal’, ‘Netherlands’, ‘New Zealand’, ‘Nicaragua’, ‘Niger’, ‘Nigeria’, ‘Norway’, ‘Oman’, ‘Pakistan’, ‘Palau’, ‘Palestine’, ‘Panama’, ‘Papua New Guinea’, ‘Paraguay’, ‘Peru’, ‘Philippines’, ‘Poland’, ‘Portugal’, ‘Puerto Rico’, ‘Qatar’, ‘Romania’, ‘Russia’, ‘Rwanda’, ‘Saint Kitts and Nevis’, ‘Saint Lucia’, ‘Saint Vincent and the Grenadines’, ‘Samoa’, ‘San Marino’, ‘Sao Tome and Principe’, ‘Saudi Arabia’, ‘Senegal’, ‘Serbia and Montenegro’, ‘Seychelles’, ‘Sierra Leone’, ‘Singapore’, ‘Slovakia’, ‘Slovenia’, ‘Solomon Islands’, ‘Somalia’, ‘South Africa’, ‘Spain’, ‘Sri Lanka’, ‘Sudan’, ‘Suriname’, ‘Swaziland’, ‘Sweden’, ‘Switzerland’, ‘Syria’, ‘Taiwan’, ‘Tajikistan’, ‘Tanzania’, ‘Thailand’, ‘Togo’, ‘Tonga’, ‘Trinidad and Tobago’, ‘Tunisia’, ‘Turkey’, ‘Turkmenistan’, ‘Tuvalu’, ‘Uganda’, ‘Ukraine’, ‘United Arab Emirates’, ‘United Kingdom’, ‘Uruguay’, ‘Uzbekistan’, ‘Vanuatu’, ‘Vatican City’, ‘Venezuela’, ‘Vietnam’, ‘Yemen’, ‘Zambia’, ‘Zimbabwe’)

then import it to db.py

from applications.yourapplicationname.modules.countries import *

and just “map” the whole list to a database field

db.shipping_info.countries.requires = IS_IN_SET(COUNTRIES)

Now, when you render the field using SQLFORM in your view, a dropdown (select) will be created automatically including all the countries.

Yeap, SQLFORM rocks.

Enjoy!

Comments (View)
Mon Sep 28

Adding your .emacs to Mercurial / Git

Having my favorite .emacs settings available, in the tip of my “hg clone” command is precious. No more backups and no more “oh no, I have an older version in my usb stick”. And it’s easy!

First of all, you need a mercurial server. Or an account at http://bitbucket.org/. Of course the same procedure stands for git.

Then you create a new repository (let’s call it my-emacs).

After that, you must move/rename your .emacs.d/ directory to .emacs.d-old/ and clone your repository.

cd ~

mv .emacs.d/ .emacs.d-old

rm -R .emacs.d/

hg clone https://yourname@bitbucket.org/yourname/my-emacs .emacs.d

the last line is available for copy-past on bitbucket.

Then you copy all your files to the .emacs.d which is now under version control

cp .emacs.d-old/ .emacs.d -R

Now the only thing is missing is adding your .emacs file. There are two ways. One is creating a init.el and the other one is having a .emacs file that loads another one dot-emacs.el which is in your version-controlled .emacs.d/

So,

cp .emacs .emacs.d/dot-emacs.el

The .emacs which is outside of .emacs.d (thus not under version control, should have this line:

(load “~/.emacs.d/dot-emacs.el”)

And you are ready! If you need to ignore a directory (which is inside .emacs.d/) just create a .hgignore file inside .emacs.d/ and add the name of the directory or any other files (google “hg ignore”):

ignore-dir/

Finally commit everything and push them to server.

cd .emacs.d

hg add *

hg commit -m “First commit”

hg push

Enjoy!

Comments (View)
Sat Sep 19

First review - Karmic Ubuntu Moblin Remix

No one has posted a review of the upcoming Ubuntu remix, so here we go!

First of all, I installed it via usb-creator on a 64gb USB (you need more than 1gb usb for installation via usb - even a 2gb will do) with no problem at all.

The boot stage is identical to the Ubuntu 9.10 and way slower than Moblin’s boot stage (+10secs). After that, the environment seems the same, but now we have the Ubuntu wallpaper and many Ubuntu programs (OpenOffice, Empathy, Synaptic package manager, etc).

The network still has the same bugs as the Moblin has (can’t save password and I couldn’t connect to wifi) and the main problem is that every time you run a program, it doesn’t seem very integrated into the Moblin UI, so when you close the application, a white screen welcomes you. After that you have to click the menu bar and return to whatever you were doing.

Another thing is that whenever you are starting a program you have to decide whether you want a new space or you want to squeeze it to an old one (the dialog stays for about 3 secs).

Definitely not a production-ready image (it’s called “development iso” for a reason) but I think that in order to utilize the Moblin v2 UI, many application must be rewritten or replaced.

You can check the images in better quality and some more here

Comments (View)
Wed Sep 16

Ubuntu Moblin Remix is out!

It seems that I am the first one the found that Canonical released an iso image of Ubuntu Moblin Remix (UMR), four months after the official announcement that Moblin v2 will be supported and a couple of months after the announcement that they are working on Ubuntu Moblin Remix. That means that the sexy interface of Moblin v2, will be included at the ubuntu repositories (and it will be supported by Canonical).

Pics/videos are coming along with a full review!

Comments (View)
Thu Aug 27

How to setup Emacs 23.1 and slime for Ubuntu

After searching and patching around this is what you have to do:

First, install emacs23 (emacs-snapshot) from here https://launchpad.net/~ubuntu-elisp/+archive/ppa. Choose your distro, add the entries to your sources.list, install and you have emacs 23.1.

Now, add slime and sbcl from ubuntu repositories and add this to your .emacs file:

;; Lisp
(setq inferior-lisp-program “sbcl”)
(add-to-list ‘load-path “/usr/share/emacs/site-lisp/slime”)
(require ‘slime)
(slime-setup ‘(slime-fancy))

and happy hacking!

Comments (View)
Mon Aug 24

OpenShare :: The First OpenSource Ad network!

This started as a project for a company that wanted an ultra fast advertising server to use for their “ring of sites”. After the project finished, I kept thinking that the OpenSource community could benefit from a “Banner Exchange” service that is free, fast and reliable. So, I started hacking one in web2py running on Google App Engine (no, it has nothing to do with the previous one I’ve built) and after a couple of days (you can tell from the design) it is done.

I think that OpenSource projects, blogs, N.G.Os, forums etc, can benefit from a non-profit ring of sites that could help them increase their hits/clicks.

If you have an OpenSource project, blog, NGO, forum, portal, whatever that is free, you are more than welcome to join OpenShare!

Enjoy!

http://openshare.emotionull.com/

Comments (View)
Sat Jul 18

Using your mobile as a Bluetooth modem for Ubuntu (10 simple steps!)

I have free GPRS on my mobile and sometimes I just need my daily dose of Internet even when I am at places with no Internet connection (island / mountain). I know there are many good solutions but sadly many of them are missing some important stuff. So, here is my take:

1. Download bluez-passkey-gnome

$ sudo apt-get install bluez-passkey-gnome

2. Run bluetooth-applet (you’ll see why in the next step)

$ sudo bluetooth-applet &

3. Pair you mobile with your Ubuntu

There is no need to enable your Bluetooth on your phone (will be automatically enabled later) but is vital to make your phone visible (at least for the time being). Also, enable your bluetooth on your Ubuntu. If you don’t know how, google around. There are many guides (it’s reeealy easy and probably is already enabled along with your wireless connection).

Find the “Paired Devices” screen on your phone’s menu and select “New paired device” and select your Ubuntu. Then you’ll be asked for a password (put whatever you like). At the same time, a dialog will popup from your Ubuntu, asking for the same password. After that, congrats, your phone and your Ubuntu are paired :D

There is no need to create a pin file inside the bluetooth directory (in case you where reading other tutorials). Bluetooth-applet handles everything.

4. Search for your phone from Ubuntu

$ hcitool scan
Scanning …
xx:xx:xx:xx:xx:xx My phone

The xx:xx:xx:xx:xx:xx your phone’s “id”. Will use it at the next steps.

4. Find the correct channel for Dial-Up networking (usually is channel 2)

$ sdptool browser xx:xx:xx:xx:xx:xx

Search for the Dial-Up networking and then check the number of channel.

5. Modify the file: /etc/bluetooth/rfcomm.conf

rfcomm0 {
# # Automatically bind the device at startup
bind yes;
#
# # Bluetooth address of the device
device xx:xx:xx:xx:xx:xx;
#
# # RFCOMM channel for the connection
channel 2;
#
# # Description of the connection
comment “My phone”;
}

Add your mobile’s “id” and the channel and you are set.

6. Restart bluetooth services

$ sudo /etc/init.d/bluetooth restart

7. Connect to the phone

$ rfcomm connect 0

There is another way to connect to your phone (using the id) but as long as you’ve done step 5, you are set :D

If it works, you should see

Press CTRL-C for hangup

8. Connection settings

You need to put these files (search for your provider). The examples below are for Vodafone Greece (I couldn’t find it anywhere online). If you can’t find yours online, you can either call them OR check the setting from your mobile (Internet Settings, connections, something like that). You should see something like this:

Name of access point: wapkarta.vodafone.gr

Write that down. We are gonna need it.

Update: These setting usually a proxy for your browser. Google around for the proxy or a better access point.

Now,  create a file :

$ sudo nano /etc/ppp/peers/vodafone

and paste this (they might be different for your provider! Google around!)

# from www.hingston.demon.co.uk/mike/nokia6680.html 
noauth
#change this if you move the path to your connect script
connect "/usr/sbin/chat -v -f /etc/chatscripts/vodafone-connect"
#change this if you move the path to your disconnect script
disconnect "/usr/sbin/chat -v -f /etc/chatscripts/vodafone-disconnect"
#I found that I needed this to remove problems with loopback on connecting
silent
#remove this if you don't want lots of information going to /var/log/messages
debug
#this is the device specified in your rfcomm.conf file
/dev/rfcomm0
#speed at which to connect - might be worth trying higher...
115200
#this is needed so that a default route is added to your routing table
defaultroute
#this is needed so that you pick up Orange's DNS settings
usepeerdns

Next,

$ sudo nano /etc/chatscripts/vodafone-connect

and paste this BUT put your access point (again, this is for Vodafone Greece)

#from www.hingston.demon.co.uk/mike/nokia6680.html
TIMEOUT 5
ECHO ON
ABORT '\nBUSY\r'
ABORT '\nERROR\r'
ABORT '\nNO ANSWER\r'
ABORT '\nNO CARRIER\r'
ABORT '\nNO DIALTONE\r'
ABORT '\nRINGING\r\n\r\nRINGING\r'
'' \rAT
TIMEOUT 12

OK ATE1
#here's the magic bit!
#OK 'AT+cgdcont=1,"IP","wapkarta.vodafone.gr"'
# We found a better one that doesn't need a proxy and allows even ssh!
OK 'AT+cgdcont=1,"IP","webkarta.vodafone.gr"'
OK ATD*99***1#

and finally,

$ sudo nano /etc/chatscripts/vodafone-disconnect

# from www.hingston.demon.co.uk/mike/nokia6680.html
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
SAY "\nSending break to the modem\n"
"" "\K"
"" "\K"
"" "\K"
"" "+++ATH"
"" "+++ATH"
"" "+++ATH"
SAY "\nPDP context detached\n"

9. Let’s connect!

First, check if the connection to your mobile is still up (step 7). If you don’t see

Press CTRL-C for hangup

connect to your phone again.

Now, the big monent!

$ sudo pon vodafone

starts the connection and you are online!

$ sudo poff vodafone

bring the connection down :P

10. Troubleshooting

Check /var/log/messages for problem when “calling your phone”.

If everything goes well you should see:

Jul 17 22:46:33 trinity pppd[9401]: PAP authentication succeeded
Jul 17 22:46:35 trinity pppd[9401]: local  IP address 10.2.116.125
Jul 17 22:46:35 trinity pppd[9401]: remote IP address 10.4.4.4
Jul 17 22:46:35 trinity pppd[9401]: primary   DNS address 210.239.17.10
Jul 17 22:46:35 trinity pppd[9401]: secondary DNS address 210.239.17.11

PS: Forget SSH unless you are ready for some tunneling

Also check this (great tutorial which I borrowed MANY stuff) http://www.lynchconsulting.com.au/blog/index.cfm/2006/12/11/Nokia-N73-Bluetooth-modem-with-Ubuntu-Linux-Howto

Comments (View)
Tue Jun 30

Erlang Factory and RainUp Project - Phase I

All I can say is: I am AMAZED by the Erlang community! Sadly here in Greece there isn’t an active Erlang community (but if your are interested in starting one, give me tweet at jonromero) even though there are some crazy Erlang projects (tidier/HiPE/Dialyzer) and some crazy researchers/developers.

All the presentations were inspiring (and most of them uplifting) but what was very strange was the bonding of the community. Guys (and girls) with great knowledge about distributed systems, hacking and expertise in the their field, were easy not only to be approached but also give share thoughts, business directions and discuss about everything (ranging from new BEAM features to “I love summer in Greece”). And of course Joe Armstrong is not only a great scientist but a VERY funny, inspiring and open-hearted person. We had great discussions with him during Speaker’s dinner (where he was ecstatic about us trying to run thousand of nodes for our project) but also bought us some beers the last day where we chilling out after the conference. What a great guy!

O’Reilly was there with 35% discount with books for Clojure, Python, Ruby, Software architecture and of course the Erlang Programming and Programming Erlang (with signatures of Joe Armstrong, Francesco Cesarini and Simon Thompson).

After having a GREAT time at the Erlang Factory and meeting with a lot of interesting and fun-to-be around people, it’s time to continue working on RainUp. We’ve uploaded some info here and you can download our presentation slides here (soon the video will be available from the erlang-factory.com ).

For our first phase we need to find some really interesting problems to start working on, so if you have any interesting algorithms please send us an email at contact@rainup.org.

We have some servers to start working on but we are still interested in more computing power (there is along way to infinity), so if you have a datacenter to spare or money to help us fund the whole thing, send us an email at contact@rainup.org

Comments (View)
Thu Jun 11

A quick hack for random numbers in Erlang

It seems that you can’t get random numbers in Erlang when you are in different processes. I am building a distributed Monte Carlo simulation and I wanted two random numbers for the x and y (of the dart). So, the only way to do it (if you want it to run in a cluster) is this (at least that’s what I’ve found).

{Seed1, Seed2, Seed3} = erlang:now(),
X = random:uniform(),
random:seed(Seed1, Seed2, Seed3),
Y = random:uniform().

Any suggestions / better implementations?

Comments (View)
Fri Apr 10
Awesomeness : Looking at your own code after a couple of days and thinking: “f*ck, I wish I could code like that By me
Comments (View)