SaaS’s rottenpotatoes ruby-debug LoadError fix

rails

In two days Barkeley’s edx SaaS course is starting and I wanted to set up their rottenpotatoes RoR app on my machine without the VM they provided but I kept getting this error every time I tried to run “rails server” within the rottenpotatoes directory:

“/usr/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:1:in `require’: /usr/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so: undefined symbol: ruby_current_thread - /usr/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby_debug.so (LoadError)”

Knowing almost nothing about working with RoR it took me a while to figure out why exactly this wouldn’t work and how to fix it. I tried installing a few different versions of ruby-debug and whatnot but nothing helped. Finally, I found this answer on StackOverflow which let me to the right rail. :D Apparently, ruby-debug19 and ruby-debug-base19 gems haven’t been updated in some time (and won’t any time soon) which already caused headaches for many people around the world.

To fix this simply install debugger (“Debugger is a fork of ruby-debug called ‘debugger’ and it incorporates many of the fixes people had been deploying on top of ruby-debug19.”) gem using:

1
gem install debugger

after that edit the following line from “Gemfile” file from your rottenpotatoes directory:

1
gem 'ruby-debug19', :require => 'ruby-debug'

to:

1
gem 'debugger', :require => 'ruby-debug'

save the changes and run “rails server”. You should get this as the output:

1
2
3
4
5
6
7
=> Booting WEBrick
=> Rails 3.1.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2013-01-05 17:30:01] INFO WEBrick 1.3.1
[2013-01-05 17:30:01] INFO ruby 1.9.3 (2012-12-25) [i686-linux]
[2013-01-05 17:30:01] INFO WEBrick::HTTPServer#start: pid=3041 port=3000

and now you will be able to acces the rottenpotatoes app on http://localhost:3000/movies

Pyramid installation – “UnicodeDecodeError: ‘ascii’ codec can’t decode byte” error fix

Following pyramid framework installation notes I kept getting ‘ascii’ codec can’t decode byte error message. The whole error output looked like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
$ bin/easy_install pyramid
Searching for pyramid
Reading http://pypi.python.org/simple/pyramid/
Reading http://docs.pylonshq.com
Reading http://pylonsproject.org
Reading http://docs.pylonsproject.org
Best match: pyramid 1.4a4
Downloading http://pypi.python.org/packages/source/p/pyramid/pyramid-1.4a4.tar.gz#md5=0a5da1a25791764cdfefb15b2d55656a
Processing pyramid-1.4a4.tar.gz
Writing /tmp/easy_install-hrcuuc/pyramid-1.4a4/setup.cfg
Running pyramid-1.4a4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-hrcuuc/pyramid-1.4a4/egg-dist-tmp-kbuxa9
Traceback (most recent call last):
  File "bin/easy_install", line 9, in <module>
    load_entry_point('distribute==0.6.28', 'console_scripts', 'easy_install')()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 1929, in main
    with_ei_usage(lambda:
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 1910, in with_ei_usage
    return f()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 1933, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python3.3/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.3/distutils/dist.py", line 917, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 358, in run
    self.easy_install(spec, not self.no_deps)
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 598, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)                                                                                                                    
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 628, in install_item                                    
    dists = self.install_eggs(spec, download, tmpdir)                                                                                                                              
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 823, in install_eggs                                    
    return self.build_and_install(setup_script, setup_base)                                                                                                                        
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 1103, in build_and_install                              
    self.run_setup(setup_script, setup_base, args)                                                                                                                                  
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/easy_install.py", line 1089, in run_setup                                      
    run_setup(setup_script, args)                                                                                                                                                  
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/sandbox.py", line 31, in run_setup                                                    
    lambda: exec(compile(open(                                                                                                                                                      
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/sandbox.py", line 79, in run                                                          
    return func()                                                                                                                                                                  
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/sandbox.py", line 34, in <lambda>                                                      
    {'__file__':setup_script, '__name__':'__main__'})                                                                                                                              
  File "setup.py", line 122, in <module>                                                                                                                                            
  File "/usr/lib/python3.3/distutils/core.py", line 148, in setup                                                                                                                  
    dist.run_commands()                                                                                                                                                            
  File "/usr/lib/python3.3/distutils/dist.py", line 917, in run_commands                                                                                                            
    self.run_command(cmd)                                                                                                                                                          
  File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/bdist_egg.py", line 172, in run
    self.run_command("egg_info")
  File "/usr/lib/python3.3/distutils/cmd.py", line 313, in run_command
    self.distribution.run_command(command)
  File "/usr/lib/python3.3/distutils/dist.py", line 936, in run_command
    cmd_obj.run()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/egg_info.py", line 179, in run
    self.find_sources()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/egg_info.py", line 254, in find_sources
    mm.run()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/egg_info.py", line 308, in run
    self.add_defaults()
  File "/home/pootzko/env/lib/python3.3/site-packages/distribute-0.6.28-py3.3.egg/setuptools/command/egg_info.py", line 339, in add_defaults
    self.read_manifest()
  File "/usr/lib/python3.3/distutils/command/sdist.py", line 377, in read_manifest
    for line in manifest:
  File "/home/pootzko/env/lib/python3.3/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7896: ordinal not in range(128)

…aaaaand it kept driving me nuts for a couple of hours until it finally came to me that the problem lied my locale setup and not in python setuptools. Simply typing:

1
export LANG='en_US.UTF-8'

in terminal to change the encoding fixed the problem (keep in mind that this changed the locale temporarily only for the current session).

Hope it saved you some time. Cheers!

autokana – jQuery plugin

Autokana is a jQuery plugin that automatically converts latin (roumaji) to kana (hiragana / katakana) using the auto-correct principle (keep in mind that it’s not suitable for converting copy/pasted but only typed-in text). You can check out how it works at autokana example page.

You can also download the plugin (including a simple usage example) from github and use it for free.

To use it, you will have to add the following somewhere at the beginning of your body tag:

1
2
3
4
5
6
7
<script type="text/javascript">
   // bind events when document is ready
   $(document).ready(function() {
      // attach auto-kana plugin with default options
      $("#kana_text_box").autokana();
   });
</script>

After that add the input box itself wherever you need it (make sure to use the same ID in the above part and in the input field itself):

1
2
3
4
5
6
7
<input id="kana_text_box" type="text" />
<script type="text/javascript">
   // this part will clear and set focus on the input field on refresh
   // feel free to remove that part if you don't need it
   document.getElementById("kana_text_box").value="";
   document.getElementById("kana_text_box").focus();
</script>

If you have any suggestions or bug reports, feel free to leave a comment.

Mapping Japanese kana characters (hiragana/katakana) for use in programming

When I started working on Zanzou, I had to find a way to somehow map the whole kana so I could later use it in my webapp. I simply used 2D array to accomplish this. It’s no nuclear science but to save you the trouble of copying and pasting all the symbols into a single file yourself (I think it actually took me around an hour to do it :D), here is my kana.js file (note that if if you open the file itself in the browser, it will most probably display some strange characters instead of proper UTF-8 encoded kana symbols but when you open the file in your text editor, it should be usable and displayed just fine).

I divided it into 4 major groups (arrays): monographs, digraphs, monographs with diacritics and digraphs with diacritics. Each array element (representing sound) consists of 3 subelements (roumaji record, and hiragana and katakana symbols).

With some minor modifications, this could easily be used in any other programming language. Just make sure if you edit the file to save it in UTF-8.

Hope it helps, がんばって!

残像 – Zanzou

Zanzou is alive. =)

Zanzou an e-learning tool I made as my computer science master’s degree thesis project at the Faculty of electrical engineering, Osijek, Croatia. Its goal is to help people memorize kana using flashcards. Based on unsuccessful answering, Zanzou will repeat certain symbols more frequently and (depending on the chosen difficulty level) it will group and present some of the similar symbols together to make it harder to “guess the answer”. Global user success statistics are also available.

Features

  • memorize hiragana and katakana using flashcards
  • three difficulty levels
  • three types of exercises
    • kana to roumaji
    • roumaji to kana
    • voice to kana
  • customize your kana practice set
  • flashcard frequency based on correct answers
  • free

Thanks to

 

For any feedback or bug reports, feel free to contact me through email or just drop a comment bellow. =)

Nook Simple Touch “Reading Now” button goes to the first page of the book fix

This happened to me a few times now (each time after a new firmware update) and it’s actually quite an annoying bug. What happens is that if you go to home/library/settings/whatever screen and then want to go back to where you stopped reading a book by pressing “Reading Now” button in the upper left corner, it doesn’t take you to the right page but to the first page of that book and it also “ignores/forgets” your bookmarks (opening a book from the library screen goes to the right page and still remembers bookmarks correctly). In my case this happened with side-loaded books and stock firmware and here is what fixed it for me:

  1. Connect Nook to your PC with USB cable
  2. Delete everything from both the internal memory and the SD card
  3. Safely remove and disconnect the device
  4. Reboot your Nook
  5. Connect the device to your PC again
  6. Side-load your books again
  7. Safely remove and disconnect the device
  8. Everything should be working properly now

TP-Link WR703N OpenWrt post installation tips

In this post I’ll write down a few thigs I think are worth doing right after flashing your WR703N. The flashing itself is not covered in this post. For that, check out my How to flash TP-Link WR703N with OpenWrt post.

 

Setting up a static IP address

The first thing you should do is to assign a static IP address of your choice to your WR703N. There are three main reasons for doing this:

  1. Since your home router probably already uses 192.168.1.1, you will avoid having problems caused by conflicting IP addresses
  2. You will always know what the IP of your WR703N is and you will be able to connect to it from inside your network very fast
  3. Lastly, you will be able to make it work with DynDNS and port forwarding to connect to it from anywhere on the Internet

Connect your WR703N directly to your PC using ethernet cable, telnet to it (telnet 192.168.1.1) and then edit /etc/config/network (Vi editor comes installed with OpenWrt, so you can use that). For example, to set the IP to 192.168.1.100 (assuming your network uses 192.168.1.X range and your home router is at 192.168.1.1), your lan interface section should look like this (do not change/remove the loopback interface part):

1
2
3
4
5
6
7
8
config interface 'lan'
   option ifname 'eth0'
   option type 'bridge'
   option proto 'static'
   option ipaddr '192.168.1.100'
   option netmask '255.255.255.0'
   option gateway '192.168.1.1'
   option dns '192.168.1.1'

Now run this command:

1
/etc/init.d/network restart

And after that, feel free to disconnect the WR703N from your computer and connect it to your router/switch (you will be able to access it on the IP address that you just set up).

 

Enabling SSH / disabling telnet (setting up password)

Setting up the account password (using “passwd” command) will automatically disable telnet and enable Dropbear SSH daemon on port 22. Dropbear is an OpenSSH replacement designed for environments with low memory and processor resources (such as WR703N) and on OpenWrt it is installed by default instead of OpenSSH. You can easily replace Dropbear with OpenSSH if you want, but don’t do it before setting up extroot (see the next subsection) or else you will run out of free space.

 

Extroot – extending your memory with an external USB device

Extroot will allow you to use an external USB device to extend your internal memory which will enable you to install more packages onto your device (WR703N only has 4MB of flash memory which really isn’t much). Since this is a bit more tricky and it depends on which version of OpenWrt you have installed as well as on what kind of USB stick you have, I believe it is bettter for you to go to extroot wiki page and follow the steps provided there than for me to just copy all that stuff here.

 

Installing GNU Screen and Vim

GNU Screen will allow you to have multiple screens (you can view them as tabs or virtual terminals) so you won’t have to log in multiple times to have several terminals at once which is really, really handy. Vim is simply Vi improved. If you prefer another terminal editor (nano, joe..), go ahead and install that one.

1
2
opkg update
opkg install vim screen

If you’re not familiar with screen, here are some basics.

 

Installing the web interface

You might want to install the OpenWrt web interface - LuCI (you need to have extroot set up for this or you will run out of free space):

1
2
opkg update
opkg install luci

You will have to enable and start uhttpd daemon afterwards:

1
2
/etc/init.d/uhttpd enable
/etc/init.d/uhttpd start

Then you will be able to access the web interface by typing your WR703N’s IP into your browser’s URL bar.

 

Switching to Bash / setting up .bashrc

OpenWrt comes with Ash shell. If you would like to use Bash instead, here is how you can switch and add some nice colouring to it. Install Bash by issuing the following:

1
2
opkg update
opkg install bash

Then edit /etc/passwd and change the root user line to this:

1
root:x:0:0:root:/root:/bin/bash

After that, run this command (which will create /root/.bash_profile and put “. $HOME/.bashrc” in it):

1
echo ". $HOME/.bashrc" > /root/.bash_profile

Then you can either use your own .bashrc or download the one that I use (I got it from Arch wiki a few years ago) and put it in your root directory like this (if you would like to use your own .bashrc, make sure to put it in /root as well):

1
wget -P /root/ http://cmikavac.net/download/.bashrc

Now log out, and log in again and you should have a brand new prompt.

 

SSH public key authentication

To enable SSH public key authentication on Dropbear you will first have to copy your public key to your WR703N’s tmp directory by issuing the following command from your Linux machine (change YOUR_KEY with your actual public key file name, and WR703N_IP with the IP address of your device):

1
scp ~/.ssh/YOUR_KEY.pub root@WR703N_IP:/tmp

Then log in to your WR703N and copy your public key to authorized_keys file:

1
2
cat /tmp/YOUR_KEY.pub >> /etc/dropbear/authorized_keys
chmod 0600 authorized_keys

I couldn’t make make OpenSSH work with SSH public key authentication because apparently there is a bug in OpenWrt’s OpenSSH package (I read that somewhere on OpenWrt forums while I was trying to make it work some time ago, but I can’t find that post now… if I find it, I’ll put the link here).

If you don’t use SSH public key authentication already, go here and read why you should and how to use it.

For MS Windows users.

 

Using DynDNS / setting up port forwarding on your router

If your router supports DynDNS, or a similar service, you can make your WR703N accessible from anywhere on the internet (this is useful because you will be able to use your WR703N to tunnel your traffic to protect yourself while you are connected to an unsecured network somewhere). The explanation will be a bit more generic, but it will give you a rough idea on what you have to do to make it work:

  1. Register an account on DynDNS webpage
  2. Enter your DynDNS credentials into your router (find them somewhere in your router’s options)
  3. Forward a high TCP port (something above port 1024) to your WR703N (for example – if your WR703N is on 192.168.1.100, and Dropbear is running on port 22, then forward 8822 TCP to 192.168.1.100 port 22)

Now you should be able to SSH into your WR703N by issuing the following command inside your terminal:

1
ssh -p 8822 [email protected]

This might help you set up port forwarding on your router.

 

Reflashing

If you for any reason ever want/need to reflash your WR703N with a fresh instance of OpenWrt do the following (wget will download the latest snapshot of OpenWrt for WR703N, and mtd command will flash it to your device):

1
2
3
cd /tmp
wget http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin
mtd -r write openwrt-ar71xx-generic-tl-wr703n-v1-squashfs-factory.bin firmware

 

Other

OPKG Wiki 
OpenWrt WR703N Wiki
MiniPwner
PirateBox

 

Hope this helps. If you find out that something I wrote is wrong and is not working, please drop a comment bellow and I’ll fix it. Thanks. =)

How to flash TP-Link WR703N with OpenWrt?

  1. Go to OpenWrt WR703N wiki page and download the latest squashfs-factory.bin firmware (keep in mind that although this is what most people use – this is not the latest stable version, but the bleeding edge OpenWrt firmware snapshot from the trunk which work just fine in most cases (if you want the latest stable version get the latest stable version))
    edit: I have only been using the trunk version myself, and I’ve been told that there is no stable version for WR703N (yet) since it got supported some time after the latest stable release (Backfire 10.03.1)
  2. Connect the WR703N directly to your PC using ethernet cable (WR703N will use 192.168.1.1 by default so if you try to connect it to your router/switch instead, it will probably start causing problems since most home routers have the default IP of 192.168.1.1 and you will have two devices on your network with conflicting IP addresses)
  3. Set a static IP address on your PC (it must be in 192.168.1.X range, different from WR703n’s 192.168.1.1 and with 255.255.255.0 subnet mask)
  4. Go to http://192.168.1.1/ and log in using admin/admin credentials
  5. Now go to http://192.168.1.1/userRpm/SoftwareUpgradeRpm.htm (according to Gene Wood’s comment, after the 1.6 update you will not be able go to this link directly any more but instead you will have to navigate through the menu manually, he wrote down the correct menu navigation sequence on his wiki page so feel free to check it out).
  6. Click on the grey button on the right side of the empty box and upload the firmware *.bin file that you download earlier
  7. Flashing might take up to a few minutes so be patient and DO NOT turn the power off (that will probably brick your device). When it’s all done, the device will reboot automatically, the blue LED will be lit solid (no blinking) and you will be able to telnet to the device
  8. For further configuration, feel free to check my TP-Link WR703N OpenWrt post installation tips post =)

cmik.fm at build.last.fm + source at github

cmik.fm made it into build.last.fm a few days ago, and not only that, but last.fm team rewarded me with a jolly good one year of free last.fm subscription as well, yaaay! thanks last.fm!

I also decided to release the source-code for cmik.fm under GPL3 over at github for anyone interested (not that I see a good reason for anyone to look at it, but it just feels good to leave it out there). heh :D

Github “Permission denied (publickey).” fix

Over at github troubleshooting page, there is some info about this issue, but since I haven’t used this way of authentication (public key) previously it took me a while to figure out why exactly I kept getting this message and why I failed to establish a connection with github. The thing is, I generated an RSA key-pair with a name different from the default “id_rsa” and because of that the ssh-agent did not have the key in its cache (thus I could not authenticate).

To fix this, you can either use the default “id_rsa” for your key name (in which case it will be in ssh-agent’s cache automatically) or use “ssh-add your_key” command to add it to the cache.

If you did the same funky key-naming thing as I did, I hope this helps and takes away your headache! =D