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.

Monday, 4 December 2017

Secret Santa - Without a Facilitator Using QR Codes

Introduction

We decided to introduce our younger kids to joy of giving gifts this Christmas by organising a Secret Santa. But we all want to have the fun of guessing who the secret santa is, so decided to find a way that didn't use a facilitator. In addition to that, two people had to be included over Facetime, giving them the same experience, and preserving their secracy.

There are ways to do this using websites and apps, but I wanted to be able to do this with paper, drawing evelopes from a box, and so I could supply a generic label for everyone to use.

The Problem

There are basically two rules in this endevour:
  • ensure you don't pick yourself.
  • maintain secracy at all times.
I needed a way that envelopes could be uniquely identified, but not without some work. They should all look the same to the naked eye so nobody should be able to see when their envelope has been drawn, yet the drawer should be able to effectively reject their own.

Thinking back to my post on treasure hunts the other year, this seemed like a job for QR Codes!

Printing Codes

Find yourself a good QR code generator, (I used http://www.qr-code-generator.com/), but you can also create them in QR Reader Apps on your phone.

1 - Start out by creating a load of codes based on simple numbers, to fix to your envelopes. Print them out at a size of around 1 inch square.

Envelope Identifiers (1-7)

2 - Then create a set of labels with the recipients name and any other details you'd like to add. (I added their Christmas Elf name details from http://christmas.namegeneratorfun.com/ )

Label for my son Saul

Finally I printed off a note for each person. You don't need a QR code on this, and it could just be a bit of paper with their name.


Saul's Note & Instructions

OK, now you're ready to start.

Running the Selection Process

Follow these instructions:-
  1. Fix the envelope identifier QR codes to the outside of your envelopes in a way that they all appear to be the same. (note the orientation of the corner blocks). Use a glue stick so that the label may be removed near the end.
  2. Give each person their own note and label, and a randomly selected envelope.
  3. Each person should then seal these inside their envelope. 
  4. Everyone should then scan their envelope code with their phone to find out their number/id and then post the envelope into a box.
  5. Shake the box to mix up the envelopes and have each person draw one in turn, while others wait at the far end of the room.
  6. After selecting they should scan the QR code and ensure it doesnt belong to them. (if so, have them replace it and take another)
  7. Peel off the QR code and place it in the box, then they should open the envelope in secret.
(Repeat 5-7 for all)

nb. Those joining on Facetime will need an assistant in the room to hold their envelope up to the camera so the remote person can scan it. After drawing the envelope (in step 5) the assistant will also have to write their name and either post it, or find a way of getting it to them.

Hope you find this useful, have a nice holiday.

Monday, 11 September 2017

iPad Won't Start or Charge

The Problem

My son let his ipad run down really low, and then his brother accidentally unplugged it shortly after it had been set to charge. The net result was that the screen went black, then when we plugged it back in to charge we just got the apple logo.



After a few hours it was still the same. It didn't appear to be charging and refused to start.

The solution

I fixed it by putting the ipad into DFU mode and left it plugged into the charger overnight.
  1. Hold the Power Button (3 secs)
  2. Continue holding the power button and also hold the home button (15 secs)
  3. Release the power button while continuing to hold the home button (10 secs)
The ipad screen was black after this, but you'll know it's in DFU mode because when you plug it in you will no longer get the apple logo.

The next day I forced it to shutdown by pressing Power and Home. You should then be able to start it as normal and it will show a 100% charge.

Hopefully this will work for you, good luck.

Tuesday, 18 July 2017

VB - Deploying an Application using Oracle Data Access

Introduction

It's great when you get your application to run in Visual Studio, or even from the compiled files on your PC, but at some stage you're going to want to deploy or share it. This is where I ran into problems with Oracle drivers.

Oracle  Drivers

You set up your Oracle access in VB by selecting the DLL that came with your client software and adding it to the project resources. Here's what mine looked like in Visual Studio..

Assigning the Oracle library as a project resource.
Then add the following imports into your program module..

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types


But, although you've set your resources correctly, the DLL location and version is likely to be different on other machines you deploy to. So you'll probably to get errors.

You can start to fix this by setting the Copy Local value to be True, and then the DLL file gets bundled into the release folder when you re-compile.

Set Copy Local
But while this might get your locally compiled version working, it's likely that other machines will still have problems with driver compatibility errors.

Typically you'll see something like this..

Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client

Solution

Download the Instant Client Basic Lite files from Oracle and unzip it to your PC. Copy the following library DLL files and put it into the same deploy folder as your executable:-

oci.dll
ociw32.dll
Oracle.DataAccess.dll 
orannzsbb11.dll
oraocci11.dll
oraociicus11.dll
OraOps11w.dll

Hopefully that will get you going.

Friday, 7 July 2017

VB - Connecting to an Oracle Database without using a TNS Entry

Introduction

Connecting to an Oracle database isn't too much of a problem, there's examples everywhere on the web along the following lines..

Dim conn As New OracleConnection()
Dim connstr as String, dataSource as String, userId as String, password as String
dataSource = "dev10g"
userId = "jsmith"
password = "letmein"
connstr = "Data Source=" + dataSource + "; User Id=" + userId + "; Password=" + password + ";"
conn.ConnectionString = connstr
Try
  conn.Open()
Catch ex As Exception
  ' Database connection failed
  conn.Dispose() 'Dispose of the connection
  Exit Sub
End Try


This works ok, but it's not very portable unless everyone that wants to use it sets themselves a TNS entry called "dev10g" in their tnsnames.ora file.

What if we wanted to define the host and port number in the config, and then connect without using TNS?

Connecting to Oracle Directly

In practice all we need to do is alter the connection string to provide the information that the tnsnames.ora would have sent. So the code above doesnt change much.

Dim conn As New OracleConnection()
Dim connstr As String
Dim dbServer As String, dbPort As String, dbServiceName As String
Dim userId As String, password As String

dbServer = "lordv01"
dbPort = "1521"
dbServiceName = "dev10g"
userId = "jsmith"
password = "letmein"
dconnstr = "Data Source=" + dbServer + ":" + dbPort + "/" + dbServiceName + ";User ID=" + userId + ";Password=" + password
conn.ConnectionString = connstr
Try
  conn.Open()
  Catch ex As OracleException
  conn.Dispose() 'Dispose of the connection
  Exit Sub
End Try


It took me a bit of poking around to find the right syntax, so hopefully someone will find this useful.