Sunday, 29 April 2018

Brexit: All stick and no carrot

"Travel," as Johnny Morris said in his Around the World in 25 Years, "not only, broadens the mind, but stretches it out and rolls it up like a chelsea bun until you don't know who you are, or what you are."

It also gives you jet lag, which means plenty of time to think about what you are too tired to write; until at last you reduce it so such simple points you have to write them.

In the matter of Brexit, remainers still have it so backwards that they keep shooting chunks out of their own foot under the delusion that it is someone else's foot. Their attempts to convert always lead the other way.

If we want home rule and self sovereignty then they offer even more sovereignty (over other countries) via the EU. Apparently sovereignty can be pooled, and in the EU there should be enough to satisfy our thirst for it.

If we want Britain to be ruled by the British, it isn't because we are worried about the race or nationality of the parliament that implements the final legislation to enact the will of the EU commission; and so no, we aren't easily satisfied that our own elected parliament will have the final say on the form of words used to bind us.

We want to be ruled by our own countrymen because they are like us, and they live within marching distance for an angry mob with pitchforks and flaming torches. It keeps them more honest.

But what about unity? What about international cooperation? What about friends and allies? We can't expect other European nations to co-operate in a true spirit of international friendship if we don't pay the EU to permit it.

Think of the hungry golden curly haired European children whose parents pharmaceutical businesses are failing because the EU won't permit the sale of life saving medicines to the suffering sick British golden curly haired children, and all because we wouldn't pay the yearly fee! Wouldn't we pay any amount of money to save those lives? (You can almost see an accounting with an adding machine).

But that argument hardly deserves an answer.; it portrays an EU that can grant nothing but the removal of barriers which it will otherwise enforce.

Then come the veiled threats: Perhaps we wish to avoid war? They suggest: think of all the wars in Europe to defend ourselves from foreign rule (since world war two) that the EU has avoided through the simple expedience of having member states surrender (I mean pool) national sovereignty in advance without need for battle!

Except for the EU army that is suddenly needed...

Stick and Carrot

Their problem is that EU Membership is all they have as carrot, and it having been rejected, they having nothing better to offer but stick.

In fact the EU is in a very hard and woody carrot, in fact pretty much all stick anyway, but it's all they have.

Blasting the Foot

So in what way are the repeatedly blasting their own foot?

The EU can only be made to look attractive in comparison to it's worst parts, and so remainers actually select and identify the worst parts of the EU and present them as some kind of potential exit deal or indefinite transition arrangement, along with larger ongoing fees.

The basis for this is their strategy to argue that if we can't get unity on what the initial leave arrangement should be, we should stay by default. But this is backwards, as I have written before. Our membership of the EU was never assented to and is illegitimate, and so it rather goes like this: if we can't agree on a way to stay, we should leave. It is the remain terms that need unity for us to remain; we already have a mandate to leave without compromise.

But, under their delusion, and in an effort to make remain look attractive, they start drawing attention to the woodier parts of their carrot in the form of various horror bad deals.

If we don't stay, we might leave but remain as part of the customs union (for the good of the economy, so we don't get thrown into the streets and starve). In the customs union we will have much of the obligations and duties but none of the voice - a condition that has been referred to as a vassal state. But the actual choice is to leave, entirely, in comparison to which their vassal-state deal looks absolutely stupid.

"How terrible, " we say, "we don't like that deal" (after all, it is a least carroty part of the stick), but they can't work out why we don't follow up with "so let's stay".

If we leave we will be required to put up a hard border between Eire and Northern Ireland and cause a shooting match. Required by who? The Irish don't want a hard border, the British don't want a hard border, it looks like the EU is making the problems here. The sooner we leave the better.

So now remainers are almost unaware pointing out the bad parts of the EU, are they close to converting?

Thursday, 19 October 2017

Why we won't have a third referendum

Why we won't have a third referendum on the terms of leaving the EU

The 1975 referendum was on single market membership, not EU membership.

There is no authority for EU membership and the associated demonstrated loss of national sovereignty that subsequently occurred, the possibility of which was denied by Edward Heath.

A referendum would be needed to get that authority, and that authority was not obtained in either the 1975 referendum or the 2016 referendum.

Prime Minister Cameron, doing his best (we assume) was unable to find terms on which to get voters to accept membership.

As voters never accepted EU membership and associated loss of sovereignty, our EU membership is illegitimate, and so the default position is therefore to not be a member.

It becomes ludicrous then to seek for national agreement of the terms under which we won't be a member; it is membership that is illegitimate, the non-membership does not need legitimising in the least.

How could a possible rejection of the specific initial terms of leaving be construed as implicit legitimisation of EU membership, in the face of the explicit rejection of membership?

Should we remain by default simply because a few mardy ministers or civil servants will persistently to a bad job and refuse to facilitate a "good deal" in order to continually fail to get national approval?

No, we should assume the legitimate position of non-membership, and give them that to work from.

This is why we shan't have a third referendum on the terms of leaving.

We might have a third referendum on whether and on what terms to re-join the EU, in a few dozen years or so.

Monday, 2 October 2017

Vodafone Broadband

Using your own VDSL router

Thanks to aquazi who reports that you can use your own broadband router if you add to the end of your PPOE username.

Others report that Vodafone will no longer give out the PPOE username and password to you, however I just had online support chat and was given the POE username and password complete with at the end!

Someone pointed that Vodafone currently supports Vodafone supplied hardware only, and doesn’t allow the use of third party routers or modems which is not something I was aware of and seems like a pretty severe limitation to my unlimited broadband.

Avoiding Content Control

Although content control may be disabled, many HTTPS MITM warnings are given for image sharing sites like imgur.

Thanks to its5am who reports that changing to not use Vodafones DNS solves the problem of Vodafones content control performing man-in-the-middle attacks on your HTTPS traffic. (And presumably also returning bogus DNS resolutions).

Wednesday, 21 June 2017

Better update your photo with powershell for windows Outlook/Lync/Skype-for-business/etc

Yesterdays post required the Remote Server Administration Toolskit installed.

Here I show how to do it without that, just using powershell. Thanks to maxx-ode who gives the answer on this Microsoft Technet Forum post .

This code will set picture.jpg as your thumbnail picture.

$root = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(&(objectclass=user)(objectcategory=person) (samAccountName=$env:username))"
$result = $search.FindOne()
$user = $result.GetDirectoryEntry()
$user.put("thumbnailPhoto", [byte[]](Get-Content "picture.jpg" -Encoding byte))

or you want to delete the photo:

$user.putex(1, "thumbnailPhoto", "")

but if you are re-using $user you may want to precede with: $user.refreshcache()

If you get an error like this:

Exception calling "setinfo" with "0" argument(s): "A constraint violation occurred."
At line:1 char:1
+ $user.setinfo()
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

then it could be that your picture is too big, keep it less that 100K, and ideally much smaller than that.
A 100x100 picture should be around 4K which is more ideal.

Tuesday, 20 June 2017

Update your photo with powershell for windows Outlook/Lync/Skype-for-business/etc

NOTE: See my following post which does not required the Remote Server Administration Tools to be installed.

Thanks to the EZ IT guy who writes explaining that by installing the Remote Server Administration Tools for Windows 10 (or Windows 7 if you need it) you can then read your windows domain thumbnail photo picture.jpg like this:

$record = Get-ADUser $ENV:USERNAME -Properties thumbnailPhoto
$record.thumbnailPhoto | Set-Content "picture.jpg" -Encoding byte

And, provided that your photo is less that 100K you can also upload it:

Set-ADUser $ENV:USERNAME -Replace @{thumbnailPhoto=([byte[]](Get-Content "picture.jpg" -Encoding byte))}

All this requires that you be logged into your domain. Also thanks to the WOSHUB for help simplifying it.

If only there were a way that didn't require installing Remote Server Administration Tools.

Also some talk here from heyscriptingguy.

Friday, 16 June 2017

Putting self-tests in a C header file

You can compile a header file to C using gcc -x c like this:

gcc -x c -o feature-test feature.h

Without the -x c options it would have built a pre-compiled header instead of a program you can run.

But of course the compile will ultimately fail as you don't have a main( ) function, and when you think about it you know that you won't normally want one.

Except when compiling the top level header file directly.

The pre-processor symbol __INCLUDE_LEVEL__ is conveniently 0 for the top level file, which lets us do:

int test1( ) {
int main(int argc, char **argv) {
  return test1() && test2() ... ;

So if the top level header file is build directly, then it gets a main and some test functions too.

Thursday, 18 May 2017

Macro detection overload - Special Access Macros

This article talks about how one macro can call another macro if it exists, but if not, it can fallback to a default macro. This can be useful for behaviour vectoring or interception, debugging macros, etc.

Preferring Special Access Macros, but falling back to default macros

It would be nice if a C pre-processor macro can tell if another macro is defined.

It can... in a way. If you know in advance the name of the other macro you are looking it, you can do some comparison tricks as explained by Paul Fultz II in his C Preprocessor tricks, tips, and idioms.

But what if you don't know in advance what it will be called?

What if you are composing a combination of C macros and functions, where the developer can override a special case of the default behaviour for reasons of efficiency?

Maybe you have a cross-bar / plug-board, with data from a variety of sources, to undergo a variety of processing and be sent to a variety of destinations. Maybe you have a general route from a to b but sometimes want to drop in a specific optimisation.

Maybe you want to call a macro process(data, handler) where handler is the name of a macro or function used to emit the slowly generically processed data. Maybe process itself is actually an argument passed to you.

#define work(process, data, handler) process(data, handler)
work(mangle, input, archive);
work(mangle, input, deliver);
A conceptual mangle might be defined (using GCC / clang statement expressions):
#define mangle(handler, data) ({
  for(int x, int i=0; ITERATATE_DATA(&x, i, data); i++) {
but perhaps it's not efficient for mangle to call archive for each processed input element, and we want to have a specialised function to mangle the input for archive instead.

After all there is a big difference between dest[index++]=c; and http_post_value(dest, c); when being called on every piece of data!

Of course the archive handler is simply a macro name and can't be passed as a parameter to a function (this isn't C++ templates you know...).

But that's OK, we write a specific function to mangle the input for the archive output, by calling the archive macro inside the function:
void mangle_archive(void* data) {
  void* buffer = bulk_mangle_to_buffer(data);
That's nice.

But we'd like work(mangle, input, archive) to expand to call function mangle_archive(data) but we'd still like work(mangle, input, deliver) to expand to call the generic macro mangle(data, deliver) because it's not worth writing a more efficient handler to that. (But we might write one later, and if we did, we would want it to just work).

Can we do this? The answer is yes!


Now the difficulty is that (unlike in Paul's example) that we don't know in advance all the different handlers or processes that the user might have, so we can't go declaring in advance a load of macros like COMPARE_foo in advance. (Furthermore this is an ugly requirement to put on the author.)

However, in our case we can require that the special macro body (with which to override the default behaviour) should be entirely enclosed in parenthesis.

So while mangle_archive may well ultimately be a function, we will also define a macro wrapper thus:
#define mangle_archive(...) (mangle_archive(__VA_ARGS__))
Or something like that. As long as it is a macro whose body is in parenthesis and whose name is formed by joining mangle with archive. How does this help?

We have mangle and archive as input parameters, and if we can construct the name mangle_archive from mangle and archive, and then attempt to invoke it (as a macro, with the right number of parameters) it would result in (mangle_archive(...)) which (as the more enlightened will excitedly note) is an expression in parenthesis.

As anybody who has been reading Fultz2Heathcote and Gustedt will know, a well formed expression contained within parenthesis can be made to disappear entirely if prefixed by something such as the name of a macro which was defined thus:
#define VANISH(...)
e.g., with the right amount of coaxing:
VANISH (mangle_archive(__VA_ARGS__))
is quite easily persuaded to be nothing at all. And we can detect nothing at all. (See Jen's piece Detect empty macro arguments).

Clearly, if mangle_archive were not defined, we would have:
VANISH mangle_archive(__VA_ARGS__) which clearly won't be persuaded to vanish, and if mangle_archive were defined to something (not entirely) enclosed in parenthesis, we might have:
VANISH something (not entirely) enclosed in parenthesis
which clearly won't vanish either.

So to detect if the developer has defined a valid overriding macro, we simply attempt to invoke the macro with a VANISHing prefix and then use standard mechanisms already discovered to see if anything is left. (Using EVAL, naturally).

The actual trick is that rather than
#define VANISH(...)
we leave a comma (thanks Jens)
And put this at the start of an argument list to be followed by
We then grab the second argument with
and whether that is the concatenation of the process and handler, or just the process depends on whether or not an extra comma was inserted which would offset the first argument to become the second argument.

The resultant call to the overriding macro is called with the same arguments as would be supplied to the default macro, including the name of the handler. Of course, the handler is implicit now, being defined in the overriding function body, so the overriding macro can dispose of this (perhaps after a static assert) before calling the overriding function.
The simplified full solution is here.

MAGIC_DISPATCH takes at least two or three arguments, which are:

  1. default process name
  2. output handler, which when joined to the default process name becomes a potential overriding process name
  3. other arguments to pass to whichever of the processes is selected, should include at least the handler as the default macro will need to know where to send the data.
#define MAGIC_MAKE_NAME_(a, b) a##_##b
#define MAGIC_MAKE_NAME(a, b) MAGIC_MAKE_NAME_(a, b)
#define MAGIC_EMPTY()
#define MAGIC_DEFER(id) id MAGIC_EMPTY()
#define MAGIC_EVAL(...) __VA_ARGS__


#define work(process, data, handler) MAGIC_DISPATCH(process, handler, handler, data)
#define mangle_archive(handler, ...) (STATIC_ASSERT(#handler == "archive"), do_mangle_archive(__VA_ARGS__))

work(mangle, data, archive); // This will be overridden with mangle_archive
work(mangle, data, deliver); // This will call the default mangle
giving the output:
(STATIC_ASSERT("archive" == "archive"), do_mangle_archive(data));
mangle(deliver, data);
A last minute entry:
#define mangle_deliver(handler, data) (crunch_data(data))
work(mangle, data, deliver); // this will be overridden with mangle_deliver
If this looks too theoretical, consider that handler could be a list whose first member is the macro to call and whose other members could be trailing (or leading) arguments that are inserted into the process invocation. Such a handler would be decomposed by the invoker work to form a correct argument set for MAGIC_DISPATCH.

In such decomposition, these macros may prove useful.
#define MAGIC_LIST(...) (__VA_ARGS__)
#define MAGIC_UNLIST(...) __VA_ARGS__ 
though a more powerful level of EVAL may be required.

Much thanks to Paul Fultz II (C Preprocessor tricks, tips, and idioms), Jonathan Heathcote ( C Pre-Processor Magic), and particularly Jens Gustedt (P99 Macros for Emulation of C11), for documenting their work, which I have read, confused over, and slept on for many a night.