Creating a chrome extension

A few days ago I found that I wanted to create a browser extension for fixing some things that annoyed me about Jira, so I started my Journey of learning how to do this for Chrome. I had in the past written an extension for Firefox and I am not sure if it is because I did it so long ago or because chrome system is more friendly, but I felt this time was a lot easier.

Setting up the environment

The step of setting up the environment is extremely easy. Chrome gives you a lot of flexibility to do things the way you like, so basically the first thing you need is a folder and a manifest.json file inside of it. Here is an example of one:

Read More

Creating user interfaces with android (Part 2 of 2)

This is part 2 of an introduction to creating user interfaces for Android.

Styling

If you come from a web development background, you probably find it ugly to define styles inline. Luckily as with HTML and CSS, you can define your styles in an external file. The syntax is completely different so it may take some time to get used to, but I think of it as assigning classes to the elements I want to style and then defining their styles.

To create a stylesheet we need to create an XML file in the res/values/ directory, it should look something like this:

1
2
3
4
5
6
7
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="FillWidth">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
    </style>
</resources>
Read More

Creating user interfaces with android (Part 1 of 2)

I am resuming my journey to learning Android development and for this article I will focus on the UI. On this post I will explain how to add labels, buttons and related elements so the user can interact with our app.

The way I see building UIs for Android is very similar to they way they are built for the web. You can do it in two ways: programmatically or declaratively. Programmatically means creating elements using Java code and declaratively means using XML files. If you are familiar with web development, this is analogous to how JavaScript and HTML interact. As on Web, the recommended way is to do it declaratively whenever possible since it is usually faster.

While designing a user interface for android it is important to keep in mind Android design guidelines to give the user a consistent experience among different apps.

Read More

Creating web applications with Node and Express

Express is a web framework which allows you to easily make web applications on node. I already wrote about writing a simple server with node, but this time I will focus more on the application structure.

Lets start by creating a folder for our app called app/ and put a file inside named package.json. This is a special file used to define node projects. You can find more information about it on node JSON documentation, in this example I’ll use just the basics:

1
2
3
4
5
6
7
8
{
  "name": "app",
  "description": "A simple sample app",
  "version": "0.0.1",
  "dependencies": {
    "express": "3.x"
  }
}

An important thing to mention is that this has to be a JSON file, so all the json attributes and values must be wrapped by double quotes (“). Most of the fields are just information about the project, but the dependencies attribute defines which packages my projects depends on. These packages will by default be downloaded from npmjs.com. We specified that we want the latest revision of version 3 of Express for our project.

Read More

Getting started with Raspberry Pi

I got my hands into a Raspberry Pi, so I thought it was time to start playing with it. My goal is to show the first steps to get your Pi running, so basically installing the OS in the SD card.

I am going to install Raspbian, which you can get from Raspberry Pi’s download page. I used the torrent option, which downloaded a zip file. After getting the zip file, extract it’s contents and keep it handy for later.

To verify which devices are mounted run:

1
df -h

Now insert your SD card in your computer and run the command again. The device that wasn’t there is your SD card. The output looks something like this:

1
/dev/sdb1  3.7G 4.0K  3.7G  1% /media/adrian/Pi

Now that we know the device, we need to unmount it:

1
umount /dev/sdb1
Read More

Writing JavaScript unit tests with venus.js

JavaScript used to be a language mainly for handling minor interactions or animations in the browser, but not anymore. Now you can see full applications built using JavaScript. Frameworks like backbone have brought architecture to the browser and you can even see JavaScript being used in the server with frameworks like node. As JavaScript becomes a language for building real applications, it becomes important to also adopt professional practices like having a way write and run unit tests.

Venus

Venus is a test runner that makes it very easy to run your tests and plug them into a CI system. Venus is written in JavaScript and runs on Node. It lets you choose which tools you want to use to organize your tests, write assertions or create mocks.

You can get more information about venus at venus’ website and you can get the code at github.

Read More

Getting started with Jenkins Continuous Integration

For those of you who don’t know, Jenkins is an application that allows you to create a Continuous Integration environment for your software projects. Most of the time it is used to periodically run test and build your project in an environment that should be similar to your production environment.

Installation

To install Jenkins on a Debian based system you only need to use:

1
sudo apt-get install jenkins

This command will install it and will automatically start it as a service. This service will be started automatically every time your system is restarted.

If you are using another OS you can download a war file from Jenkins main site and run it using:

1
java -jar jenkins.war

To see your instance of Jenkins running you can visit http://localhost:8080

Read More

Why and how is dust.js asynchronous

Today we had a discussion at work about which templating library we should use for our backbone applications. Since Dust is the library most teams in the company use, we thought it may be the direction we want to take. I have never used Dust, but some people in the room mentioned that the fact that it was asynchronous made it a little painful to do some tasks. It was very weird for me to hear that the rendering of templates happened asynchronously, mostly because I don’t know a way to make JS execute asynchronously other than using setTimeout. So I decided to dive into the code and figure out how they are doing it.

I started my journey by getting dust from github. The only file I really needed was dist/dust-full-0.3.0.js, so I got the file and built a simple example in an HTML file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html>
<head>
  <script src='dust-full-0.3.0.js'></script>
  <script>
    var compiled = dust.compile("Hello {name}!", "intro");
    dust.loadSource(compiled);
    dust.render("intro", {name: "Fred"}, function(err, out) {
      console.log(out);
    });
  </script>
</head>
<body>
</body>
</html>
Read More

JS Dependency Management

It is common for JavaScript applications to depend on libraries, or JavasScript files to depend on other files. The way we usually deal with this problem is by manually including the files we depend on on our document:

1
2
3
4
5
6
<script src="jquery.js"></script>
<script>
$(function() {
  // Do something
});
</script>

To deal with this problem some people came out with the Asynchronous Module Definition (AMD) API, which allows us to specify modules or files that our code depends on and have them automatically loaded for us. The API defines one global function require that allows you to define the dependencies of the module and it’s functionality. Something like this:

1
2
3
4
5
6
7
<script>
require(['jquery'], function($) {
  $(function() {
    // Do something
  });
});
</script>
Read More

Create MySQL users

I always forget the syntax to create a new mysql user, so I decided to write it in here for later reference. I am doing this from a mysql terminal, so first we need to login:

1
2
mysql -uroot -p
mysql>

And then we can:

1
2
CREATE USER 'username'@'domain' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database.table TO 'username'@'domain'

When issuing the GRANT command you can use wildcards like this:

1
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%'

And that is pretty much all there is to it.

Read More