Minecraft stronghold finder

18/02/2014

I wrote a simple app to triangulate Strongholds in Minecraft. Instead of wasting a bunch of Eyes of Ender trying to get to a Stronghold, you can just do a couple of throws and get a good estimate of its position.

You can check out the app or look at the source code

Python bindings for Ngspice

17/02/2014

I wrote a set of Python bindings for the Ngspice simulation engine. It’s meant to add the clarity and power of Python to electronics simulations. For instance, you can simulate a circuit while varying different parameters and produce highly customized plots of your results, while minimizing your exposure to SPICE syntax.

More details on the project page.

Build your own Wigner-Seitz cells

18/08/2013

I made templates you can print out to build the Wigner-Seitz cells for hexagonal, body-centered cubic and face-centered cubic crystals. Check out the ideal result:

hexagonal_thumb bcc_thumb fcc_thumb

And the actual result:

Hexagonal photoBCC photoFCC photo

You can print these out to build your own:

I used blender to model the cells in 3D and UV-unwrapped them into svg files. These I edited with inkscape to add the edge tabs.

Deploying Flask to Apache2 on Ubuntu 13.04

09/07/2013

I had some trouble deploying a Flask app with Apache2, so here’s a minimum working configuration.

Virtual environment setup

virtualenv appname
cd appname
source bin/activate
pip install flask
mkdir -p src/appname www
echo "site.addsitedir(os.path.join(base, 'src'))" >> bin/activate_this.py
echo "from .appname import *" > src/appname/__init__.py
cat > src/appname/appname.wsgi <<EOF
activate_this = '/path/to/virtualenv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

from appname import app as application
EOF
cat > src/appname/appname.py <<EOF
from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "Success?"

if __name__ == '__main__':
    app.run()
EOF

Virtual host configuration

<VirtualHost *:80>
    ServerName host.name
    ServerAlias www.host.name
    DocumentRoot /path/to/virtualenv/www
    <Directory /path/to/virtualenv/www>
        Order allow,deny
        Allow from all
    </Directory>
    WSGIScriptAlias /connote /path/to/virtualenv/src/connote/connote.wsgi
    WSGIDaemonProcess host.name processes=2 threads=15
    WSGIProcessGroup host.name
    <Directory /path/to/virtualenv/src/connote>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /path/to/virtualenv/var/error.log
    LogLevel debug
</VirtualHost>

Ising model simulations

26/06/2013

I’ve been playing around with Monte Carlo simulations of the Ising model. The idea is that you have a grid of dipoles (think bar magnets) which interact with their neighbours. They can point up or down, and they feel a force from their neighbours which tends to make them parallel. However, there’s also random thermal motion which flips them randomly.

Depending on the ratio of interaction energy to thermal energy, different behaviors emerge from the lattice. The most interesting one is that below the critical temperature, the lattice spontaneously magnetizes, meaning there’s an imbalance between up and down. This models what happens in ferromagnets, which can retain magnetization if they are below the Curie temperature.

Here is the simulation code and a pretty video.

Android RenderScript: Solution to ‘Cannot find symbol’ forEach_root

17/06/2013

I’ve been playing around with RenderScript and found a problem only referenced in this StackOverflow question. Unfortunately, my solution brings another problem with it because it makes the app incompatible with my cellphone.

Ubuntu ARM toolchain compiles Stellaris USB examples correctly

22/12/2012

I managed to get the StellarisWare libraries and examples working without Sourcery Codebench. Based on these two articles:

The complete StellarisWare suite compiles without errors, and the examples I tried (including usb_dev_serial and usb_dev_mouse) work correctly. This is an improvement over summon-arm-toolchain, which compiled non-functional USB examples.

Instructions for Ubuntu 12.10:

  1. # Install toolchain
    sudo aptitude install gcc-arm-linux-gnueabi
    # Download and compile newlib (had trouble with the toolchain's libc and libm)
    wget ftp://sources.redhat.com/pub/newlib/newlib-1.18.0.tar.gz
    tar xzf newlib-1.18.0.tar.gz
    cd newlib-1.18.0/
    ./configure --target arm-linux-gnueabi --disable-newlib-supplied-syscalls
    make

    This makes the files libc.a and libm.a in the subdirectory arm-linux-gnueabi/newlib

  2. Unzip the StellarisWare files, and in the root directory edit makedefs. Search for the following settings and change them, replacing something with the directory where you unzipped newlib
    PREFIX=arm-linux-gnueabi
    LIBC=/something/newlib-1.18.0/arm-linux-gnueabi/newlib/libc.a
    LIBM=/something/newlib-1.18.0/arm-linux-gnueabi/newlib/libm.a

    Also change CFLAGS, adding the line with -fno-stack-protector, so it looks like this:

    CFLAGS=-mthumb             \
           ${CPU}              \
           ${FPU}              \
           -Os                 \
           -ffunction-sections \
           -fdata-sections     \
           -MD                 \
           -std=c99            \
           -Wall               \
           -pedantic           \
           -DPART_${PART}      \
           -fno-stack-protector \
           -c
  3. To compile everything, run make clean and make

USB Mouse example for Stellaris Launchpad

10/12/2012

With some help I got the USB Mouse example from the LM3S9D90 board working on the Stellaris Launchpad. It needed a few changes:

  • Replaced the linker script usb_dev_mouse.ld with one from the Launchpad examples. The only difference was the size and location of the FLASH and SRAM memory regions.
  • Added code to configure the USB pins at startup, as suggested by dellwoodbu.
  • Changed several lines in the Makefile:
    • PART=LM4F120H5QR
    • VARIANT=cm4f
    • Set ROOT to my StellarisWare directory as usual
    • Added a target for programming the board:
      .PHONY: download

      download: ${COMPILER}/usb_dev_mouse.bin
          lm4flash -v $<

    • Replaced all instances of “cm3″ with “cm4f”
    • CFLAGSgcc=-DTARGET_IS_BLIZZARD_RA2

You can download the example project files. Remember to set ROOT in the Makefile to your StellarisWare directory.

Warning: it does not work when compiled with the Summon Arm Toolchain. It compiles without errors but the device fails to enumerate. It responds to descriptor requests with malformed USB packets (seen with Wireshark). Works fine if compiled with Sourcery Codebench, haven’t tried other toolchains.

15/11/2012

My Stellaris Launchpad finally arrived. I’ve been following this tutorial for programming it on Linux successfully.

However, I was annoyed at having to run the flashing utility as root. So I created a udev rule that gives the board’s device file the proper permissions. First, create a group called stellaris and add yourself to that group:
sudo addgroup stellaris
sudo adduser $USER stellaris

Then create the udev rule. Create the file /etc/udev/rules.d/45-stellaris.rules with the following contents:
ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00fd", MODE="0664", GROUP="stellaris"
What does this mean? This line consists of key-value pairs separated by commas.

  1. The first two are match keys: when something is plugged in, udev checks if its vendor and product IDs match the ones here.
  2. The last two are assignment keys: if there’s a match, the device file is created with the specified permissions and group. These permissions mean that the owner (root) and members of the the group stellaris can read from and write to the file, while others can only read.

You might have to restart your terminal in order for it to recognize you’re now in the stellaris group. You can also run
exec su -l $USER

Collaborative latex editing with Dropbox and inotifywait

10/11/2012

I’ve settled on this workflow for writing lab reports in a group:

  • We share a folder with Dropbox that holds the measurements and report files (graphs, latex source files).
  • To prevent collisions we use separate .tex files for different sections, and split the sections between group members.
  • To make sure the output is consistent, only one person compiles the PDF. Inspired by this blog post I wrote a short script to build the PDF whenever a file changes:
#!/bin/bash

while true
do
    echo Compiling
    pdflatex -interaction nonstopmode -file-line-error informe.tex &>salida.log
    inotifywait -e modify -r .
done

Previously I’d tried running

make

in a loop (it only compiles if one of the input files changed). However, this script automatically checks all files for changes, without having to add them to a Makefile.


Seguir

Recibe cada nueva publicación en tu buzón de correo electrónico.