Pair…configuring?

One of the aspects of XP that also shows up in related styles of development, such as agile, is pair programming.

This is where you work as a team of two, at the same workstation. One of you is the pilot, operating the keyboard. The other is the co-pilot or navigator, and they sit off to the side, observing. Every so often, you switch roles.

Two programmers at work, pair programming. The pilot on the right, at the keyboard, with the navigator to the left. CC BY 2.0 wocintechchat.com
Programmers working as a pair

Continue reading “Pair…configuring?”

CamShow – webcam document visualiser application for educators

CamShow is a simple desktop application for teachers, lecturers or anyone who wants to demonstrate little things up on a big screen.

CamShow in action
CamShow in action

The short version is this- it’s a little app that lets you use a webcam to show real, physical documents on your PC (and therefore your smartboard), and it has a vertical flip option in case you want to mount the camera at the rear of your table.

Continue reading “CamShow – webcam document visualiser application for educators”

Virtualmin admin scripts

The college’s neongrit linux server uses Virtualmin/Usermin to handle the admin of users, and providing those users with a web interface to configure things like how apache works for their virtual host, creating new databases, etc.

It’s a very useful framework, and has most of the essentials we needed, but I wrote a few scripts in Perl to assist me with some frequent tasks, the way that fit me- which is perhaps more true of sysadmin scripts than any other sort of software, that they are built to scratch an itch. Here’s one to assist batch adding of users and creating them a virtual web host.

Continue reading “Virtualmin admin scripts”

JavaScript userscripts

Problem

I was playing a browser-based game that required me to perform an action at 04:00. And I wanted to be asleep at 4am.

One thing I want all budding web developers to remember is this- your application front end is running on someone else’s computer. In what is effectively a debug environment. Developers need to ensure there is no trust between the client and the server (the other way around is fine, however).

Because the code is not compiled, it is even easier to dig into the code- the HTML and JavaScript -and make changes.

But I didn’t need to go that far.

Using Firefox, and hitting Ctrl-Shift-K, brings up the Web Console. From here, we can look at messages, errors and warnings, but we can also issue commands in JavaScript.

Solution

setTimeout(function() {document.getElementsByName("act_use")[0].click()}, 120*60*1000);

Let’s break it down. First, I need to trigger something in the future. That calls for setTimeout() (setInterval() if we wanted to keep triggering again and again).
setTimeout() takes two arguments, which we might call what and when. what needs to be a function- not the result of a function, but a reference to a function, and if you won’t be using it elsewhere, you might as well inline it, as above. The when is the delay time in milliseconds.

The function body will contain all the instructions we want to carry out. I wanted to simulate a button press on a button element. So the next step is to get a reference to that element. Looking at it, I could see it hadn’t got an id attribute, but it did have a unique value for its name attribute. So that indicates use of document.getElementsByName(). Note that it is “Elements” and not “Element”, because name isn’t necessarily unique on a page. So it returns an array, of which I wanted just the zeroth element- so my call needs the index [0] suffixed to it:

document.getElementsByName("act_use")[0]

This expression should now be a reference to the button element. And what did I want to do with it? Click it. Luckily, there is a function available to us, click(). We can just tack that onto the end, and that’s all our function needs to do.

There’s not much to say about the delay, but note how I have used an expression, not just a literal. That’s to allow me to edit it more easily in future. The 120 is the number of minutes, and I can change it directly, as opposed to working out how many milliseconds it would be.

So, leaving my computer awakw, and the browser open, I issued the command in the Web Console, and came back down in the morning to find it had worked like a charm. Itch, scratched.

If you want to explore this further, might I recommend you take a look at GreaseMonkey or TamperMonkey, for permanent scripting you can apply to pages you visit?

My favourite regexp

Do you have a favourite regular expression? That might be a tricky question for some- like the benighted masses who haven’t yet heard the gospel of regular expressions. Or maybe you have so many dear to your heart, a real Sophie’s Choice? For me, it is easy, the first non-trivial one I wrote, for a task management system called TOM. Take a look and see if you can sell what it does- to help you out (?) I have left it in the context of the line of Perl it came from.

$string =~ s/(?=.{79,})((.{0,77}[\-,;:\/!?.\ \t])|(.{78}))/$1\r\n/g;

Randomness – C# mini tutorial

Note: This was some teaching material I used on the degree and professional courses to explain a little about using randomness- why and how -in your applications. The courses were based around C#, but are easily adapted to many other languages, including Java and Javascript. Just ask for a translation! Because they were slides used as part of an in-class tutorial, some parts may raise questions as much as answer them…

Note 2: A Visual Studio project is available with some starting code, and some questions (in the form of comments) for you to try to answer, available here: rand.zip

Randomness

  • What is randomness?
  • Where can we use it in our programs?
  • How can we acquire random values?
  • How can we make some values more likely than others (weighting/non-uniform distribution)?

Continue reading “Randomness – C# mini tutorial”

Boring Deadly Urgent Machine (Game) :: Part 1 :: The Spec

Some machines I like because of their sleek, minimalist exteriors, modernist or even brutalist megaliths of silicon, or brass.

But I love me some blinkenlights. If it’s got switches galore, laden with quadrant faders and vernier dials, festooned with vu meters, pulsing with neon lamps or LEDs, I’m going to pay that some serious attention. Throw in some industrial interconnects, be they ubiquitous BNCs, or some exotic mixed signal sockets, anything heavy duty, very very high frequency, lots of pins or fibre optic, fastened with clips, twist-locks, clamps or thumb screws….ahem.

Continue reading “Boring Deadly Urgent Machine (Game) :: Part 1 :: The Spec”

Why isn’t SVG more widely used?

I was first introduced to Scalable Vector Graphics (SVG) through Inkscape, the excellent free vector graphics drawing application. It’s available for Windows, Linux and OS X, so please give it a try. You can get it as a portable app, runnable on a Windows machine from a USB memory stick, incredibly handy to have when working on other people’s machines (so if you’ve never visited PortableApps.com, maybe now’s the time!).


Continue reading “Why isn’t SVG more widely used?”

Atollic TrueStudio and STM32Cube

TL;DR version of getting Atollic TrueStudio and STM32Cube working

I have an ST Nucleo-F411RE development board that I’d like to use for a project. It’s using a microcontroller from the same STM32 family as I’ve tried out before, but packaged onto a board with Arduino (Uno)-pattern headers, as well as the full pin breakout. I’m not sure how useful that is for my project yet, but I wanted to give it a test drive.

Most platforms have multiple development options.

The Arduino biosphere has various hardware targets, but with a common IDE. But the Arduino boards are all based on microcontrollers from Atmel (now part of Microchip, the company that also makes PIC microcontrollers). So you aren’t limited to the Arduino IDE, and if you’d like to, you can use all sorts of development toolchains and IDEs.

Continue reading “Atollic TrueStudio and STM32Cube”