Run an ASP.NET website on #AWS without a server

Here is a a few simple steps to run a ASP.NET (Razor / C#) based website on AWS without provisioning an EC2 instance – So you only pay for the few seconds when your website is being requested, and some S3 storage.
TL;DR; Here is the github repo https://github.com/infiniteloopltd/AWSServerlessHelloWorld
First, you have to download the AWS Toolkit for Visual Studio and then open up VS 2019, and select New Project > AWS Serverless application (.NET Core)
Right click on the Project, select publish. Press the user icon, and enter in your AWS Access key and Secret from IAM.
Then, enter in a cloud formation name (just type anything), and create a new S3 bucket (again, any name). Press publish, and wait 5 minutes.
At the end you’ll be given a url like this;
Start and Stop an #AWS #EC2 instance using the C# SDK

Automation of EC2 instances is really important if you want to optimize costs. Perhaps you have a server that does not need to be online 100% of the time, perhaps just during peak hours, or perhaps, when running a scheduled task.
You can use C# to query the state of an instance, and start and stop it. You will need to generate your own Access keys in AWS IAM, and the instance ID and region will change based on your setup,
Add the Nuget Package AWSSDK.EC2
Here is the code to log in to AWS
const string accessKey = "....";
const string secretKey = ".....";
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
var config = new AmazonEC2Config
{
RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName("eu-west-2")
};
var client = new AmazonEC2Client(credentials, config);
var response = client.DescribeInstanceStatus(new DescribeInstanceStatusRequest { IncludeAllInstances = true});
var state = response.InstanceStatuses.First(i => i.InstanceId == "i-0fb....").InstanceState.Name.ToString();
Console.WriteLine("Instance is " + state);
then to start the instance it’s :
client.StartInstances(new StartInstancesRequest(new List<string> { "i-0fb9f4....." }));
And to stop the instance it’s:
client.StopInstances(new StopInstancesRequest(new List<string> {"i-0fb9....."}));
Easy done!
Car Registration #API for #Israel

Israel is a country with 2.9 Million vehicles, and a population of 8.8 million, giving a total car ownership percentage of 33%.
We have just launched an API in Israel, that allows uses to search for a vehicle by license plate (Registration Number), and will return technical details about that vehicle.
This API can be used to determine, the make, model, VIN, and other technical specifications of a vehicle registered in Israel from it’s registration number (license plate). The API applies to cars, motorbikes, and heavy vehicles.
The website is available in Hebrew here ; http://www.rechevapi.co.il/ but, equally, the API can be accessed via any of our other websites, such as here; https://carregistrationapi.com/api/reg.asmx – using the same account, and credits.
Here is an excerpt from our documentation:
Israel support
Offline data available
Car registration plates in Israel use the /CheckIsrael endpoint and return the following information:
- Make / Model
- Age
- VIN number
- Fuel
- Engine size
- Representative image
Sample Registration Number:
1011928
Sample Json:
{
“Description”: “Porsche CAYENNE”,
“Variant”: “PLATINUM”,
“RegistrationYear”: 2017,
“CarMake”: {
“CurrentTextValue”: “Porsche”
},
“CarModel”: {
“CurrentTextValue”: “CAYENNE”
},
“MakeDescription”: {
“CurrentTextValue”: “Porsche”
},
“ModelDescription”: {
“CurrentTextValue”: “CAYENNE”
},
“VehicleIdentificationNumber”: “WP1ZZZ92ZHLA32339”,
“Fuel”: “Diesel”,
“EngineSize”: “2967”,
“Co2”: “179”,
“HorsePower”: “262”,
“IsAutomatic”: “1”,
“Doors”: “5”,
“Seats”: “5”,
“Weight”: “2870”,
“EngineCode”: “CVVA”,
“VehicleUse”: “P”,
“TestDate”: “02/01/2020 00:00:00”,
“LicenseDate”: “11/01/2021 00:00:00”,
“MakeHebrew”: “פורשה גרמניה”,
“VehicleType”: “Car”,
“ImageUrl”: “http://rechevapi.co.il/image.aspx/@UG9yc2NoZSBDQVlFTk5F”
}
C# 300% #performance increase Dictionaries vs #Linq

Simple statment, if you are holding large (1M+) objects in memory, use a Dictionary, don’t use Linq on a Generic List. I saw a 300% improvement using this approach.
So, here is, in pseudocode what I’m talking about.
// SLOW!
List<SomeObject> myList = new List<SomeObject>()
.. Add 1M items to myList
var myObject = myList.FirstOrDefault(o => o.property==id);
Whereas, if you can do this:
// FAST!
Dictionary<int,SomeObject> dList = new Dictionary<int,SomeObject>();
.. Add 1M items to dList
var myObject = dList[id];
It is 300% faster.
My benchmarking code created a 1M item list, and a 1M item dictionary, and ran 100 lookups on each. The Linq approach took 7.6 Seconds, the dictionary took 2 seconds.
Of course, you lose the flexibility of writing filters on other properties, or more complex lookups other than equality.
Extracting data from a running process #Windows / #WindowsSecurity

In this particular instance, I had a long running EXE, that crashed, but didn’t terminate. I couldn’t restart it, but I see that it was still in- memory, so I wanted to see if I could rescue the data from it, or at least some of the data, there was about a 1GB memory footprint.
So, I opened task manager, and Right Click > Create memory dump, and it created a 1GB file. I opened this file in GLOGG, a large file viewer.

And… lo and behold, amonst alot of binary data, there was plain text, that could be easily extracted. Like in this screenshot, where you can see HTML in plain text.
This also may serve as an alarm bell for any software that might hold passwords or sensitive information in memory. Make sure that passwords are not held in static variables, since this approach could be used to extract them.
#OpenSource web crawler in C# based on #HTMLAgilityPack

TL; DR;
Here’s the Repo; https://github.com/infiniteloopltd/WebCrawler/
A Web Spider based using HTMLAgilityPack. This library will follow links within webpages in order to find more webpages, it works asynchronously, and will fire events every time a new page is encountered.
A few caveats, is that it’s single-threaded, so, it’s going to be rather slow. It holds it’s queue in memory, so it’s going to be a memory hog on really large websites. It also doesn’t obey Robots.txt.
Please feel free to fork this library, and improve upon it!
Sample Usage
Spider.OnQueueUpdate = q =>
{
Console.WriteLine("Crawler Queue updated : " + q);
if (q == 0)
{
// when this reaches 0, then the crawl is complete
Console.WriteLine("Crawl Complete");
}
};
Spider.OnVisitedPage = (webpage,content) =>
{
Console.WriteLine("Crawler visited : " + webpage.Url);
};
Spider.OnCrawlError = (webpage, ex) =>
{
Console.WriteLine("Crawler hit error at : " + webpage.Url);
};
Spider.StartPage = new Uri("https://www.cloudansweringmachine.com/");
Spider.Scope = "https://www.cloudansweringmachine.com/"; // Don't leave this domain.
Spider.Start();
Console.WriteLine("Crawl stated, press enter to stop.");
Console.ReadLine();
Decode an SSL Cert from a byte array in C#

This is more of a useful code snippet than any great revelation, however, if you ever needed to convert a byte array of a X509 cert into a X509 certificate object, then here’s how you do it using BouncyCastle
var certificateBase64 = File.ReadAllText(“cert.txt”);
var certData = Convert.FromBase64String(certificateBase64);
var parser = new X509CertificateParser();
var cert = parser.ReadCertificate(certData);
Really easy!; Here’s the project on GitHub – https://github.com/infiniteloopltd/CertificateDecoder
First #Dart / #Flutter Package published

https://pub.dev/packages/license_plate_api_uk
And, I’ve also set up a verified publisher here; https://pub.dev/publishers/infiniteloop.ie/packages
license_plate_api_uk 1.0.2
license_plate_api_uk
A Dart package for looking up technical details on vehicles registered in the UK by their license plate (VRM)
license_plate_api_uk provides a simple way to find vehicle details from a license plate (registration number) of a car, motorbike, or HGV registered in the United Kingdom.
This requires a username and password, which is available for free from https://www.regcheck.org.uk
Usage
A simple usage example:
import 'package:license_plate_api_uk/license_plate_api_uk.dart' as RegCheck;
void main(List<String> arguments) async {
// Usage:
// dart bin/main.dart *VRM* *USERNAME* *PASSWORD*
// Where *VRM* is a UK vehicle registration mark (license plate)
// *USERNAME* and *PASSWORD* are available from https://www.regcheck.org.uk
var vehicle = await RegCheck.LicensePlateUK(arguments[0],arguments[1],arguments[2]);
print('Description: ${vehicle['Description']}');
print('Engine: ${vehicle['EngineSize']['CurrentTextValue']}');
print('Fuel Type: ${vehicle['FuelType']['CurrentTextValue']}');
print('Transmission: ${vehicle['Transmission']['CurrentTextValue']}');
print('Image: ${vehicle['ImageUrl']}');
print('Body Style: ${vehicle['BodyStyle']['CurrentTextValue']}');
print('Colour: ${vehicle['Colour']}');
print('Registration Date: ${vehicle['RegistrationDate']}');
print('Engine Number: ${vehicle['EngineNumber']}');
print('VIN: ${vehicle['VehicleIdentificationNumber']}');
}
which produces the following:
Description: VAUXHALL MOKKA SE
Engine: 1364
Fuel Type: Petrol
Transmission: Automatic
Image: https://www.regcheck.org.uk/image.aspx/@VkFVWEhBTEwgTU9LS0EgU0U=
Body Style: Hatchback
Colour: BLUE
Registration Date: 01/06/2014
Engine Number: A14NET 140580075LUJ
VIN: W0LJD7E85EB690449
Features and bugs
Please file feature requests and bugs via the website http://www.regcheck.org.uk
Call a JSON-based #API with basic authentication using #Dart / #Flutter

TL;DR;
The Github repo is here, for anyone to clone / fork : https://github.com/infiniteloopltd/DartLicensePlateAPI
What this does, is call a JSON based API, using basic authentication using the Dart programming language. The code is pretty simple, and it only requires ‘http’ as a dependency.
import ‘package:http/http.dart’ as http;
import ‘dart:convert’ as convert;Future<dynamic> LicensePlateUK(String Reg, String Username, String Password) async {
String basicAuth = ‘Basic ‘ + convert.base64Encode(convert.utf8.encode(‘$Username:$Password’));
String url = ‘https://www.regcheck.org.uk/api/json.aspx/Check/$Reg’;
var response = await http.get(url,
headers: <String, String>{‘authorization’: basicAuth});
return convert.jsonDecode(response.body);
}
Which can be consumed as follows;
import ‘package:RegCheck/RegCheck.dart’ as RegCheck;
void main(List<String> arguments) async {
// Usage:
// dart bin/main.dart *VRM* *USERNAME* *PASSWORD*
// Where *VRM* is a UK vehicle registration mark (license plate)
// *USERNAME* and *PASSWORD* are available from https://www.regcheck.org.uk
var vehicle = await RegCheck.LicensePlateUK(arguments[0],arguments[1],arguments[2]);
print(‘Description: ${vehicle[‘Description’]}’);
print(‘Engine: ${vehicle[‘EngineSize’][‘CurrentTextValue’]}’);
print(‘Fuel Type: ${vehicle[‘FuelType’][‘CurrentTextValue’]}’);
print(‘Transmission: ${vehicle[‘Transmission’][‘CurrentTextValue’]}’);
print(‘Image: ${vehicle[‘ImageUrl’]}’);
print(‘Body Style: ${vehicle[‘BodyStyle’][‘CurrentTextValue’]}’);
print(‘Colour: ${vehicle[‘Colour’]}’);
print(‘Registration Date: ${vehicle[‘RegistrationDate’]}’);
print(‘Engine Number: ${vehicle[‘EngineNumber’]}’);
print(‘VIN: ${vehicle[‘VehicleIdentificationNumber’]}’);
}
I’m going to publish a package to pub.dev once I figure out how to do that!
Push Notifications #iOS13 with Cordova PushPlugin

If you’re using phonegap-plugin-push 1.10.0 “PushPlugin” with Cordova and iOS13, then you will quickly notice, that in your callback, that the data.registrationId will be in the wrong format, something like:
{length=32,bytes=0x61a941c6799e63043d5366de0b865cbf...781fd5936a7efdc6}
as the device token, which will obviously not work.
So, there are solutions, like upgrading the push plugin, but for whatever reason, you can’t do that, here is the code change necessary to fix the plugin:
Open Plugins > PushPlugin.m
Scroll down to didRegisterForRemoteNotificationsWithDeviceToken
and remove this line of code:
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:@”<“withString:@””]
stringByReplacingOccurrencesOfString:@”>” withString:@””]
stringByReplacingOccurrencesOfString: @” ” withString: @””];
and replace this with:
NSUInteger length = deviceToken.length;
const unsigned char *buffer = deviceToken.bytes;
NSMutableString *hexString= [NSMutableString stringWithCapacity:(length * 2)];
for (int i = 0; i < length; ++i) {
[hexString appendFormat:@”%02x”, buffer[i]];
}
NSString *token = [hexString copy];
This is from https://onesignal.com/blog/ios-13-introduces-4-breaking-changes-to-notifications/ – So credit due, and respect to George Deglin for this fix.
With this fix, the registrationId goes back to normal, and push notifications work as before.