Category Archives: Tech

LearnWith: Concept to Implementation – Docker Development Environment

In this installment of the LearnWith series I create a standalone development environment using Docker and invite you along on the journey of working through the process outlined here. I go from having a vague idea of what I need with very little prior Docker experience, to a working solution. Rather than be a tutorial on Docker, the focus of this article is on the method and reasoning behind getting to a solution. I do present a solution at the end containing all the notes and explanations gained from following the process. So if you’re here for that, this article is not all theory, I’ve got you covered too. Come LearnWith me.

NOTE: If you are here just for the solution, skip to The Implementation section.

Defining the Problem: The Why

I’ve been working on Project ︎◼︎◼︎◼︎◼︎◼︎’◼︎ ◼︎◼︎◼︎◼︎◼︎ for a while now. So far, it has a Front End which is a little baby skeleton of a website and a browser extension; both of which are supported by a data API. The website is a web server running NodeJS, while the API is made up of Elastic Search and another web server running Java.

For the next part of Project ◼︎◼︎◼︎◼︎◼︎’◼︎ ◼︎◼︎◼︎◼︎◼︎, I’m creating an Editing Suite to manage the source data the Front End needs to work. To support the Editing Suite I’ll need a web server, a queue, queue processors and an a second API composed of a web server and a database.

Getting to the problem… Imagine running the full system on your local machine; the Front End and the Editing Suite. A minimum of 8 processes would need to be running on the same machine. That’s a lot of starting and stopping of services and a lot of port management. I currently need half of that and I’ve already started losing track which exact processes are needed for specific parts to work.

This very close to an actual conversation I’ve had when doing an impromptu demo: “… and after the extension is installed you see a list…? Where’s the list?! Ahh, I forgot to start the web server. Refresh and…. hold on, forgot to start elastic search…? Refresh and …Ngggggllff!! I changed the port earlier… Restart and refresh… What’s wrong now…? I’ll show you another time….”.

As any system grows, there comes a point when you need spend time on managing the complexity to continue being efficient.

Fortunately that demo scenario I described was to an understanding fellow dev friend, so not a big deal. So far I’ve not had any significant problems dealing with the complexity. Doubling the number of processes, doubles the complexity of the system, which also doubles the points of failure. As any system grows, there comes a point when you need spend time on managing the complexity to continue being efficient.

Side note: For Devs that don’t have any love for project managers, managing complexity is a part of what they do. They manage the complexity of coordinating different types of people doing different things that are all part of something larger. It’s not easy by any means. Shout out to my PM friends!

To summarise and to state concisely why we’re fixing this problem and what the proposed solution should be working to fix:

  1. Working in the development environment of the app is becoming complex.
  2. Multiple services all use the same port sometimes causing clashes.
  3. Getting a service running is tedious and error prone.
  4. Managing different versions of software for each service is difficult on the local machine.
  5. Versions of software installed on the local machine may clash with software needed for other projects.

Additionally this is going to be used for development, so ideally the solution should not fundamentally change the development process too much.

Defining the Problem: The What

We just described what we don’t want. Let’s describe it in the positive, let’s describe what we do want:

  1. Different parts of the app (the Front End and the Editing Suite) can be run independently.
  2. Simplify the starting and stopping of services.
  3. Every process needed will start up if it’s needed for a service to function correctly.
  4. Each process can have it’s own software version.
  5. Changing a file locally must still change the file represented in the output.

We’ve described what an outline of the solution should look like. This where come up with different technologies and evaluate them based off of these criteria. In an ideal world you’d go with one that has the most merit. In the real world, your situation (money, time, politics, available skills) often guides your choice. I’ve done this before using Vagrant. This time, as the title suggests, I use Docker. For the sake of brevity, and because this isn’t an article on the pros and cons of Docker vs Vagrant, let’s assume an analysis has happened and we’ve verified Docker fills all 5 of the requirements above.

Service Architecture. (If I had a child they’d have drawn it like this. I don’t have a child, so I had to draw it like this myself.)

Referencing the diagram above, we’re getting to the details of the setup we need. A successful implementation would mean we need all the following running in docker containers:

  1. An instance of the Java Application
  2. An instance of MySQL
  3. An instance of RabbitMQ
  4. An instance of the Python Worker Application

Additionally the following constraints would need to be satisfied.

  1. The Java application must able to communicate with RabbitMQ.
  2. The Python application must be able to communicate with RabbitMQ.
  3. The Java Application must be able to communicate with MySQL.
  4. Altering the Java code on the local machine must alter the code running in the container.
  5. Altering the Python code on the local machine must alter the code running in the container.

Note on technologies chosen: The choice of technology to build your project in, is in some cases arbitrary. I chose MySQL because amongst other things, it’s free, open source, stable, and a relational database that matches the requirements of my data. I’ve worked with it before and it’s more than good enough to get the job done. There may be better a database but does it really matter? Everyone has a bias. A few of the biases/reasons I’ve heard are “I know how to do it this way”, “It just feels right”, “Google does it this way”, “We’ve always done it this way”, “I don’t trust other people’s code”, “It’s cheaper and easier to find developers”, “I was here first”. Some of those are valid, others not. The process should be: have some options, build consensus around one or more of the options, choose one, implement it.

I chose Java and Vertx because I wanted to broaden my skillset. I could have used PHP or NodeJS and the result would have be the same. If any juniors are reading this, if someone is telling you your programming language is inferior, they’re likely gate keeping. If you press those people, you’ll generally find in most cases they’ve barely used the technology they’re criticising. Some of the criticisms might be valid, take what they’re saying with a pinch of salt, get a second opinion and take that with a pinch of salt too.

I chose RabbitMQ quite frivolously. I’ve heard it mentioned and it’s the name I’m most familiar with when it comes to queues and queue processing – even though I’ve never used it. That and it’s also open source and free. I might find it can’t do what I need, I doubt it, but if that happens I’ll just swap out the message transfer part for something else.

As an aside: If you find value in using open source software, make an effort to support those communities. Where would the world be without them?

Python arguably has the best support for Natural Language Processing so I chose that for this specific worker. There may be other workers that work better in other languages. Though it might make sense to keep your stack as small as possible.

Ultimately everyone has a bias, I’m showing mine because this is meant to be an honest peak behind the curtains of software development. As I mentioned, your situation can dictate your solution. If I make a mistake on this project, no one will die. With that in mind, my approach is: give something some thought, do that something, maybe make a mistake, learn from it, improve, update the implementation.

Preparing for Implementation

We know what we need to do, but we know nothing about Docker. For us mortals that mostly deal with common problems, we’re usually not the first person to try and solve a problem. And even if we are, chances are someone has done some work on the subject before us and we can build on what they’ve done. Maybe someone has written about it, maybe there are some tutorials, some online courses. All of these things can help us get to where we need to be.

Think of learning the terminology of a technology in the same way you’d ask for directions in a country where you don’t speak the language. You will probably get there, but various misunderstandings might mean there will be a few wrong turns along the way.

The first thing with any new technology is to read it’s introduction. This will give us a brief understanding of what we’re dealing with and the terminology we need to speak about our solution. The terminology is important because it gives us a way of speaking to the wider community allowing them to be able to understand and help us. Think of learning the terminology of a technology in the same way you’d ask for directions in a country where you don’t speak the language. You will probably get there, but various misunderstandings might mean there will be a few wrong turns along the way.

Docker’s overview page seems the perfect place to get this good initial understanding. Get started with Docker looks like a good next step. And a quick browse of the menu shows a Develop With Docker section. This looks promising! The official website looks like it has all the information we need to get to a solution. I can’t stress how happy this makes me: All or most of the knowledge will come straight from the source; The methods used will be officially supported known ways of doing things; And people already versed in the technology will be more likely to follow the implementation. All good things!

Now to read through the links and run the tutorials posted above. Depending on the time I have available, it’s likely a few weeks will have passed before I get to the next section.

Completed the Readings

I’ve been trying to read during my lunch break and after work. 2 weeks have passed. It would have taken me longer but I’d already gone through 60% of the readings before starting this write up. Most of it was a refresh.

I’ve got lucky with some very good documentation. I’ve read the overview and completed the getting started tutorials. I have enough information to start! I’ve not read the develop with docker section. I’m probably missing a key piece of knowledge to solve the problem completely. So… enough information to start but not enough to finish. I prefer starting as soon as I can. Others may prefer to do more reading. In this case, I don’t to have worry about the piece of string issue because I have already defined the problem. As long as I have that goal in mind, the work I do will generally get me closer to a solution. I also know from the readings, that anything I’ll need to change won’t need significant effort or have significant repercussions.

As I mentioned previously, this isn’t meant to replace the well written tutorials on the web, rather an exploration of the method of reaching the solution. With that in mind, onto the implementation.

Onto the implementation!

The Implementation

Note: If you want to see a step by step evolution of how I got to the solution, take a look a the source code on github. Look through branches ‘Part 1’ through to ‘Part 7’ to see the incremental steps needed to arrive at this solution.

You’ll need to add two files to your project to get it to. A Dockerfile file to tell docker how to package up the code and how to prepare the environment the code needs to run in. And a docker-compose.yml file to tell docker what other services are needed for the app to run and how to run them.

The Dockerfile:

FROM openjdk:8u212-jdk
WORKDIR /app
COPY . /app
RUN ["./gradlew", "clean"]
EXPOSE 8888
CMD ["./gradlew", "run"]

Lets look at this line by line:

FROM openjdk:8u212-jdk
This tells Docker to base my image off of the official openjdk image. This means I will have a specific version of the Java OpenJDK installed before I even begin. Docker will try to find this image on the local machine. If it can’t it will try download it from the docker hub. There are loads of official images on the docker hub you can use in your app.

WORKDIR /app
This tell Docker that the commands following this one will be run in the container from the directory /app.

COPY . /app
This tell Docker to copy everything in the current directory (denoted by the dot) to the folder /app on the container.

RUN [“./gradlew”, “clean”]
This will tell Docker to run the java specific command ‘./gradlew clean‘ (from the previously set WORKDIR) – I run this to make sure the gradle wrapper is available on the container before packaging it.

EXPOSE 8888
The Java application runs on port 8888 and this tells Docker to allow access to the application from via this port.

CMD [“./gradlew”, “run”]
CMD is the command Docker uses to start up your application. In this case to start my Java application Docker will run “./gradlew run” from the WORKDIR

Docker will now know how to build your code into an image and have it be able to run on it’s own.

Next docker-compose.yml:

version: "3"
networks:
  java_to_db:
  java_to_queue:
services:
  java_app:
    build: .
    volumes:
      - './:/app'
    ports:
      - "4000:8888"
    depends_on:
      - mysql
    networks:
      - java_to_db
      - java_to_queue
  mysql:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
    networks:
      - java_to_db

If you’ve not seen yaml before, it’s a text file format where the number of space before the text has meaning. If something has more spaces than the line before it, that means it is relating to the line before it. So in the example java_app and mysql are sections that belong to services. Let’s continue line by line:

version: “3”
Tells docker what version of the docker file structure we are using. Different versions have different sections and capabilities.

networks:
This section defines the list of networks and lets Docker know how to set up these networks. A network is used to allow communication between services and the outside world. The lines below network ‘java_to_db:‘ and ‘java_to_queue:‘ tell Docker to set up two networks with the respective names.

services:
Under this section we put all the process we need to run. MySQL, python, Java, RabbitMQ would all be defined under this section.

java_app:
This is a name for the service. The name itself can be anything and has no specific meaning. However you may need to refer to it in your application so make it something meaningful.

build: .
This is tabbed into the java_app section meaning it’s a command for the java_app. This tells Docker to build run all the instruction in the Dockerfile in the current directory. (the one we defined above).

volumes:
We’ll do volumes and – ‘./:/app’ together. Volumes is part of java_app and volume usually means refers to data storage such as files. – ‘./:/app’ falls under volumes. So, with these two lines we’re defining the file storage for the java app. You might remember ./ and /app from the COPY command in the Dockerfile. The copy command copied the all the code at the time the command was run. If any changes have been made since the code is now out of date. – ‘./:/app’ is called a bind-mount and tells Docker that we want to have the current directory in place of the /app directory on the container. This means changes made in the local directory linked in the Docker container too.

ports:
Also part of java_app. This and the line below, – “4000:8888”, map port 4000 to port 8888. What this means is that by visiting port 4000 on the (virtual) hardware it runs on, Docker will make sure all data that transfers through 4000 to port 8888 on the container.

depends_on:
This section is used to determine the order in which to start the services. The line below depends_on tells us that the java_app should wait for the mysql service to be ready before it starts.

networks:
Sitting under ‘java_app‘ this tells Docker java_app needs to talk to everything in the java_to_db and everything in the java_to_queue networks. ‘java_app‘ won’t be able to communicate with anything anything else.

mysql:
This is the start of a new MySQL service. The service has the name mysql but could have been anything. I mentioned earlier has is important. In this case when trying to connect to MySQL from the Java App, we need use the service name, ‘mysql’, as the hostname.

image: mysql
This is tells docker to create a service using the official MySQL image.

Other than ‘networks‘, the rest of the commands in the mysql section setup mysql to run in a specific way, you can find more details on the official MySQL Docker image page.

And that’s it. We’re finished! That’s everything needed to a development environment running in Docker.

Reflecting on the Goal

Are we finished? Let’s look back at what we set out to do. Let’s look at what we have:

  • An instance of the Java Application
  • An instance of MySQL
  • The Java Application must be able to communicate with MySQL.
  • Altering the Java code on the local machine must alter the code running in the container.

And what we we still need:

  • An instance of RabbitMQ
  • An instance of the Python Worker Application
  • The Java application must able to communicate with RabbitMQ.
  • The Python application must be able to communicate with RabbitMQ.
  • Altering the Python code on the local machine must alter the code running in the container.

That looks like more than half of the original plan is still missing. How in any way is this finished?

The Business Answer: Priorities change constantly when working on a project. Things outside of your control often affect what you’re doing on the project. Perhaps something your boss asked for, perhaps something a competitor has done now means something very important yesterday, has had to be moved out of the way to make place for something else today. I purposefully put in an extra bit to show how a modular iterative approach to solving a problem can mean that even though we’ve only done a piece of the work, the solution in it’s current state still helps us move forward. If we come back to the solution later, we can pick up where we left off.

The Truth: I’m currently the only developer building the proof of concept for Project ◼︎◼︎◼︎◼︎◼︎’◼︎ ◼︎◼︎◼︎◼︎◼︎. It’s taken a long time for me to write this article. I’m doing all this while still having a full time job, so it’s taken maybe a month or more. On top of that, I’ve not allowing myself to continue with the code until I finish this documenting the solution. Having the solution means I am unblocked and I’m REALLY excited to get back to writing code again! Having said that, I feel like I have solved the whole problem conceptually. All the core concepts needed to add Python and RabbitMQ are already included in the solution. Adding them in will a copy and paste job with a little bit of reading to get the specifics of RabbitMQ. If there was another developer waiting on the full solution, I’d definitely have made sure it was complete.

Finally…

Don’t be discouraged if you get stuck. Take a break and come back to it later. While writing I had two moments where I got stuck and despondent. My internal thoughts were: “The solution isn’t doing what I want! I should quit!”, “Is Project ◼︎◼︎◼︎◼︎◼︎’◼︎ ◼︎◼︎◼︎◼︎◼︎ even worth doing?”, “If I can’t even do this small, how dare I write an article and to give others advice?”. Most people I’ve worked with think I’m a good software engineer. To be honest, I am happy with my skills and I do have my moments but I’ve never ever felt like “one of the best developers I’ve worked with“. If that person is right and I am a good developer, I say this to let you know if you’re feeling discouraged, just remember, we all feel that way sometimes, just keep at it.

That’s it! Thank you for reading. I hope you learned something with me and had fun doing it.

Move along – You can’t Like that here

According to this article the Facebook Like button has been one of the guiding forces of defining how we interact with content on the web today. To be honest I can’t remember what the article said but I thought it was a decent enough lead in, so I went with that. However what I said isn’t really such a bold claim if you take into account all the sites that already have the Like button somewhere on the page. I’m sitting here, trying to think of non-sterotypical hyperbole of how frequently the like button is used on the web as a way of avoiding doing any form of research on what I am writing about. The problem being, I am not really in the most verbally creative states of mind just yet… so lets just say it’s a lot… like really a lot… like over 12.

As much as I want to hate on Facebook, the idea of a Like button is a simple and intuitive concept, it’s difficult to see why it wouldn’t work. Without doing any research or caring about whether I am right or not, the Digg button existed long before the Like button. If things were different and Digg was a little more cautious with it’s version 4 overhaul and it’s users weren’t so whiny, we may have still been Digging stuff. I’d like to think that the Digg button was the precursor to the Like button. The concept is not new by any means, but being in the right place at the right time has seen a huge uptake of the like button.

As an aside I find the corporate Like culture quite weird. It’s used as a form of currency, Like me and you can have this download. Like me and you can enter this competition, you had to make a purchase previously. You have to like me before you can interact with me. What is that shit all about? Companies are collecting them, kind of like XBOX achievement points but for corporates – to see who has the biggest dick. I am not saying that is all it’s good for, as a content provider I can see how it may have value as a feedback system. But… I’m getting sidetracked.

The undeniable success of the Like button has spawned some Like clones. Google’s +1 is an obvious one, while Behance has the Appreciate This seal of approval at the bottom. There is also Flattr, but that’s different. It’s the put your money where you mouth is of Like buttons, the put up or shut up – there are direct real world consequences for clicking a Flattr button. That’s just three examples, I’m sure there are many others and I have no doubt many others will follow suit.

Hmmm... Do I Like this or is it Tits?

With everyone wanting to cut out their own little wordy real estate on the web, I was wondering why we can’t reuse. Will I be allowed to like stuff in a non Facebook way? They probably won’t, but why can’t Microsoft, Google or Apple let users Like stuff? I am not saying they would want to either but I sure would like to see someone try. What would happen? Litigation? Even if the button were branded differently so there was no confusion? I don’t know? A Nike Like or something? I mean, people were liking stuff long before the internet. Liking something has always been a natural form of expression. Why can’t we reuse it? Surely you can’t hold a monopoly on liking stuff?

Using this when referencing a member variable

Originally I wrote this whole article using the words “global scrote” instead of “global scope”. My intention was to include a picture of the world inside a scrotum. It was going to be hilarious. Then I had to switch it all back after I started searching for a picture of a scrotum that would be suitable to Photoshop the earth into. I just couldn’t any more. Urgh!

Anyhow, back in 1999 I started learning Object Orientation and Java. I learned that you used the keyword this to denote that you are talking about the class you are currently in. So you could have something like this:

public class bar{
    private Int abc;
    public function foo()
    {
        this.abc = 21;
    }

    public function foobar()
    {
        this.abc = 92;
        this.foo();
    }
 }

It made sense.

Recently I have been playing around with Adobe Flash and Java. I’ve noticed is that there’s no requirement to use the keyword this. I really want to say how this is wrong, and how the language designers have made a poor decision. I have no idea how I can say those things and be taken seriously. Taking into consideration the small fact that I have a total of maybe 6 months experience in both of those languages combined, I can’t help but feel the language designers have a bit more knowledge on the subject than I do. So it probably makes sense in the larger context.

Having said that, I have no idea why this was allowed. I think Java and code written OO in general have large increases in verbosity compared to non-OO. The verbosity allows for readability and maintainability.

Coming from a background where my professional coding has largely been PHP, where PHP allows for (but frowned upon) functions and variables to be defined in a global scope I have learned that you ALWAYS ALWAYS use this. You have no idea whose code you have inherited and you have no idea who will inherit your code. Using this does two things:

  1. In the case of the function, this.foo(), tells you that the code to be executed is the code defined in the function just in this class. No matter if someone defines a foo() in the global scope outside of the file and includes it into the local scope the function in the class will always be run.
  2. In the case of the variable, it says we are using the variable defined inside the class we are currently in.

In the case of point 2 above you may think: “ok… yeah so?”. Well take a look at the code below. This is an example of the code I have been seeing in the Java examples and tutorials:

public class bar extends kablah{
    private Int abc;
    public function foo()
    {
        abc = 21;
    }

    public function foobar()
    {
        abc = 92;
        foo();
    }
 }

That just seems confusing to me. Maybe it’s because I come from an environment where global scope was allowed (but frowned upon as the language and its developers matured). If I am looking at function foobar(), I think ok fuck where does this variable come from? What was it’s previous value, should that really get changed. Do I need to worry about it. Let me try find out. Then (in larger classes) you have to go searching to find out it’s a member variable. Same with the function foo(), I spend some mental energy thinking where is that function defined what does it do (this is even more of a problem if the functions don’t have descriptive names)?

Not entirely sure if I should stop here. Basically I answered myself. It is my PHP background that is causing confusion. With Java everything is an object, so if you started on Java and you see foo() you know that it refers to the current object. Where as if you come from maintaining really old PHP4 code as I have, you have seen some really horrible bugs from people using calling functions and variables defined in the global scope. “How the fuck has this variable changed it’s value?!!? This code isn’t even executing!!?!?”

It’s probably just a choice of style and makes no difference (I am not sure if this is always the case and there may be some special cases in more advanced or fringe OO techniques) but I think using this makes it implicit and adds to the readability. So, I’ve come to the conclusion that I will use this and attempt to incorporate what I have just learned into my frame of reference.

Edit: Turns out it does make a difference if you use this or not in java. Which is what I think Jon was trying to tell me in the comments. If you look the example code below

 

public class bar extends kablah{
    private Int abc;
    public function foo()
    {
        abc = 21;
        Object anObject = new Object();
        anObject.setSomething(new Asdf{
            public void barfunc(){
                foobar();
            }
        });
    }

    public function foobar()
    {
        abc = 92;
        foo();
    }
 }

In the anonymous inner class defined by new Asdf we call foobar(). If you invoked the function using this.foobar() it only looks for the class inside the anonymous inner class. If you don’t use ‘this’ the scope will start locally and then be expanded until the function is found.

Motorola Droid Bionic [pics] – Unlock Hidden Functionality

The Motorola Droid Bionic. The latest feature to be added to the Motorola Droid Bionic, the company’s new flagship smart phone, is the ability to fuck you in the ass. I know some of you may be thinking: “Finally! Smart phones have finally reached the pinnacle of human technology!” The truth is this is nothing new. This feature has been included in many of Motorola’s older products including the original Motorola Droid, the great-great-grandfather of Motorola Droid Bionic. It’s not common knowledge, but this feature can be unlocked on nearly all of Motorola’s mobile products, including the soon-to-be-released Motorola Droid Bionic.

The best part about accessing this functionality is that you don’t have to root your phone, you don’t have to download an app. It already comes standard with the phone and will DEFINITELY be included in the Motorola Droid Bionic.

You may be wondering how you can do this on your phone. Well, I was one of the first people to get hold of and become a proud owner of the original Motorola Droid. I’ve been really happy with it. I shouted its praises at anyone willing to listen. Imagine my joy in finding new abilities on an old piece of hardware that I already thought was amazing.

Anyways enough teasing. In then next few paragraphs I will explain to you how to unlock this functionality so that your own Motorola phone can fuck you in the ass. So without further ado:

Unlock the ability to get fucked in the ass with the Motorola Droid Bionic

Motorola Droid Bionic - The fuck machine

  • Step 1: Use your phone as normal.
  • Step 2: Wait for a fault that you yourself are unable to fix.
  • Step 3: Send it to the repair centre listed on Motorola’s own website.
  • Step 4: Hear nothing. Wait a week.
  • Step 5: Phone the customer centre. Listen to them tell you they have no idea where your phone is… even though it was tracked and you can see that someone has signed for it.
  • Step 6: Send a few emails, wait a week.
  • Step 7: They find your phone and email you to tell you they will send you a quote.
  • Step 8: Wait for the quote, receive nothing.
  • Step 9: Call them up. Get told you’ve already been sent a quote and they have been waiting on you all this time.

That’s it! You’ve been fucked in the ass. As you can see it comes standard with every Motorola phone.

The best part is the feature has lasting effect and with the last few steps probably being:

  • Step 10: Pay through you teeth for this shitty service.
  • Step 11: Maybe get your phone back.

SBE Ltd UK, the company behind Motorola’s customer service, is shit. LG uses them too as does T-Mobile. If you can, avoid these companies at all costs. This is NOT an isolated incident. Support is a big part of the product. If you don’t have good support, you don’t have a good product.

Fuck you, a lot.

Question Mark inside Angled Brackets in Java?

Edit: Thanks to Jon Ellis for some clarification.

Edit 2: Added more context to the code.

Edit 3: Thanks again to Jon for more clarification.

I came across something like this while following an android tutorial:

import android.widget.AdapterView.OnItemClickListener;

public class HelloLinear extends Activity
{
  public void onCreate(Bundle savedInstanceState)
  {
    ...
    gridview.setOnItemClickListener(
      new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
          Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
        }
      }
    );
  }
}

If you look at the line with the colours, what the hell does that mean?

A quick Google search led me to a tutorial on Generics in Java.  Turns out the question mark is called a wild card. I am not entirely sure on the full meaning of that line as my goal is to get just enough information to carry on with the tutorial. So having said that, what I think it is saying is: The onItemClick() takes as it’s first parameter a construct of AdapterView of an unspecified type. The collection can referenced using the variable name parent.

The reason I added more context because I kept staring at this code as there was something else that was not sitting correctly with me. Look at this my original understanding (because I was applying dynamic type rules from JavaScript) was It was a class definition (HelloLinear) containing a function definition, containing a function call which instantiates and maybe even possibly defines an OnItemClickListner class, which then defines a function.

Turns out I was way off. What is actually happening is we are defining a HelloLinear class which defines the onCreate() function which calls the gridview member function which takes as a parameter, I think, any object that implements the ALREADY defined OnItemClickListener interface (which I should have seen from the imports) which is required to implement the onItemClick function. I guess what I was struggling with is that I was not aware you could firstly, instantiate an interface… or secondly instantiate an interface AND define a function inline. Or was it you could instantiate interfaces and it’s the abstract class you can’t instantiate? Or is that just a java thing?

Turns out the new keyword is used slightly differently to what I am used to. The new keyword here is defining an “Anonymous Inner Class” that implements the OnItemClickListener interface.

What about the rest of us?

Update: Facebook and other third party measurement firms reports are in conflict with previous statistics and indicate that overall Facebook numbers are still growing. Three of the firms’ figures do indicate a decrease in the Facebook user base for at least two non-consecutive months. Rightly so, some are saying there is not enough information to call it a trend.

I attempted to quit Facebook the other day. I say attempted because Facebook does not actually let you delete your account. I just deactivates it. Meaning the data is all there. So when you come back in it’s as though you have never left. It’s as though the digital you has just been asleep and everything has carried on around you.

That’s not actually what I wanted to talk about but let me continue down this way for a bit longer. There are both good things and bad things about being in a digital coma. The good thing is that because my account was only deactivated I still have the opportunity to get information I have on there. For instance I had a few appointments sitting in Facebook that I had not yet put in my Google calendar. I logged in to diarise these before deactivating again. Technically I would not have been at that much of a disadvantage if my account was actually deleted, I could have called/emailed the person and I’d have it again. Facebook however, does make it easier. The bad thing is that I feel as a person I’d be much better off from not having a Facebook account at all. To me being slightly less connected feels like a breath of fresh crisp mountain air.

WHY YOU HERE? YOU LEFT US! WHO NEED WHO NOW MUTHAFUCKA!?

 

The other thing to consider is I am by trade, a WEB developer. I develop applications for the WEB. With Facebook being such a large part of the web, is it really plausible that I cannot have a Facebook account. Is it professionally irresponsible? Is it my professional duty as someone who enjoys what he does to have a Facebook account – Arguably to give myself a better reflection of what is happening on the web?

And with Facebook trying to cement itself in every facet of the web, with the bulk of the current web having nearly 5 Like buttons per page, Facebook orientated commenting and also a lot of newer sites using Facebook connect instead of having native registration.

So with the last sentence in the last paragraph, I’m very nearly on the topic of what I want to say. I heard of a new social music experience Turntable.fm today. It’s description was quite compelling so naturally I wanted to try it out. The thing is, I had to sign up using Facebook. This being the other major reason I have been reactivating and deactivating Facebook since I left. The two services I wanted to look at both required an active Facebook account.

This is a worrying trend for me. Well, “worrying” is the wrong word, it doesn’t fit my lifestyle. I understand that everything is better with friends. I also understand that especially in the case of social software you want to tap into Facebook. Your software is social and it’s a pre-built network ready to go, you would have to have a good reason NOT to use Facebook. The thing is I am an introvert and I think right now I want to be a digital introvert now too. I want to be off Facebook, I don’t want everyone knowing my business. And now especially with people losing interest in Facebook, services like this should, if it makes sense, at least cater for my lifestyle too… what ever that may be, native sign up or twitter integration.

Just as an aside to me not being on Facebook, keep in mind if you see me on Facebook in a year or a months time and want to bring up this post to call me a hypocrite, here is my reply: “Fuck you. I do what I want”

Humble Beginnings

I have been wanting to make a game for a very long time. It’s a very complex game, the game I have in mind. So instead of going for the gusto, I thought I would start small as as far as I was concerned, I’d not yet done any sort of game development. I have of course done the crappy Tetris clone and the 0.001% finished Bubble Bobble I did in Javascript. But I didn’t complete those so they do not count.

So I started doing some flash game development. ActionScript(3), Flash, Flex whatever you want to call it. I did some of that using a flash game library called flixel. I basically followed a tutorial with a few twists here and there.

This is the result: (No that is not an edge detection error. That is a “the flash movie does not fit into my column” error.

The control are Left Arrow, Right Arrow and Ctrl to shoot.

P.S Don’t try to get a rating higher than fancy mullet – there isn’t one as this is merely a test.

P.P.S Flash WordPress, the kimili plugin, swfobject and Chome are not playing nicely. It’s not embedding correctly in the chrome browser. I would fix it but I wanted to do something else today. I will fix it another time. For now though try a different browser.

Get Adobe Flash player

 

The funny thing is. The architecture I thought up when attempting Bubble Bobble is very similar to what is suggested implied by the flixel package.

Note: No spelling spelling or grammar checks were done. The message is what is important.

Internet Segregation

Since when has it been ok to Segregate the internet?

What you say? You’ve no idea what I am talking about? If you’re’nt* from the states, you may not know that internet segregation exists. It does though. If you don’t live in the states, try watching a Hulu clip or try watching something on Comedy Central. Under normal circumstances, you can’t! That’s called internet segregation. You may think, “Gerard, Lord of darkness, why does this matter, it’s one site.” True, but if you understand the true nature of the web, it’s all interlinked. This detracts from the whole web experience not only on hulu but digg and all sites that reference locked content. There are ways around this though. By using a proxy it can appear as though you are browsing from inside the United States, thus allowing you to watch the content. Hulu however have begun to shut down content for people using proxies even if they are for a valid reason. All this leads to is people finding other methods to watch the content, namely torrents. Pointless.

Hulu, its pretty gay.
Hulu, it's pointless.

Another example of internet segregation is this talk of Microsoft trying to buy the news from News Corp. My current belief is that Google currently hold an information monopoly on the world. Don’t believe me, check out Google Dashboard and just see how much they know about you. If you are anything like me, it’s a lot. So if you could ignore my paranoia about Google until the day I get to say, “I told you so”, you would see that I am all for removing the Google information monopoly. (Losing it to Microsoft, is another issue all together, but still). Assuming it’s the actual news and not the news brand that is more important. And assuming it’s possible to get the same news on the internet from more than a single source. With all this in mind is it a good idea to prevent content being viewed from a specific network. Even if somehow it did make sense, ultimately it would be pointless. All this will do is broaden the the market for something I thought previously useless, search engine aggregators.

These are just more examples of big business messing up the internet.

*you’re’nt: contraction for “you are not”… I totally just invented that

David Versus Google

I want to write a post, but I am horribly rushed. I feel I have something really important to say but not enough time to say it in. Instead, I will link to the articles I read which have angered me.

This one: http://www.boingboing.net/2009/11/20/britains-new-interne.html. This is rubbish. If it happens I will leave the UK. I promise you this. I don’t like petitions because I don’t believe they work but  go here to “help prevent” this: http://petitions.number10.gov.uk/dontdisconnectus/

The other post is this: http://gigaom.com/2009/11/22/should-web-page-speed-influence-google-pagerank/. This is bullshit… because I say so. The internet is currently a level playing field for everyone, big and small business alike. Are you going to skew it towards those with most cash? Are you Google? Recently I’ve become A LOT more untrusting of Google.

Ok, it’s true that one swallow does not make a summer, but these things seem to point to the trend that the internet is now going to become more of a corporately controlled entity? I hope I am wrong.

Edit: Also?! Why is my text justified? Justified text?! WTF? This also angers me.

Update: Ok. I removed the justified text. At least I feel like I have the power to change something.