Running simple web server on a folder

There are multiple web servers out there that allow you to do almost anything you can think of, but what I needed was to run a simple web server that would serve the files in a folder. Python allows you to do this very easily:

1
python -m SimpleHTTPServer
Read More

Command line task manager for Linux

I found this little gem because I wanted to see how my raspberry pi was handling one running process. You can use the top command to see the running processes:

1
top

You will probably have a bunch of zombie processes you don’t care about. To omit those use:

1
top -i
Read More

Writing unit test for Android with Easymock

I already wrote a post about how to create a test suite for Android, but while trying more complex tests I noticed that a lot of things are not as easy as I would have expected. Unit testing Java is different that unit testing JavaScript, but unit testing Android is even a little harder. The problem with Android is that a lot of things depend on the Activity life cycle and most of the methods have been made final so they are impossible to mock.

Alternatives

Easymock wasn’t my first alternative. My first choice was Robolectric because I heard a lot of people say good things about it, the problem is that it has very little documentation and most of it is specific for eclipse. They also have a sample project but I wasn’t able to make it work. I also tried Mockito but I wasn’t able to make it work with my project. The reason I chose Easymock is because it was really easy to make it work and it seems to have a lot of support and documentation.

Read More

Android emulator acceleration

The android emulator if used as it comes from the package is pretty slow, so it is good to know that there are ways to make it a little faster.

Graphics acceleration

To use this feature you need to have these versions installed:

  • Android SDK Tools, Revision 17 or higher
  • Android SDK Platform API 15, Revision 3 or higher

You can verify that you meet these requirements by launching the android app:

1
/path/to/android-sdk/tools/android
Read More

Introduction to Compass

Compass describes itself as an open source CSS authoring framework. For me, it is a tool that helps me organize my CSS and create sprites easily.

To install compass you need to have ruby on your system, which I trust you can do by yourself. Once you have ruby installed you need to use these commands:

1
2
gem update --system
gem install compass

Next you will want to create a compass project. Go to your project folder and use this command:

1
compass create <project-name>
Read More

Trasfering files via SSH

I sometimes need to transfer files from one computer to another using SSH and I always forget how to do it so I decided to write a short post as a reminder.

To copy a file from one computer to another we use the scp command, which is very easy to use:

1
scp file.txt <remote user>@<some domain or ip>:<remote path>

The cool thing is that you can copy from the remote computer to your local computer inverting the order:

1
scp <remote user>@<some domain or ip>:<remote path to file> /home/adrian/

Finally, if you want to copy a folder with all it’s content you need to add a -r flag.

Read More

Hooking your github project to Travis-CI

I have a little open source project that I am trying to slowly improve. One of the steps I’m taking to do this is to add some tests and code static analysis. If something is running correctly I don’t want regressions so I need to plug it to CI so it runs for every commit. A lot of people are using Travis so I decided to give it a try. The first steps can be found at Travis’ getting started page.

My project is a PHP project but it needs node to run grunt tasks so I was worried about not being able to specify two programming languages in the yml file. Luckily Travis includes a version of node on all VMs no matter what type of project you are using, so I could freely use npm and grunt:

1
2
3
4
5
language: php
php:
  - "5.4"
before_script: "npm install"
script: "./node_modules/grunt-cli/bin/grunt"

I also found that if you have a very specific requirement you can even use apt-get to download dependencies and then you will be able to use it as part of your task.

Read More

Android layouts and styles

I have been slowly working more with Android and as I go I find myself in the need to do more complex stuff. I have been recently working on the UI side and I have been asking friends who have more experience with Android to review my code and I learned that I was doing some things the wrong way.

I come from a web development background so while I was learning how to use Android layouts I was looking at ways to translate what you do in Android with what you would do in the web. In Android we have layout files which are written in XML and live in res/layout/. When I started I pictured these being my HTML files, which is not completely correct. For styling android apps we use another XML file that lives in res/values/, these I thought of as being my CSS files.

Read More

REST Services

The more I have been working on large scale projects the more I have seen the use of REST (Representational State Transfer) for almost everything. The basic concept of having an HTTP end point where you can make a request and get a JSON as a response is pretty easy to understand, but since I have never build a service from scratch I wanted to dig a little deeper into the architecture and requirements of this type of services.

Representational State Transfer

REST makes us think of our services as an interface to let the client know the current state of a resource. The state of our resource is saved somewhere in the server (Maybe in a database) and is modified or retrieved via HTTP verbs. For example, lets say we have a people table in a database and we want to know the current state of a specific person, we would do a GET request to this url:

1
http://service.url/people/1234

And we would get a response with the information that is currently stored in the database about the user with an id of 1234.

Read More

Unit testing Android Apps

I have written about unit testing in other posts so this time I will only focus on how to create a test suite and test cases for Android applications. Writing unit tests for Java is a little different than doing it for other languages like JavaScript because Java is not only a strongly typed language, but also is a lot less dynamic than JavaScript.

Creating a test suite

Good developers create tests for all their projects, and for Android there is an standard place where those tests live. Although you don’t really have to do this, it is recommended that you create a tests/ folder in the root of the Android project under test, at the same level as the src/ folder:

1
2
3
4
5
6
7
8
MyProject/
    AndroidManifest.xml
    src/
    ...
    tests/
        AndroidManifest.xml
        src/
        ...
Read More