Matt Daubneys Blog

Tag: programming

A quick hack to cheer up a rubbish couple of weeks

by on Aug.24, 2011, under Fun, life, linux, ubuntu

Simply apt-get install libnotify-bin and then add the following to your crontab

*/10 * * * * DISPLAY=:0.0 XAUTHORITY=~/.Xauthority notify-send “Don’t forget”  ”you’re awesome”

Then every ten minutes, this will happen:

Just to cheer yourself up after a really rubbish few weeks.

Leave a Comment :, , , , , more...

Training vs Teaching

by on Dec.11, 2010, under learning, life, programming, ubuntu

Today I’ve been mostly teaching myself the oddities of C++. Now C++ is an object orientated language that’s an extension of C. This has led me to a revalation.

Recently at work I’ve been doing masses of OO stuff (as a change from the previous stuff I was writing which was largely linear) and as a result of that I’ve started seeing the world in terms of objects. Now in order to achieve what I needed at work, I ended up reading up on the theory of objects and what they actually are. In times past when I’ve been “taught” how to program (rather than teaching myself) , the content of the classes where more designed for a specific language on how to solve a specific problem. I think I only once sat in a computing based lecture that talked about the more abstract issues in programming. Whenever I start designing a program I always go back to that single lecture, and a few books that have a higher level stance on problems (such as Design Patterns)  and then once I’m passed that do I go to the language specific things.

The reason I digress this far is that after learning all this meta-stuff, learning another language is actually relatively easy. Now everything is falling down to syntax rather than subject. Going back to the title, I think that those lectures that taught me to do this in this language because it does that has got things backwards. They were doing the training first in the hope it would teach you something. What they should be doing is teaching you the concepts (all the “meta”) and the train you in the language.

Teach and then train, not train and then teach. Something I shall have to try and follow more often in the future.

(Many thanks to Alan Bell for the inspiration in the title :) )

1 Comment :, , , more...

Solving Sleep Problems with Lua

by on Apr.18, 2009, under learning, linux, programming, ubuntu

I’ve discovered recently that I don’t sleep well if I sit on the internet too late at night. Here is my solution.

I’d been intending to learn Lua for a little while now, so this entire project was written in lua, with some bash scripts to call stuff. Essentially what it does, is every minute it checks the time. If the hour is greater than or equal too that set in /etc/bedtimer then it uses iptables to close all the ports I use that go out to the internet. This allows me to continue using my local network stuff (except ssh) if I had things like coursework to do. The server part continues to run every minute after that, incase I try and override it (bad me). There is also a gnome bit that is loaded when I log in. This part simply uses the ubuntu notify-send thing to warn me when I have 15 minutes before the net shuts off, and when it shuts off.

The bit that does all the work is loaded at boot using an initscript. I have yet to reboot and test this, as it’s my first initscript, but it looks ok :)

Hopefully this will force me to actually stop wasting time on the net in the evenings and actually go read a book or do something to wind down at the end of the day.

The files can be found here. There is a shell script to install it all, but it’s rubbish and may not work on your machine! BE WARNED!

2 Comments :, , , more...

Linux From Scratch

by on Apr.08, 2009, under FOSS, learning, linux, packaging, programming, ubuntu

My knowledge of linux is sadly lacking, but every day I improve on it. Since I had a few days free over the easter holidays I thought I’d try and improve this further by installing Linux From Scratch. This is essentially building up a linux system from it’s base packages and takes a LONG time. This to me seemed like a good idea, it would exponentially increase my knowledge of what makes linux tick, and what depends on what.

I started on Monday night by reading through all of the LFS documentation. As bedtime reading goes, it’s actually quite interesting, and it seemed like a good idea to get an overview of what needs doing before I started.

Luckily for me my laptop has a fairly large HD (320GB) so finding some space on a partition was quite easy. A quick boot into a livecd and resizing my /home partition created a nice little 10GB partition for LFS to go in. That was at 9am in the morning. By 10:00am I had downloaded all the required programs in the mounted partition as directed by the book and started to build them.  In the first day, I managed to build the initial toolchain and got into the chroot and got to chapter 6.15 in the LFS PDF. The longest thing to build was probably either glibc or GCC, which took just over an hour, but did give me time to cook some tortillas from scratch for lunch :)

The second day, it took me from about 10 in the morning till roughly 3 in the afternoon to finish installing everything.  Was a bit quicker than I expected, but also a lot more involved.

I did hit a few roadbumps, I didn’t have gawk installed on the host system, so at one point something didn’t compile properly and freaked out a bit. A simple sudo aptitude install gawk fixed that though. When I was recompiling glibc all of the tests failed, it took me a few minutes to realise that the reason this was happening was because I’d forgotten to run “make”.. oops.

The last major bump was that when I chose which options to compile with the kernel, I forgot to add the drivers for my ethernet card and my wireless card, so when I booted the machine I had no network! A quick scan through the options and a recompile sorted that out (to include the b44 driver)

What have I learnt from this? Two things mainly.

  1. Where everything should live on a linux system and why its there
  2. Package Managers are beyond fantastic. They save so much time and hassle!

Tomorrow I intend to try and make my LFS install useful by installing openssh initially, wget and possible x.org and gnome. That may be a bit ambitious at the moment though!

Leave a Comment :, , , , , , more...

Monte Carlo Madness

by on Mar.13, 2009, under learning, Physics, Science, Statistical Physics, ubuntu, Uni

One of my modules has recently involved writing a set of monte carlo models. I’d heard of these mystical things before, but never implimented one myself (or understood the statistics behind them). I’ve become fairly interested in how these things work now, but one thing I didn’t understand was how the number of random numbers you use affected the final result. This seemed like a fairly easy thing to calclate and graph, so I bodged som outputs into my code, wrote a short python script to do a few hundred runs and see what came out the other end.

What came out, I really wasn’t expecting. I assumed the uncertainty (or variance) would decrease as an exponential curve as you incresed the iterations, what really occurs can be seen in the graph below.

WTF?

WTF?

That horrible wiggly bit at the beggining was completley unexpected. I am now wondering if it’s a sign that my data hasn’t been thermalized properly.

Any one out there with any experience of this want to comment?

Leave a Comment :, , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...