Tuesday, February 24, 2015

J is for ... autojump!

Shell addon

At our last PYPTUG meeting, I was demoing Dshell. While at it I suggested using the j command. AKA, autojump:


On some linux distros, it is possible to install from the repo. On debian and derived systems (ie, ubuntu, mint etc), instructions to enable it after the install are in /usr/share/doc/autojump/README.Debian

Once installed and trained, you'll ask yourself how you've been able to live without it.

The j command itself is defined within a shell file. For example, for bash, you'll find this piece of code:

# default autojump command
j() {
if [[ ${1} == -* ]] && [[ ${1} != "--" ]]; then
autojump ${@}
output="$(autojump ${@})"
if [[ -d "${output}" ]]; then
echo -e "\\033[31m${output}\\033[0m"
cd "${output}"
echo "autojump: directory '${@}' not found"
echo "\n${output}\n"
echo "Try \`autojump --help\` for more information."

Although this part is all bash scripting, the actual autojump command is written in something else altogether.

Python powered

Autojump has been around for many years, to this day, few people actually are aware of it. In fact, as I typed j, a quick survey around the room confirmed my gut feel.
Python powered
I have blogged and tweeted about it before, but mostly in passing. Hopefully this post will bring a bit more exposure to this really useful tool.

And, do have a look at the python code ( https://github.com/joelthelion/autojump/blob/master/bin/autojump ). It has some interesting use of the lesser known SequenceMatcher class of the difflib module, and good use of lambdas. Oh, and yeah, it's pep8 formatted. Thank you.


Monday, February 23, 2015

DShell and cybersecurity - tonight

Check it out tonight:


I'll talk some about dshell, crypto and more (see Adam's main talk)

Tonight, Feb. 23rd 2015 at Wake Forest U in Winston Salem.


Saturday, February 14, 2015

Raspberry Pi 2 and RPi.GPIO...

Raspberry Pi 2

So, you just bought a new Raspberry Pi 2 Model B. The one with 4 cores and 1GB of RAM. You want to run some python code that uses RPi.GPIO. You have the January 2015 Raspbian. You should be good to go, right?


Let's revisit RPi.GPIO, the python module for interfacing with hardware on the Pi. Yes, it does come pre-installed. Latest Raspbian (January 2015) includes RPi.GPIO 0.5.9. But then, you try to run your script and it tells you

pi@raspberrypi ~ $ sudo python myscript.py
RuntimeError: This module can only be run on a Raspberry Pi!

Hmm, ok, whatever, this is a Raspberry Pi! So we will have to upgrade the RPi.GPIO python module. While at it, let's install the python dev, setuptools and pip:

pi@raspberrypi ~ $ sudo apt-get install python-dev python-setuptools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libexpat1-dev libssl-dev libssl-doc python-pkg-resources python2.7-dev
Suggested packages:
  python-distribute python-distribute-doc
The following NEW packages will be installed:
  libexpat1-dev libssl-dev libssl-doc python-dev python-pkg-resources
  python-setuptools python2.7-dev
0 upgraded, 7 newly installed, 0 to remove and 23 not upgraded.
Need to get 32.1 MB of archives.
After this operation, 43.5 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libexpat1-dev armhf 2.1.0-1+deb7u1 [210 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-dev all 2.7.3-4+deb7u1 [920 B]
Get:3 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libssl-dev armhf 1.0.1e-2+rvt+deb7u14 [1,505 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ wheezy/main libssl-doc all 1.0.1e-2+rvt+deb7u14 [1,206 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python2.7-dev armhf 2.7.3-6+deb7u2 [28.7 MB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-pkg-resources all 0.6.24-1 [63.6 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-setuptools all 0.6.24-1 [449 kB]
Fetched 32.1 MB in 2min 3s (260 kB/s)
Selecting previously unselected package libexpat1-dev.
(Reading database ... 88962 files and directories currently installed.)
Unpacking libexpat1-dev (from .../libexpat1-dev_2.1.0-1+deb7u1_armhf.deb) ...
Selecting previously unselected package libssl-dev.
Unpacking libssl-dev (from .../libssl-dev_1.0.1e-2+rvt+deb7u14_armhf.deb) ...
Selecting previously unselected package libssl-doc.
Unpacking libssl-doc (from .../libssl-doc_1.0.1e-2+rvt+deb7u14_all.deb) ...
Selecting previously unselected package python2.7-dev.
Unpacking python2.7-dev (from .../python2.7-dev_2.7.3-6+deb7u2_armhf.deb) ...
Selecting previously unselected package python-dev.
Unpacking python-dev (from .../python-dev_2.7.3-4+deb7u1_all.deb) ...
Selecting previously unselected package python-pkg-resources.
Unpacking python-pkg-resources (from .../python-pkg-resources_0.6.24-1_all.deb) ...
Selecting previously unselected package python-setuptools.
Unpacking python-setuptools (from .../python-setuptools_0.6.24-1_all.deb) ...
Processing triggers for man-db ...
Setting up libexpat1-dev (2.1.0-1+deb7u1) ...
Setting up libssl-dev (1.0.1e-2+rvt+deb7u14) ...
Setting up libssl-doc (1.0.1e-2+rvt+deb7u14) ...
Setting up python2.7-dev (2.7.3-6+deb7u2) ...
Setting up python-dev (2.7.3-4+deb7u1) ...
Setting up python-pkg-resources (0.6.24-1) ...
Setting up python-setuptools (0.6.24-1) ...

pi@raspberrypi ~ $ sudo easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 6.0.8
Downloading https://pypi.python.org/packages/source/p/pip/pip-6.0.8.tar.gz#md5=2332e6f97e75ded3bddde0ced01dbda3
Processing pip-6.0.8.tar.gz
Running pip-6.0.8/setup.py -q bdist_egg --dist-dir /tmp/easy_install-pPyrAv/pip-6.0.8/egg-dist-tmp-UwhkN5
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 6.0.8 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/pip-6.0.8-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip

pip install RPi.GPIO

Now, if we try to install RPi.GPIO, it'll complain that it is already installed. So we will have to use the --upgrade option:

pi@raspberrypi ~ $ sudo pip install RPi.GPIO
Requirement already satisfied (use --upgrade to upgrade): RPi.GPIO in /usr/lib/python2.7/dist-packages

Let's try --upgrade

pi@raspberrypi ~ $ sudo pip install --upgrade RPi.GPIO
Collecting RPi.GPIO from https://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.10.tar.gz#md5=f1c67de40bf99e0612d75538b06a2181
  Downloading RPi.GPIO-0.5.10.tar.gz
Installing collected packages: RPi.GPIO
  Found existing installation: RPi.GPIO 0.5.9
    DEPRECATION: Uninstalling a distutils installed project (RPi.GPIO) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
    Uninstalling RPi.GPIO-0.5.9:
      Successfully uninstalled RPi.GPIO-0.5.9
  Running setup.py install for RPi.GPIO
    building 'RPi.GPIO' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv7l-2.7/source/py_gpio.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/c_gpio.c -o build/temp.linux-armv7l-2.7/source/c_gpio.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/cpuinfo.c -o build/temp.linux-armv7l-2.7/source/cpuinfo.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/event_gpio.c -o build/temp.linux-armv7l-2.7/source/event_gpio.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/soft_pwm.c -o build/temp.linux-armv7l-2.7/source/soft_pwm.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/py_pwm.c -o build/temp.linux-armv7l-2.7/source/py_pwm.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/common.c -o build/temp.linux-armv7l-2.7/source/common.o
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c source/constants.c -o build/temp.linux-armv7l-2.7/source/constants.o
    gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-armv7l-2.7/source/py_gpio.o build/temp.linux-armv7l-2.7/source/c_gpio.o build/temp.linux-armv7l-2.7/source/cpuinfo.o build/temp.linux-armv7l-2.7/source/event_gpio.o build/temp.linux-armv7l-2.7/source/soft_pwm.o build/temp.linux-armv7l-2.7/source/py_pwm.o build/temp.linux-armv7l-2.7/source/common.o build/temp.linux-armv7l-2.7/source/constants.o -o build/lib.linux-armv7l-2.7/RPi/GPIO.so
Successfully installed RPi.GPIO-0.5.10
pi@raspberrypi ~ $ 

OK, we are now ready to get to work. 0.5.10 works with the Raspberry Pi 2 model B.


Friday, February 13, 2015

Remember the SmartiPi kickstarter?


Or perhaps not. So here's a video reminder

Post kickstarter

http://www.smarticase.com/ is taking pre orders, if you missed the original kickstarter campaign. I was a backer of the campaign, and I'm expecting mine real soon now.

If you are getting this to use with the Raspberry Pi camera module, check out this pdf:



SciPyCon Latin America - [Misiones - Argentina] [Mayo 2015]

Tercera Conferencia Anual Científica de Python 
Del 20 al 22 de Mayo en Misiones, Argentina.
Se encuentra abierto el llamado a propuesta de charlas y registraciones al evento.
Para más información consultar en: http://conf.scipyla.org/ 
Se agradece difusión. 

Sin duda, de interes para muchos de mi lectores.


Monday, February 9, 2015

Computadora Industrial Abierta Argentina (CIAA)

3DFutureTech.info: CIAA

Resumen: pre-venta sin fines de lucro de 1.000 unidades de la EDU-CIAA, a un precio final por unidad de $550 (pesos argentinos), con el objetivo ayudar a que más gente pueda acceder a esta plataforma.

Mas informacion:



Friday, February 6, 2015

Wednesday, February 4, 2015

Text editor (command line)

Raspberry pi text editor (command line)

Note: This is a translation of the Spanish version of my blog article I posted some years back

Before even mastering the command line, you will need to learn a way to edit text files from the command line. Be it to make configuration changes, or write a script (sequence of commands), you'll be a lot more productive if you learn how to use one.

Raspbian comes equipped with nano (easy to use when starting out) and vi (the standard - found on all *nix servers and desktops), but, there is something even better: vim (VI iMproved)

If you've never used vi before, might want to start with nano instead, or read a vi tutorial or even better, an interactive vim tutorial (highly recommended!!), and cheat sheet)

Normally, on Linux and modern Unix, vi is really vim, but on Raspbian, vi is vi. Let's change this:
fdion@raspberrypi ~ $ sudo apt-get install vim
There are a few things to add to .vimrc to make it better (in /home/user):

syntax on
filetype indent plugin on
set modeline

fdion@raspberrypi ~ $ pwd
fdion@raspberrypi ~ $ vi .vimrc
(type i for insert, type the above 3 lines, hit Escape and :wq)
fdion@raspberrypi ~ $ ls .vimrc
Excellent, now scripts and code (like Python) will look much better, easier to read in color:

fdion@raspberrypi ~ $ vi file.py 

There are a few lines you will want to use specifically for Python scripts:

The first line is always the "shebang" line:

#!/usr/bin/env python

Here, we tell the operating system shell executor to pass the script to the python interpreter. For other interpreters, just replace python with whichever interpreter will handle the script.

Another thing for a python script that I like to use, a docstring (description) for the script, between """ and """. 

The seventh line above (in the code example) is for vim itself for proper tabs as 4 spaces (you want that for aligning your Python code, and is a nice to have in general for shell scripting):

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

If you are dealing with utf-8 code (for example accents or special characters) then you need to define the following:

# vim: set fileencoding=utf-8


Tuesday, February 3, 2015

Revisiting "going in the wrong direction"

The original

At the beginning of 2013, I posted "Going in the wrong direction". I figured it would be a good time to revisit the theme. From 2012 to 2015, what does $35 buy you, and did we ever reach the predicted $20 / sub $20 computing units?

Sure, microcontrollers have come down in price. For example, an ARM based unit:

But what about computers with an OS?

 The follow up

It's on my new blog, talking a bit about the progression of inexpensive tech, thanks to Moore's law:

3D Future Tech - Moores law in action

Check it out!


Monday, February 2, 2015

Raspberry Pi 2

Maintenance mode

If you've tried to access the forum on raspberrypi.org today, you got: