Thursday, 30 August 2018

Where have I been?

Where have I been and what have I been doing?  Well my wife has been for more surgery, those of you know the tale will be well versed, for thos eo fyou not in the know, she's on the mend; slowly.  I have therefore been busy looking after her.

In the hopes of getting more hours out of me the office delivered one of our huge machines to my home and I've been working from there, immediate results were that I did nearly 48 hours of project work whilst not in the office, unfortunately none of that project work is going to be used as the product has changed... Hey ho.  I've also learned that I could never ever work from home for real, even barring surgery recovery, she simply could not wrap her head around how you have to concentrate whilst doing my job and would say my name, wait exactly one second, and say it again, then again and again... So yeah, never going to be able to work from home.

What form did this work take?  Well I was working on porting a Linux USB driver for a device back to windows, so I've written Linux code which drives the USB device in Linux by observing and reverse engineering the activity of a pre-existing windows driver for the said device.  Then someone found a fault in the original windows driver, so the idea was to back port my Linux work back onto windows... Which worked... It worked first time, out the box, before I even had the machine at home to look at directly.  The problem?  The device driver I've then created for windows expresses the exact same issue as the original windows driver was.

A lot of debugging later and I pretty much came to the conclusion that this is a badly behaved USB device, along the way I learned that the sync.c file in libusb has some problems expressing LIBUSB_ERROR_TIMEOUT (-7), indeed I started to write custom cuts of the functions within to let me take internal metrics on them to work out what libusb itself was doing.

So, I maybe, doing the next part of my coding standard rant videos on the contents of some of the libusb source files.

Project management also raised it's curly bonnet to me, I need to sit down, clean up and finish "Super Simple Tickets".  This is because there is no quick way to work with "tickets" in the current provided platforms in the office.  There are ticketing systems, there's a Jira system and there's a Redmine system, and my personal preference has been towards (the now out of vogue) trac for Project Management and ticketing, but none of these are simple and strippled back enough.

I need to hit a lot of users, as simply as possible, from as many devices as possible, including anonymous feedback.  The overhead of managing this is more than the whole effort of collecting & collating the details about the software... That's what we're interested in, what is the software doing, what do our testers and users think... I don't care what group or gantt chart you're in on the project management tool, I don't care who's assigned to what ticket for what purpose, so I want a central place that folks can throw information, ideas or issues... The three I's.

Plus this lets me get back to learning Flask with Python, which is a personal project I never got to finish last year.

After all the above, boost beast still needs more of my attention.

As does my WoW TBC private server.

In short, for my short supply personal time, there's a lot of projects and to get any of them back on the rails I need to sit down, sacrifice a day and just get them cleaned up and in a state where I can pick them up and put them down, literally to let me bit and bob.

I hope that explains to you all where I've been for like a fortnight, but I am here, and things will start crawling out more now the projects have passed at work.

Wednesday, 15 August 2018

Laptop Battery Project

You know that moment when you've torn your laptop battery apart and find Li Ion cells so generic that you can only call them "orange"... yeah... I'm there....



This is like the third replacement battery I've gotten for this laptop, and I love the machine.  But with a battery life shorter than a Goldfish's memory I need to sort this out.

Time to shop, and likely get scammed, trying to find affordable replacements.

The wiring on this thing is also pretty rubbish, why the heck are there two batteries with opposing electrodes towards one another with just a piece of thin plastic card between them?... I mean, is it trying to burn my house down?

Friday, 3 August 2018

Junk Hunt - Strange Typewriter Thing

I'm on the hunt for information, or even the actual thing... What thing?... Well, in the early 1990's my parents took me into a stationary store in Nottingham, I think it was Staples or Office World near the Post Office main buildings, so we're talking St Anns or City Centre ish, certainly behind the Victoria Centre.

Anyway, in there I saw a machine I was sorely tempted to get, it was a semi-electronic typewriter, so it had a form factor about 11" a typewriter keyboard with an LCD screen across the center, you typed could see the text then when you hit enter it write it to the typewriter as a nearly silent printed line...

It also simultaneously write this as an ASCII text file onto a 3.5" floppy which was inserted into the right hand side.

The one I saw was red, cherry red.

The print was a very strong, black, the ribbon was a one use thing once it had put a letter down if you came over the same piece of ribbon (by winding it back) and put another character it'd be missing the bits from the mask cut by writing the prior letter.

And... I loved it.....

I went to see this thing about six times.  I really wanted it to augment my then A-Level studies.  because it was silent, the keyboard had a tactile feel, but no click, the printing was this nearly silent swish and you got the text file from it... or you could put a text file into the disk, load it and it'd print the whole thing out in this lovely type.

Remember, at home I was toting a 9 pin Citizen 120D+ printer, so this really vibrant printing really appealed to me to present things.

If you have any idea what device I'm talking about, comment below!

Monday, 23 July 2018

Microsoft's Noexcept Code Throws Exceptions

I've not dug into this one fully yet, I'm mid-stride on what's going on, however the stack has unspooled me to this location having thrown a read access violation...


But can you see the problem here?  I'm in Microsoft's xstring, as far as I'm concerned this is from my using std::string or std::ostringstream, the function is decorated "noexcept" yet its throwing an exception!


I find this mind bendingly annoying, not least as under GCC & clan on Linux it runs perfectly fine!

So, this is "Unhandled exception thrown: read access violation" in xstring _Equal which is decorated noexcept... Time to format c: and never use Windows I think.

Saturday, 21 July 2018

C++ : Coding Standards by Example #1 (with Boost Beast)

Today I've spent sometime doing a little different video, rather than just play about in code, whilst I played about I made a video of the time I had... Here is it...


We cover:


  • C++
  • Coding Standards
  • Structured Programming
  • Functional Programming
  • Encapsulation
  • Object Orientated Programming
  • Building the Boost Libraries (1.67.0)
  • Visual Studio 2017
  • Static Linking

And generally spend time seeing how I turn gobble-de-gook code into something usable and maintainable against my own Coding Standards.

Get the code yourself here: https://github.com/Xelous/boostBeast

Friday, 20 July 2018

That Moment...

That moment you get half an hour into watching Brad Pitt in War Machine and the wife suddenly asks....

"Do you know him?"

"Who?"

"The actor!"

"Which actor?"

"Him with the grey hair?"

"The General?"

"Yes"

"Brad Pitt"

"Fuck off, that's not Brad Pitt"

I gave up.

Thursday, 19 July 2018

C++ : Copy Constructor versus Ignorance

I've spent a bit of time reviewing someone else's code recently and I've come to an impasse with them, so they have a lot of code which will take some standard container, and the code doesn't just initialise the local copy from the passed in reference... No it'll iterate over the list of elements adding them to the class version.

I have picked fault with this, it's not RAII, it looks ugly and if you're threading you can create your class instance and the member is empty or in a partially filled state before the loop within the constructor is finished... I highlight this in red below...

My solution?  Just initialise the member from the reference - see the green highlight in the code below.

My results from the timing below?



These times are "microseconds" so tiny... But with just constructing from the existing reference we always get a lower time, quicker code...


Running this test 30,000 times, trying it in different orders and with maps of upto 1000 elements I had a rough average increase of 60% speed by using the copy constructor of std::map rather than reallocating new memory for each pre-existing element.

I wanted therefore to understand the reasoning behind the original code, was there some reason to perform a clone (alloc and assign new instance) operation for each pair in the map being passed in?  Looking at the code there was no apparent reason, so I spoke to the developer, asking why they had performed the construction in this manner... Their reply...

"That's how you initialise a container"

You can load up a container in this manner, but you already have the contents of the map, you're just copying it... "Why don't you use the copy constructor?"... I asked...

"I didn't write one"

Hmm, "You don't, the compiler generates it for you, std::map has its own copy constructor".  Use the copy constructor folks, trust me.


#include <map>
#include <chrono>
#include <string>
#include <iostream>


using Mapping = std::map<int, int>;

class A
{
private:
Mapping m_TheMapping;

public:

A() = delete;
A(const A&) = delete;
void operator=(const A&) = delete;

A(const Mapping& p_Mapping)
:
m_TheMapping(p_Mapping)
{
}

A(const Mapping& p_Mapping, const bool& p_Other)
:
m_TheMapping()
{
for (auto i : p_Mapping)
{
m_TheMapping.emplace(i);
}
}

inline Mapping& Mapping()
{
return m_TheMapping;
}
};


int main()
{
Mapping l_m
{
{ 0, 0 },
{ 1, 1 },
{ 2, 2 },
{ 3, 3 }
};

auto l_time(std::chrono::high_resolution_clock::now());
// Copy Construction
A l_map(l_m);
auto l_timeB(std::chrono::high_resolution_clock::now());

auto l_Dur(l_timeB - l_time);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_Dur).count() << std::endl;


auto l_time2(std::chrono::high_resolution_clock::now());
// Clone Construction
A l_map2(l_m, true);
auto l_time2B(std::chrono::high_resolution_clock::now());

auto l_DurB(l_time2B - l_time2);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_DurB).count() << std::endl;
}