If You Do This, I Hate You

I know you’re trying to do MVC architecture, but you’re doing it wrong and it’s entirely unmaintainable. Longer rant later, possibly.

<td style="padding:0 5px 5px 0;">
 <input name="Gas" type="radio" id="Gas" value="0"  <?=(isset($PropertyDetail->Gas) && $PropertyDetail->Gas=="0")?"checked="checked"":""?> onclick="jQuery('#DivGasContainer').css('display','none');" checked/>No
 <input name="Gas" type="radio" id="Gas" value="1" <?=(isset($PropertyDetail->Gas) && $PropertyDetail->Gas=="1")?"checked="checked"":""?> onclick="jQuery('#DivGasContainer').css('display','block');"/>Yes
</td>

How to set up a remote Git server

I’ve been using github for a while now, which is fine for my public projects. There are obviously some that I want kept private though. I could pay for a github account, or I could make use of the VPS I’m already paying for and install git on there.

I was going to blog about this process from the start, but then I found a really decent article by Bradley Wright describing exactly what I wanted and figured I’d be wasting my time. I’ve run into a few problems though that the article didn’t seem to come across.

As I said, first I used Wright’s article, How to set up your own private Git server on Linux. I did pretty much everything on there, and everything worked brilliantly.

I came back to my local machine and added the remote host

git remote add vps git@shamess.info:~git/todoapp.git

Here’s where I ran into another problem when I tried to push to it.

fatal: The remote end hung up unexpectedly

That took an embarrassingly long time time to realise that I had just forgotten to fire up Pageant – this error just means that you couldn’t be authorised, so the server booted you off. This made me happy because it meant that my repos are private by default, I guess.

Even using the git:// url (which apparently only has read access), I still get an error. I’m not entirely sure this is expected, but if not it’s broken in my favour since I’ll only be accessing via ssh.

Back to my first push attempt though. After starting up Pageant I still ran into an error trying to push.

fatal: 'git/todoapp.git': unable to chdir or not a git archive
fatal: The remote end hung up unexpectedly

This took a little longer to track down, but I eventually found that it was an issue with the path I was giving it. This actually has nothing to do with git, and was just that I was giving SSH a bad URL to head to.

SSH doesn’t follow relative URLs when it’s connecting, and so you need to list the full path. I went with git remote add vps git@shamess.info:/home/git/todoapp.git, however I think just git remote add vps git@shamess.info:todoapp.git would have sufficed (since SSH would login at the git user’s home directory anyway).

That has me pretty much set up now! I hope someone finds this post once they fall into the same problems as I did, and find my resources helpful.

Playing with Java sockets and streams

I’m playing around with sockets and streams in Java in an attempt to get a conversation going between the client (my laptop) and the server (shamess.info). I decided to come here and talk about what I’m doing, because I’m a little confused and maybe having it written down will clear that up.

I have most the bones set up from the server side sockets tutorial on the Oracle site, and that works fine. The problem is though that that’s just entering data using System.in and sending it, which is fairly useless.

Since it’s in a while(true) loop I can’t do anything out of that loop – I can’t make GUI or handle anything at all that can’t be done inside that loop (which is run continuously).

So I figured I’d look into threading, which turns out to be pretty integral to Java programming (or just programming in general, I expect). That’s a new thing for me coming from a procedural language.

I figured I need three loops:

  • reading from the server
  • sending to the server
  • creating UI

One for creating UI is apparently just good practice (Event Dispatch Thread).

That’s worrying though because it means that “conversations” would be asynchronous. But that could work fine by just adding a reference ID to each message sent.

client: [10001] what's the user's current map coordinates?
client: [10002] what's the user's inventory?
client: [10003] what's the user's health?
server: [10002] two health packs, and a mana potion
server: [10001] 10,2
client: [10004] use a mana potion
server: [10003] 22
server: [10004] done

Giving each query or command a ticket, and returning with it, would make sure both sides always know what we’re talking about regardless of the order things get sent back.

Lets get that working for now then. Bbiab.

Why I think everything is lame

I’ve always been self motivated, until recently. The past few months I’ve found it hard to get out of bed each morning, hard to concentrate on work, and generally feeling low about life. Sitting on the toilet a few minutes ago, I think I’ve realised why.

In high school I had getting into college to look forwards too, and to aim for. When I got to college I had a motivating drive to do well to get into university. Even whilst at uni I knew I had to do well to impress employers for my placement year.

Now I’m on my placement year, which is pretty secure, I have nothing to aim for. I’ve no idea what type of job I want when I graduate; in fact I’d say I’m even less sure now that I’ve had a taste of full time programming. (Not that I don’t love it, I just don’t love 35 hours a week of it exclusively.)

And so I have nothing to aim for. No motivation force to get me out of bed and think “I’m one more day closer to achieving.”

The reason people get addicted to gaming, especially MMOs, is that when you successfully complete something you get a little burst of endorphins rewarding you. At work I have a pretty massive project with eight hundred features still to add, and very little time to do them all. When there’s the stress of “okay, I’ve done that, but I’ve still so many other things to do. I’m so far behind…” you don’t get those endorphins. In MMOs long quest chains where you don’t get the award till hours into the game you become bored of the chain, and usually abandon it. It’s just not productive.

I guess I just need to figure out something to live for. Hopefully I’ll think of that soon…

My productivity app

I have a pretty quick moving brain and often start ideas and have trouble finishing them off or focusing on them long enough to figure out a solution to certain things. I often quickly jump to a solution to a logic problem and rule out other potential solutions, but get distracted quickly. That’s not really a problem at work because I have a notepad right next to me which I jot things down in; that forces me to focus on completing the sentence I’m writing, and somehow having it physically written down makes it feel more important that I keep thinking about it.

The notepad worked fine when I was at work, but I increasingly do work at home away from the pad. That often stops me in my tracks because I probably won’t be able to come up with that really smart idea to get around a problem again as neatly as I did on paper. So I decided I’d endeavour to port all the functionality of my notepad (which I just wrote notes in) on a cloud-stored web app.

I ended up coming up with my “todo” app. It has ridiculously simple features like making a todo item and marking it as done, and adding some text to the todo item. That’s actually still the functionality of the website. There’s really not much else going on, and I quite like it like that. It’s really simple.

I was heavily inspired by Fever on the design. I can’t design to save my life, so why try and mess up horribly when Fever does such a clean interface. Still though, the UI is what I’ve spent most of my time on.

I really wanted everything to stay on the screen, and avoid scrolling where ever I could. The only reason I decided on that was because we learn by adding arbitrary constraints. For instance, I never would have learnt a fair few quirks with IE and document height. (The document height is based on the lowest element on the Y axis in IE, regardless of viewport size. Whereas other browsers set the viewport size as the minimum document height.)

I also learnt a lot about jquery selectors whilst trying to do the pagination of todo items.

I’m planning on adding features I need, and not what people are requesting. Though, if people are requesting a feature I need, I’m more likely to put it to the top of the list. I want to work on grouped items at the moment though, so my employer can add tasks of his own to my list.

Debugging a blank PHP page

I’m writing this post because I’ve had this problem three times in the past two weeks. Each time it’s soaked up more hours of my life than it should.

The problem is that you load you script and nothing is output. Not even an error to tell you where you’ve gone wrong. This must be a PHP bug, but I guess we’ll just have to live with it for now, and try debug around it.

The weird thing is the error that’s causing the page to be blank might not even be a fatal error. Twice for me it was just a warning, which should definitely not halt the processing of the script.

Without a line number or even which include the error is on it’s pretty hard to find out what the problem is to start fixing it.

Ultimately what I end up doing each time is echoing a string, and on the next line exiting. Put this right after the opening <?php on the first line.

echo "got to here.";
exit;

You should see the string output now. If you don’t it indicates that the hidden error is a fatal error, which will probably mean something to do with the syntax of your code, not the logic an undefined method or some such.

To fix that just carefully look through your code. If you don’t see any obvious problems then unindent everything. Now start indenting again if-by-if (or while-by-while, for-by-for, etc). Hopefully before the end of the file you’ll notice that you’ve had to indent twice, or you have left over braces. Delete or add as appropriate.

If you did see the “got to here.” text though, you can start moving those two lines down line by line. When you stop seeing the text you know the line above is the problem line. If you’re unfortunate enough to get to an include and it stops outputting, you’ll have to go through that too.

Once you’ve found the problem line, start debugging the relevant variables. You’ll likely find the problem there. (90% of all programming errors are variable related.)

Work

For almost two months now I’ve been working as an actual full time, professional web developer (Lead System Developer, actually). I’ve started my placement year with BEA Solutions, which is effectively my first full time job.

From a student freelancer’s probably ten hour a week schedule, my life is now 35 hours at least a week spent at work. That’s a bit of a culture shock. Concentrating for seven hours a day with a twenty minute break (which I rarely leave my seat for) isn’t something I’ve done for years – in fact even in school it was only six hours with an hour and half break. Not only concentrating for so long, but sometimes on one single thing for hours at a time. If nothing, it sometimes gets dull.

It’s also hard to avoid distractions. Facebook is only one “control+t fb” away since I’m usually working in a browser. Its far too easy to lose five minutes each time the impulse arises. Usually I can catch myself before I do it and think “just work another forty minutes and then you can check”, but it’s just muscle memory and habit now.

Also, there’s now people around me as I work. Before, when freelancing, I could just go to the library, or lock myself up in my room, mostly isolated. But now there’s Andrew and Marc sitting right opposite me starting a conversation is all too easy. And not just conversations either, they have weird quirks that are just distracting.

I suppose these are the types of things that you have to get used to when you become a worker bee.

My main project at the moment is a customer control panel that we sell to businesses to help them manage their customers, e-commerce, websites, and maybe telephony soon. I’m rewriting the current system to make it a little more robust and modifiable.

To give it that flexibility, I’ve made sure it focuses object orientated design which is actually really nice. It has a whole different feel to procedural PHP I’ve done in the past, and so feels less samey. I’ve never really had to seriously make sure that my code is easy to understand before either. My stuff has always been legible, but sometimes a little too sprawled out to understand quickly. Now working in a business where I’ll be leaving in a year and someone else will take over my job, I need to make sure that everything I write is clear and well commented. It’s actually nice to see really well formatted documentation for methods (I’m using javadoc notation).

As interesting as working on the control panel is, if all you do is eat pizza – as interesting as it is – you quickly get bored of it. Fortunately there always seems to be some other little thing I can be getting on with after getting bored and needing a break from it. I don’t see myself not having any work to do in the future.

Talking to customers over the phone was definitely something I was not looking forwards to. If my northern accent wasn’t bad another around these parts, I just naturally speak fast anyway. I was worried for no reason though, really. I’ve not had problems at all in that area, other than the odd bit of nervousness. I’m still a little bit under confident in what I’m supposed to be saying sometimes though, or at least worried that someone will phone with a question I can’t answer as tactically as Andrew or Marc can. That’s to be expected though; they’ve been doing this much longer than two months.

Overall the work part of my life is going fairly well, and I’m quite happy with it.

Soggy homecoming

It’s too hot to sleep, and since I have an awful memory, maybe I should start documenting my life more thoroughly. If nothing than for me to look back in a year and think “gosh, I really had an easy life back then; I wish I knew it”.

I have a boyfriend these days. It’s going pretty well, other than the occasional worried “do I really want to be with someone who I will barely get to see?” thoughts. After all, Jacob’s from Redditch which is two train rides and about two hours away from Leicester. When I’m in Portsmouth it’ll be about £40 and five hour train journey. Irck.

Fortunately though I’ve become a pretty solitary guy, and having someone around me full time is just exhausting. Once in a while is more than enough really. I’m not sure he’ll be able to handle it as much though. We’ll figure something out.

I just got back from his to find that my bed room window was left open and so my room was flooded; the mattress is soaked, and the floor is too. A part of the window sill below is really damp, and likely to just fall away at any time. Hopefully it’ll all dry up before I leave though, and I won’t lose any of my deposit. I don’t blame them if they decide to dock me any though.

Products I can’t live without

Last year I did a post on products I can’t live without with the intention of doing the same this year and comparing. I totally forgot about it until now.

Lets just go through last years list and see how it matches up.

digg.com – gosh. I can’t believe how much I actually loved that site. I use Reddit now, and would never dream of going back to digg.

WordPress – Meh. I don’t use it so much these days. It’s still something I use (obviously), but more and more rarely.

Google Talk – It’s only my Android, and people talk to me sometimes on there, but I don’t use it these days. Back into MSN!

Youtube – I use this more these days, thanks to 4oD being on there.

last.fm – I still store my plays on there, but I use Spotify to listen to music now.

4chan – What the hell? Not been there in years.

Google Reader – I’m using Fever now!

Google Notebook – this got retired. I mostly just use actual physical notebooks now. If there’s a link I want to jot down, I bitly it first.

Almost everything has changed then really. I didn’t think my habits had changed as much. Here’s this years list:

  • Fever – it’s just so much more beautiful and personal than Google Reader. I guess I like controlling it on my own server.
  • Google Listen – for podcasts on my Android
  • Spotify – I’m a premium member, I like it so much.
  • Steam – I really like having electronic copies of games. I’m not so bothered about physical media.
  • World Of Warcraft – it’s a phase, I’m sure.
  • Facebook – of course.
  • Reddit

It’s odd to see how many of my favourite things are all paid for now. I’m not sure if paying for something is a thing that people do as they get older, or if I just feel better about paying.

It’s nice to be back in charge!

I switched back to WordPress.org, on a hosted server from .com since my domain wrapping ran out, and I was getting bored of the walled garden anyway. I wanna start WordPress hacking again and it’s hard to do that with a blog to play around with!

I’ve switched to a new theme too, which is freaking amazing. Not just the front end, but the back end is so comprehensive. There’s a few changes and little bugs I’ve noticed already, but I’ll fix them and send them back to the author when I get a few minutes.