Make an authenticated #Http Request with #Kotlin

January 19, 2018 Leave a comment


Kotlin is a superscript of Java, and the next big thing in Android programming, so it’s worth taking a little dabble in the language, to do something basic.

Beyond Hello World, I always see if I can use it to call an API, which of course, my example below is of – a car registration API. You’ll need to get your own username and password at the website to try out the below code.

Create a file called Http.kt as below;

import java.util.Base64;

fun main(vararg args: String) {
val response = sendGet(“”,”**username**”,”**password**”);


private fun sendGet(url: String, username: String, password: String ) : String {
val connection = URL(url).openConnection() as HttpURLConnection
val auth = Base64.getEncoder().encode((username + “:” + password).toByteArray()).toString(Charsets.UTF_8)
connection.addRequestProperty(“Authorization”, “Basic $auth”)
val text = connection.inputStream.use { it.reader().use { reader -> reader.readText() } }
return text;

Compile the JAR using the code;

kotlinc http.kt -include-runtime -d http.jar

Then run it by using;

java -jar http.jar

and you should get the output

“ABICode”:”21057867″,”Description”:”2015 Honda Civic Type R Gt, 1996CC Petrol, 5DR, Manual”,”RegistrationYear”:”2015″,”CarMake”:{“CurrentTextValue”:”Honda”},”CarModel”:{“CurrentTextValue”:”Civic”},”EngineSize”:{“CurrentTextValue”:”1996CC”},”FuelType”:{“CurrentTextValue”:”Petrol”},”MakeDescription”:”Honda”,”ModelDescription”:”Civic”,”Immobiliser”:{“CurrentTextValue”:””},”NumberOfSeats”:{“CurrentTextValue”:4},”IndicativeValue”:{“CurrentTextValue”:””},”DriverSide”:{“CurrentTextValue”:”RHD”},”Transmission”:{“CurrentTextValue”:”Manual”},”NumberOfDoors”:{“CurrentTextValue”:”5″},”ImageUrl”:””,”VehicleInsuranceGroup”:”21″}

Categories: Uncategorized

#Backup #AWS #Route53 DNS Zones in C#

January 16, 2018 1 comment


If you host your DNS on Amazon Route53, and it’s reasonably complex, it’s worthwhile taking a backup of it, so that future errors can be undone quickly. There are some tools to do it, however, you can also write a script yourself in C# to do it.

First off, get the NUGET package

Install-Package AWSSDK

Create an IAM user within AWS with programmatic access, and get it’s Access Key and Secret ID. – I’ve given it Administrator access, but you should limit the scope to the minimum.

Then I output all the zones to the console here;

var client = AWSClientFactory.CreateAmazonRoute53Client(“***”, “***”, RegionEndpoint.USEast1);

var strOutput = @”route53backup.json”;

var req = new ListHostedZonesRequest();
for (; ; )
var zones = client.ListHostedZones(req);
foreach (HostedZone zone in zones.HostedZones)


var recordSets = client.ListResourceRecordSets(new ListResourceRecordSetsRequest() { HostedZoneId = zone.Id });

foreach (var record in recordSets.ResourceRecordSets)
Console.WriteLine(“\t” + record.Name + ” (” + record.Type + “)”);

foreach (var resource in record.ResourceRecords)
Console.WriteLine(“\t\t” + resource.Value);

req.Marker = zones.NextMarker;
if (req.Marker == null)

Note that the ListHostedZones call only returns 100 domains at a time, you have to set the “marker” parameter to the value of the NextMarker property that was returned on the previous call to get all records.


Categories: Uncategorized

Free HTTPS image hosting – website revamp

January 10, 2018 Leave a comment


If you need to host an image via HTTPS (SSL), because it is going to be embedded into a secure website, such as paypal, ebay, or an email footer. Then this website is a really easy and free way to upload a single image for hosting online via HTTPS.

The website just got revamped, with the new Responsive MaterializeCSS framework, and Stripe to handle the payments.

Over the next few days, there are going to be new features added, like bulk uploads, better logging, and more…


Categories: Uncategorized

Access an #Oracle 11g Database via an #iOS app.

January 10, 2018 Leave a comment

This is a short video demoing the iOS App “”MsSQL,MySQL,Oracle & Postgre” available via… It shows how to add an Oracle Database server, view tables, and query them, all under 30 seconds!

Categories: Uncategorized

Connecting to #PostgreSQL via C#

December 19, 2017 1 comment


As a planned expansion to the Mobile SQL client app ( for iOS, – soon support for Oracle and Postgre will be added.

The back-end to the app is some C# middleware, and the code it uses to connect to Postgre is as follows;

private static DataTable ExecutePostgre(string strDataSource, string databaseName, string strUsername, string strPassword, string strSQL)
const string strDsnTemplate = @”Server={0};User Id={1}; Password={2};Database={3};”;
var sqlConnection = string.Format(strDsnTemplate, strDataSource, strUsername, strPassword, databaseName);
var adapter = new NpgsqlDataAdapter(strSQL, sqlConnection) { SelectCommand = { CommandTimeout = 0 } };
var dataSet = new DataSet();
adapter.Fill(dataSet, “sql”);
return dataSet.Tables[“sql”];

Where NpgsqlDataAdapter comes from the Nuget Package Npgsql, which is installed using

Install-Package Npgsql

Categories: Uncategorized

Connect to an #Oracle #Database from C#

December 18, 2017 1 comment


Connecting to an Oracle Database in c# is just as easy as MySQL or SQL server, it just requires it’s own library and a different connection string.

First, you need the following Nuget Package

Install-Package Oracle.ManagedDataAccess

Then import it using:

using Oracle.ManagedDataAccess.Client;

Here’s a code example –

public static DataTable PopulateDataTable(string command)
var sqlConnection = @”Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XE)));user id=system;Password=xyz123″;
var adapter = new OracleDataAdapter(command, sqlConnection) { SelectCommand = { CommandTimeout = 0 } };
var dataSet = new DataSet();
adapter.Fill(dataSet, “sql”);
return dataSet.Tables[“sql”];

Here, the default service is “XE”, the TNS port is 1521, the  username is system, and password is xyx123 – and the oracle server is on the same PC (localhost)

It’s used as follows;

var strSQL = “select * from someTable”;
var dt = PopulateDataTable(strSQL);
foreach(var dr in dt.Rows.Cast<DataRow>())


Categories: Uncategorized

Query #Microsoft #SQL server from an #iPhone

December 15, 2017 Leave a comment

This slideshow requires JavaScript.

If you use Microsoft SQL server as your production database server, and you keep getting calls when you are out-of-office to make simple updates or check a value in the database, then you no longer have to rush to your PC.

This app, just released yesterday – Called “MsSQL & MySQL Client” is available for download from the app store for 99p at

As the name suggests, it allows updates to both MySQL and SQL server databases.


Categories: Uncategorized