Wednesday 29 August 2018

The Rise Of Pseudo-Science (flat-earth example)

Introduction

When I was growing up, science was all about truth. It was about proving things by experimental observation. We started off our adventures at school proving relatively simple things like how Hooke's law applies to weights on springs, building on from there, and soon find that you have to rely other peoples work. You accept they are true because their hypothesis has been scrutinised by other scientists and that their experimental evidence successfully reproduced.

It's called “scientific method”, someone has an idea, finds a way to prove it, publishes to their peers and they check it. (It's worked well for hundreds of years)

But our world is changing and with the rise of the internet anyone can publish. It doesn't have to be true, it doesn't have to be checked, and even if it's later proven to be wrong it's unlikely to get taken down. Alongside that we've had a growing movement of conspiracy theorists who are taking advantage of the ease of spreading their ideas.

The all-seeing-eye

People feel increasingly distrustful of their governments and their lack of control in life. But why do people fall for bad science when there's plenty of evidence to the contrary if they choose to go looking for it?

There's also something called "confirmation bias", we are more likely to trust evidence that supports what we believe, and discard what contradicts it. This means once somebody starts to believe in those sorts of ideas it's almost impossible to argue with them.

The dunning-kruger effect chart shows that as we get a small amount of knowledge we can become very sure of our beliefs, but then if we continue to research, we see the bigger picture and the limits of our original ideas. (that's the dip in the curve)

So Why Use/Abuse Science?

It’s more and more common for scientific principles to be selectively used in an attempt to prove a conspiracy or false belief because of material readily available on the internet. They tend to be from less educated people who can’t be bothered to look completely into an observed phenomena because what they see at the surface supports their ideas

Let me give you a couple of flat-earther examples so you see what I mean.

Flat Earth Example 1

In the first example we’ll use google earth to prove the earth is flat.
  1. Take a location by the sea and make a note of it's altitude using Google Earth.
  2. Take another location hundreds of miles away (also by the sea), and note that altitude.
  3. Using the distance between these points and the Earth Curvature table, see what the height drop would be.

Earth Curvature Table
The theory is that for a two points three hundred miles apart there should be a 11 mile drop, but Google Earth shows them to be at the same altitude.

This is of course utter rubbish, because altitude is height above sea level and we picked two points right by the sea.

Example 2

In the second example we’ll take a satellite image showing the transition of the moon across the earth. The distances involved, and the lens focal length make the moon appear to be quite close to the earth and to be around a third of its size.

The transit of the moon

Now look at this photo taken from lunar orbit during one of NASA's Apollo missions. The moon appears huge (it's close to the camera) and the earth looks small (it's far away).

Lunar orbit showing the earth

"Ahah", say the conspiracy theorists, if that picture really was take from the moon then the earth would fill the sky. "Just look at that first picture!"

It's at times like this that I am reminded of this clip from Father Ted..

It's simple really.

Wednesday 28 March 2018

Electronics Store Maplin Closing - The End of an Era

Introduction

As a teenager in the late 80's, I was really into electronics. Back then you could build useful circuits for a reasonable cost, making things that were otherwise expensive or unavailable. It was a great hobby to get into, I wanted to be an electronics wizard (although that name seems silly these days) and I considered at some stage I would get a job within the electronics industry. I would regularly read 'Everyday Electronics' magazine, not only for the articles and build details, but for the adverts, and it was on one of these pages that I discovered an electronics mail order company who sold a chunky catalogue at W.H.Smith for just a few quid. It had amazing cover art, details about a huge range of electronics components and included suggested circuit diagrams for most of their semiconductor components. I bought one every year, it became my faithful companion for my many projects and hobbies... and so began my thirty year plus relationship with Maplin.

The Rise and Fall of the Catalogue

The first catalogue was just 28 pages back in 1972, the year the company first started. But it soon became an impressive tome with well organised sections, filled with clear diagrams, data charts and product photographs. You knew exactly what you were buying, and you received exactly what you'd seen. It's not surprising that Maplin was so successful.

Some of the Maplin catalogues from the 80's borrowed from This Blog

As the years went by, the rise of computers and microprocessors had a huge impact on the industry and Maplin did a reasonable job in keeping up with changes in the market. Add to this the flood of cheap Chinese goods entering the country and making your own stuff became a non-starter. They started to stock computer hardware, but PC technology changed too quickly. These items often became obsolete or were overpriced as soon as the catalogues came out. The company was able to mitigate this problem when they created their website, but the result of this was that most people didn't need the catalogue anymore. I still bought one from time to time, but when you knew a reasonable percentage of stock would be unavailable, it no longer seemed relevant.

The Rise and Fall of The Store

The company expanded the number of stores to over two hundred, every town seemed to have one, but I still liked the convenience of mail order. They diversified into consumer products like gadgets, phone accessories, lighting, disco equipment, home security, kids toys and hobbies. Clearly they weren't going to be able to support shops like these by selling LEDs and 555 timers, but each store still sold a limited quantity of components from a counter at the back. They hadn't totally sold-out, but they lost a lot of credibility by selling cheap crap at hiked-up prices.

The company has been acquired by a number of owners over the last thirty years and it was with sadness that I started seeing news articles this year that revealed Maplin was in trouble. Shortly afterwards PwC were called to act as administrators and attempts were made to find a new owner. The reasons cited ranged from a drop in the value of the pound caused by Brexit, to the withdrawal of credit insurance which made it impossible for them to raise capital. But I don't think we should ignore the impact of online services who could easily under-cut their prices. It may just be another one of those high-street tragedies,.. another bricks and mortar company floundering in wake of online retailers like Amazon.


Just another store closing in this Derby Retail Estate

I wouldn't like to say how much I've spent at Maplin over the years, it's always been my go-to store for bits and bobs. But more recently I've found the store seemed to be a little out of touch or less useful than it used to be. As they cut the number of SKU's to reduce cost, I've found myself turning to eBay for those more obscure items. Nevertheless let's consider for a moment how convenient this place has been. How many stores are there where you can easily go for a cable to connect your USB keyboard to your iPad, a spool of solder, or a couple of metres of speaker cable and take it home that day?

Maplin - Closing Down Sale

I've visited the Derby store a few times over the last week, there's a huge sale on with typically 30% off most products. There's some great bargains, but I wish it wasn't so. For my whole adult life you have been there for me Maplin and I will miss you greatly.

Friday 23 February 2018

Oracle Apex - Forcing Password Change in Custom Authentication

Introduction

If you've created you own authentication scheme in APEX, you may be aware that there's no mechanism to hook into that enforces a password change. Typically you might want your users to change password after 90 days, or if it's just been reset by an admin.

The example in this blog uses a redirect on a global page region to switch to the change password page. It's not a full authentication solution and assumes the following:-
  • You have a table called system_users
  • The table has a column called "expired" which is either '1' or '0'.
  • You have already created a change password page (in my example this is page 106).
  • Page 106 has a process to change your password and reset the "expired" flag.
  • You already have a working authentication and password change function.

Instructions

1 - Create a function to check if your user account is expired.

(My example below assumes you have a "system_users" table with a column called "expired". But it's only a simple example. Write something better!)

Function check_expired(p_app_user varchar2)
 RETURN NUMBER AS
 l_return NUMBER;
BEGIN
  BEGIN
    SELECT 1
    INTO   l_return
    FROM   system_users
    WHERE  expired = 1
    AND    upper(username) = upper(p_app_user));
  EXCEPTION
    WHEN no_data_found THEN
      l_return := 0;
  END;
  RETURN l_return;
END check_expired;



2 - Create an application item called "G_PASSWORD_EXPIRED" and ensure its scope is 'Global'.

3 - Create an application computation for this item, set the computation point to After Authetication and the type to 'PL/SQL Expression'.

The compution will be:-

  check_expired(:APP_USER);
Create an Application Compution for G_PASSWORD_EXPIRED


4 -  Create a global page and add a region called "Redirect".

5 - Set the region type to 'PL/SQL Dynamic Content' and add the following code:-

IF :G_PASSWORD_EXPIRED = 1 THEN
   APEX_UTIL.REDIRECT_URL('F?P=&APP_ID.:106:&APP_SESSION.::&DEBUG.');
END IF;

(NB. Page 106 is the change password page)

6 - Set the Server-side Condition to 'Current Page is NOT in comma delimited list', and list pages you don't want the redirect to be affected by.

(NB. This should be the login page, and the change password page.)

7 - On your change password page, ensure your ChangePassword process sets the G_PASSWORD_EXPIRED item to zero, or you will be stuck in a loop.





Change Password Page Should also Reset G_PASSWORD_EXPIRED

That's all you need... the global page adds a page redirect and no attempt to hack an alternative page allowed me to get around it.

Thursday 25 January 2018

Powerscript - Processing Changed Files in a Folder

Introduction

I needed to find a way of running an import routine for all CSV files in a folder that have recently changed. To do this I created a Windows Powerscript that looked for files where the archive attribute had been set.

(nb. The archive attribute is always set when a file is created or updated)

The basic process will be:-
  • Get all files in folder (which have the .csv extension).
  • Loop through looking for those with the archive attribute set.
  • If found start a new log.
  • Run my dataload process.
  • If success remove archive bit.
  • Write output to log.
The structure and layout of Powerscript is reminiscent of Perl, the block structures are normal, but comparison operators can catch the unfamiliar out.

The Powerscript

Here's what I came up with:-

$path = "<path_to_files>"
$files = Get-ChildItem -Path $path -filter "*.csv"
$attribute = [io.fileattributes]::archive
$newlog = 0

Foreach($file in $files) {
 If((Get-ItemProperty -Path $file.fullname).attributes -band $attribute) {
   if ($newlog -eq 0) {
    $LogTime = Get-Date -Format "dd/MM/yyyy hh:mm:ss"
    "Processing started: $LogTime" | Out-File import.log
    $newlog = 1
   }
   "File: $file" | Out-File run_rt_forecast.log -Append
   $scriptOutput = &<my_external_process> $file.fullname 2>&1
   if($?) {
    Set-ItemProperty -Path $file.fullname -Name attributes -Value ((Get-ItemProperty $file.fullname).attributes -BXOR $attribute)
   }
   Foreach($out in $scriptOutput) {
    "$out" | Out-File run_rt_forecast.log -Append
   }
  }
}

Having spent a lot of time working with Perl, I found it okay to use. There's quite a nice Windows PowerShell ISE which does a reasonable job of allowing you to develop and test in one place. I was also able to open my log file here, but it's a shame it doesn't offer to reload the file when it detects a change.

Gotcha's

Just a few things that caught me out..
  • Ensure you give your script name an extension of ".ps1".
  • When testing, remember to use a Powershell not an ordinary Command Window.