The Midlife Geek

Ramblings of a middle aged engineer, runner and open source enthusiast

Category: Misc (page 1 of 2)

Destiny 2 permission error

This PS4 Destiny 2 error:

Your permissions to access online multiplayer may have changed or your profile may have been signed in elsewhere.

Annoying unhelpful Bungie message

Restoring licenses (Settings Account>Management>Restore Licenses) fixed it for me. 

Rainbow hat – decorators, arguments and threads

Raspberry Pi

Playing with Rainbow Hat I learned a few things about Python as a result I found out what a decorator is, the difference between args and kwargs and threads. I also learned that a lot of guides don’t understand either.

If you can’t explain it simply, you don’t understand it well enough.

Albert Einstein

Decorators

Rainbow Hat documentation says “use touch handlers either by passing in a function by name, or using the method as a decorator”.

Learning Python (Lutz, 2013) dedicates a chapter to decorators and sums it up rather well:

In short, decorators provide a way to insert automatically run code at the end of function and class definition statements—at the end of a def for function decorators, and at the end of a class for class decorators.

With similar notation to Java’s annotations:

1
@decorator_function def function(arguments): ...

Python is running one function through another and binding the result to the original function name.

1
2
3
4
def function(arguments):
    ...

function = decorator_function(function)

For example, Python has a built in function that returns a static method staticmethod(function). To make example_func static, we put:

1
2
3
@staticmethod
def example_func(arg)
    ...

Which is rebound to:

1
staticmethod(example_func)(arg)

So now I know what a decorator is in Python, I used it for the buttons. What to use them for though? I figure that they should control speed of LED, sequence or colour. That’s going to need a thread running as an event handler.

A short digression on arguments

What on earth is a key-worded argument? Lots of documentation refers to *args and **kwargs but had no idea what it was. Arguments passed to functions are read left to right:

function('Dougie', 42)

But we can also use a key-value pair:

function(name='Dougie', age=42)

Apart from improving readability in the function call, default arguments can be assigned in the function definition:

def function(name='Dougie', age=42)

By convention these are referred to as arg and kwarg. Almost there – that just leaves the *. Python lets you define functions that take any number of arguments, assembling them into a tuple. If you use key-value arguments, it assembles a dictionary.

def function(**kwargs): {...}

Now the clever(er) bit because if you do the same on the function call, Python unpacks the argument into individual arguments (*arg) or key-value pairs (**kwarg).

function(**kwargs)

Back to the main thread

The Rainbow Hat has buttons so I want to use these to control rainbow speed. This seems suited to a thread running an event handler. The syntax for the thread library (hopefully explaining the digression) is:

thread.start_new_thread (function_name, (*args, **kwargs))

Concurrency in Python is probably a post in its own right. The CPython interpreter bytecode isn’t fully thread safe. There are different interpretations of what that means so I’ll use the Open University definition:

A class is considered thread-safe if its instances behave under concurrent method calls as if they were called sequentially.

M362 Developing concurrent distributed systems (THE OU, 2008)

Python source code is compiled to bytecode which is run in a VM as machine code. In order to ensure only one thread executes bytecode at once the current thread has to hold a global lock (Global Interpreter Lock (GIL)).

This means multiple processor cores aren’t being used. In this application it doesn’t matter because the interpreter emulates concurrency by routinely switching threads.


PyCharm Professional

PyCharm Professional offers a free student license – which is handy as it supports a remote interpreter over SSH. It also has a Linux version!

Developing for Raspberry Pi is fun but developing on Pi is on the sluggish side. So I just use a text editor, making me less productive. Being able to develop on my laptop then execute on the Pi is great – code completion, VCS, highlighting and debugging all available!

Configuration is easy too. Setup Pi for SSH then add the remote interpreter in PyCharm.

PyCharm Professional

Chill JRPG

I hacked a SNES Classic Mini with Hakchi2 the other day.  Wanting to replay a bunch of old school RPG (Lufia I and II, Chronotrigger, Secret of Evermore and Earthbound), I took the name “Dude”.

It’s just like my opinion but it changes the dialogue of the entire game.

 

Is your PS4 ignoring your controller?

Weird one, pressing PS button and it flashes but doesn’t turn on the PlayStation.

Power off the console (hold the power button for about ten seconds or so), connect USB, console comes on when the controller PS button is pressed!

Go figure.

Unexpected footnotes

I am reading “Chavs: The Demonization of the Working Class” by Owen Jones. Borrowed from my local library, a previous borrower has made their own addendum.

owenjoneschavs

It reads “keep them out of mischief“.

There are lots of these. Some reinforce points (or disagree). Some are checking the author’s arithmetic. Why make notes in a borrowed book? There’s not enough time to read it twice and it is unlikely you would borrow the same copy (there’s a waiting list).

My favourite – “Hazel Blears” always annotated “Chunky Kit-Kat“.

Training in El Centro

Just  got home from three months working in El Centro, CA. I wanted to thank the Morales Brazilian Jiu Jitsu Academy for being so welcoming and for teaching me so much.

Made some good friends and thoroughly enjoyed myself. Hopefully I’ll get to come back on that exercise again soon. Looking forward to training there again but until then, I’m going to find a club in the UK and continue there.

For the next week, regrettably, I will be studying my ass off for the M269 exam!

Paranorman

Took the family to see ParaNorman the other night. I really enjoyed it (then again I love this sort of movie) – if you liked Coraline it’s along the same lines (its by the same people).

Its always a bit tricky trying to find something to watch together, especially as the kids get older but this had a good balance for adults, teenagers and younger children. There were a surprising number of people with very young children and I heard a few scared cries in the back of the theatre.

Check out the web site, the trailer is worth a watch and there’s a bunch of free downloads.

Repair Samsung NC10 MBR

I removed Ubuntu from a Samsung NC10 yesterday, now the F4 recovery option doesn’t work. Please excuse the lack of screen shots on this Howto but I couldn’t think how to capture from the recovery manager and camera shots look rubbish.

It would appear that Samsung uses a custom Master Boot Record (MBR) – so for Grub all is well because you can choose to boot into the recovery partition and away you go. However if you have followed any of the usual guides to removing grub (such as running an XP CD to a recovery console and typing fixmbr) F4 will not launch the restore tool.

System Rescue CD is a great tool to have handy on a USB key. You can, so booting into it run this command:

fdisk /dev/sda

Now pressing “p” should show you that the recovery partition is 1, so type “a” then “2”, “a” then “1” to make it bootable. Now write the partition table by typing “w” then reboot. At this point you will boot into the recovery manager and be able to recover but the F4 key will not still not be available at boot and of course trying to create a backup will not work either (as Windows will be booted on restart).

Once Samsung Recovery Manager III has loaded up, press Ctrl+Alt+F10 – I had no idea there was a management mode until I read this page (French) but be aware its only available from the recovery partition. It asks for a password – “secos” (without the quotes). Once in management mode, click the “Image” tab and select “Export” then “Select Location”, I used “D:”. Click “Start” and accept the dialogue box that comes up. This is a backup of the recovery partition.

Once this stage is finished, select the “Tools” tab, insert a spare USB stick and click “Admin Tool USB”. It will format the USB stick and then install some utilities. It takes a couple of minutes. Once finished click the close button in the top right and it’ll ask if the computer should be turned off – say yes.

Boot with the USB key we just made, bringing you to a completely different recovery menu. Click “MBR Fix” and then close the application.

Now when you reboot you’ll notice that the MBR has been repaired and F4 once again boots into Recovery Manager III.

Don’t fix it, censor it

The Security Research Computer Lab at Cambridge University posted an article about industry response to a fundamental flaw in the “chip and pin” system in February. The paper, by Omar Choudary (a PhD student), highlights a flaw in the standard that permits the use of any PIN number. The University passed it to industry two months before publishing.

Now, some eight months later, the only bank known to have addressed this is Barclays. Instead of addressing the issue, the bankers’ trade association feels the best course of action is to tell the University its being irresponsible [pdf] in publishing the information! Given the Streisand Effect, is that not trying to close the stable door after the horse has bolted? The University’s response is an emphatic no, at the moment.

It is interesting that the UK Cards Association feels an offence was committed in proving the vulnerability. I would have thought they’d welcome the information, given their front page statement:

We inform and engage with stakeholders to advance the industry for the ultimate benefit of our members’ consumer and retail customers. Our work includes preventing card fraud, contributing to legislative changes, collating industry statistics and developing industry standards and best practices.

« Older posts

© 2019 The Midlife Geek

Theme by Anders NorenUp ↑