Archive
Creating a #macOS App using HTML and #Javascript

You can create great macOS apps with Swift, and if you’ve got the time to learn a new language, then this is the way to go. But if you already have something cool made with HTML and Javascript, then you can turn it into a macOS app with a few simple steps.
TL;DR;
If you want to skip to the end, you can just clone the GIT repo at https://github.com/infiniteloopltd/UnderTheCryptOSX
But, if you fancy going step by step, – open up XCode and create a new macOS / Cocoa app. Drop a WKWebView onto the form, and set it’s constraints so that it fills the view. Then drag an outlet called;
@IBOutlet weak var webkitview: WKWebView!
You’ll need to add a reference to WebKit as follows;
import WebKit
Then in the viewDidLoad, add the following lines
let url = Bundle.main.url(forResource: “index”, withExtension: “html”)!
webkitview.loadFileURL(url, allowingReadAccessTo: url)
let request = URLRequest(url: url)
webkitview.load(request)
You can then go Add files to … and add your index.html to the project. Now, if you run this now, you may get a white page. To get around this, you will need to go to the project > Capabilities > App Sandbox and click “Outgoing connections (Client)”

Another thing that you may have to do, or else the app may get rejected by apple, is to exit the app when the window is closed. you do this in AppDelegate.swift as follows;
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool
{
return true
}
Sending multiple attachments with #SMTPJS

UPDATE:
Check out the V3 version of the API for a much easier way to do this:
One of the limitations of SMTPJS.com is that you can only send one attachment, this blog post demonstrates a way of sending multiple attachments, by zipping them into one file. It also keeps the size of your email down also.
This uses the JSZip library, which I’ve loaded via the cloudflare CDN. Note the mime type used: application/x-zip-compressed this is important, so that SMTPJS will send the file as a attachment named file.zip, rather than the default file.txt
<html> src="https://smtpjs.com/v2/smtp.js"> src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.js"> language="javascript"> function uploadFileToServer() { var zip = new JSZip(); var numberOfFiles = event.srcElement.files.length; var numberOfProcessedFiles = 0; for(var i=0; inumberOfFiles; i++) { (function(i){ var file = event.srcElement.files[i]; var reader = new FileReader(); reader.readAsBinaryString(file); reader.onload = function () { numberOfProcessedFiles++; zip.file(file.name,btoa(reader.result), {base64: true} ); if (numberOfProcessedFiles == numberOfFiles) { zip.generateAsync({type:"base64"}) .then(function(content) { var datauri = "data:application/x-zip-compressed;base64," + content; Email.sendWithAttachment("YOUR@EMAIL.com", "THEIR@EMAIL.com", "This is the Subject ", "This is the Body - see file.zip attachment!", "****SMTP HOST****", "****SMTP USERNAME****", "****SMTP PASSWORD****", datauri, function done(message) { alert("Message sent OK") } ); }); } }; })(i); } } <input type="file" id="fileupload" onchange="uploadFileToServer()" multiple/> </html>
Charging a credit card with #Stripe in C#

This has been demoed a million times before, but just to show how ridiculously simple it is to bill a card with stripe, here’s a code example in C#
You first open package manager and type
Install-Package Stripe.net
Then use the following code:
var strStripeSecretKey = “sk_live_xxxxxxxxxxxxxx”;
var strCardNumber = “xxxxxxxxxxxxxxxxx”; // Long card number
var strCvCNumber = “xxx”;
var intExpiryMonth = 1;
var intExpiryYear = 2019;
var requestOptions = new StripeRequestOptions() { ApiKey = strStripeSecretKey };
var chargeService = new StripeChargeService();
var chareResponse = chargeService.Create(new StripeChargeCreateOptions()
{
Amount = 1000, // In pence – i.e. £10
Currency = “GBP”,
SourceCard = new SourceCard()
{
Number = strCardNumber,
Cvc = strCvCNumber,
ExpirationMonth = intExpiryMonth,
ExpirationYear = intExpiryYear
}
}, requestOptions);
And that’s all there is! – wow…
#Javascript Error handling with #Chakra in C#

Microsoft’s ChakraCore DLL allows you run Javascript within C# applications using IE’s Javascript interpreter, without having to spawn an exernal process like PhantomJS. This has great applications for situations where you might want to evaluate a user-provided mathematical equation, perhaps like within a spreadsheet, or a statistical application.
The Hello world example can be cloned from Github here; https://github.com/Microsoft/Chakra-Samples/tree/master/ChakraCore%20Samples/Hello%20World/Windows/C%23
You’ll also need to get the built version of the DLL from Nuget here;
Install-Package Chakra.Core
I noticed that I had to copy the DLL from bin\x86 into the bin folder when running an application as 32 bit (A console app), and copy bin\x64 into the bin folder when running under IIS (64 bit)
One thing that I had to build myself in the C# code, was error handling. If the Javascript expression was buggy, then the result was null, with no information about why the Javascript had failed (for example, I noticed that btoa() and atob() were missing in Chakra – for base64 encoding/decoding).
So, to capture the error message, you need to add the following lines after RunScript
varerror = Native.JsRunScript(script, currentSourceContext++, “”, outresult);JavaScriptValueexception;Native.JsGetAndClearException(outexception);JavaScriptValueexceptionString;Native.JsConvertValueToString(exception, outexceptionString);varstrEx = JavascriptValueToString(exceptionString);
Where JavascriptValueToString is defined as follows;
private static string JavascriptValueToString(JavaScriptValuevalue){// Project script result in JS back to C#.IntPtr resultPtr;UIntPtr stringLength;Native.JsStringToPointer(value, outresultPtr, outstringLength);stringresultString = Marshal.PtrToStringUni(resultPtr);return resultString;}
Database mail not working from #SQL server (fixed)

Database mail allows you send email from SQL server, which is handy to report the status of jobs. It’s easy to set up, if you expand Management, select Configure Database Mail, to set your SMTP credentials. Then press send Test Email to check it works.
If it doesn’t work, then, here was a issue I ran in to; if you run
EXEC msdb.dbo.sysmail_help_queue_sp
And both queues are marked as INACTIVE, then you may be missing .NET 3.5 from your server,

You can add .NET 3.5 via server managment, Add Roles and Features Wizard.
You may need to restart your SQL server service after installation.
Car registration #API for #Colombia launched

Colombia is one of the largest automotive markets in South America, after Brazil and Argentina.
At the end of 2017 there were 13 million vehicles in Colombia, according to data from the Ministry of Transportation and the automotive association Andemos. Of those, 912,142 were registered for transportation (freight and passenger) and 7.4 million were motorcycles (57%). Not including motorcycles, 83% of Colombian vehicles are for private use, 16% are in public service, and one percent is for official use (7). According to research conducted by Business Monitor International in 2017, Colombia’s car ownership is still far from reaching saturation point. [Source: Export.gov]
We have launched an API that can return vehicle details from a number plate registered in Colombia at http://co.placaapi.com
Car registration plates in Colombia use the /CheckColombia endpoint and return the following information:
- Make & Model
- Age
- VIN
- Insurance details
- Owner
Sample Registration Number:
HBK482
Sample Json:
{
“Description”: “FORD ECOSPORT [2] SE TP 2000CC 4X2”,
“CarMake”: “FORD”,
“CarModel”: “ECOSPORT [2] SE TP 2000CC 4X2”,
“EngineSize”: “1999”,
“NumberOfDoors”: “0”,
“FuelType”: “COMBUSTIBLE SIN ESPECIFICAR”,
“Vin”: “9BFZB55F6F8517816”,
“VehicleType”: “CAMPEROS Y CAMIONETAS”,
“MotorCode”: “AOJAF8517816”,
“RegistrationYear”: “2015”,
“ImageUrl”: “http://co.placaapi.com/image.aspx/@Rk9SRCBFQ09TUE9SVCBbMl0gU0UgVFAgMjAwMENDIDRYMg==”,
“Insurance”: {
“InsuranceCompany”: “SURAMERICANA”,
“PolicyNumber”: “40006946171”,
“FasecoldaCode”: “03006130”,
“ValidityEndDate”: “03/06/2018 00:00:00”,
“ValidityStartDate”: “03/06/2017 00:00:00”,
“DocumentId”: “79643987”,
“DocumentType”: “CC”,
“Owner”: “JARAMILLO RUBIO WILLIAM”
}
}
Car Registration #API in #Ecuador launched

Ecuador is a country with almost 2 million vehicles registered via the AMT, and we now offer an API that allows users query the make, model and age of a vehicle registered in Ecuador, via it’s number plate, at the website ec.placaapi.com
Car registration plates in Ecuador use the /CheckEcuador endpoint and return the following information:
- Make & Model
- Age
- Representative image
Sample Registration Number:
PBU2742
Sample Json:
{
“Description”: “JEEP RENEGADE”,
“CarMake”: {
“CurrentTextValue”: “JEEP”
},
“CarModel”: {
“CurrentTextValue”: “RENEGADE”
},
“MakeDescription”: {
“CurrentTextValue”: “JEEP”
},
“ModelDescription”: {
“CurrentTextValue”: “RENEGADE”
},
“Year”: “1979”,
“Type”: “LIVIANO”,
“Subtype”: “AUTOMOVIL 4 TIEMPOS”,
“ImageUrl”: “http://ec.placaapi.com/image.aspx/@SkVFUCBSRU5FR0FERQ==”
}
This brings our south american coverage to the following countries:
Car registration #API launched in #Bolivia

Bolivia has a relatively low motor vehicles per capita ratio of only 70 vehicles per 1,000, – meaning the total road population would be only 762,000 – however, for businesses selling into Bolivia, having an API that can quickly and accurately determine the make, model, colour, age, and policy number is a great time saver for users. – We’ve just launched our bolivian website today on http://bo.placaapi.com
Car registration plates in Bolivia use the /CheckBolivia endpoint and return the following information:
- Make & Model
- Age
- Representative image
- Policy Number
- Colour
- and more…
Sample Registration Number:
3054SXI
Sample Json:
{
“Description”: “FORD FIESTA”,
“RegistrationYear”: “2014”,
“CarMake”: {
“CurrentTextValue”: “FORD”
},
“CarModel”: {
“CurrentTextValue”: “FIESTA”
},
“MakeDescription”: {
“CurrentTextValue”: “FORD”
},
“ModelDescription”: {
“CurrentTextValue”: “FIESTA”
},
“Policy”: “140447810”,
“Class”: “AUTOMOVIL”,
“Country”: “MEXICO”,
“Service”: “PARTICULAR”,
“Drive”: “4 X 2 (SIMPLE)”,
“CC”: “1600”,
“Colour”: “ROJO METALICO”,
“Body”: “–“,
“Load”: “0”,
“Doors”: “5”,
“Location”: “LA PAZ”,
“VehicleType”: “REEMPLACADO”,
“ImageUrl”: “http://bo.placaapi.com/image.aspx/@Rk9SRCBGSUVTVEE=”
}
Car Registration #API in Peru

Does your business sell car parts, car services, car insurance, or used cars in Peru? this API will save your users time, and give you more accurate information about the car that the user owns, or intends to purchase.
You can open a free account at http://pe.placaapi.com/ – and get 10 free credits to search for number plates registered in Peru. The data returned will include the make, model, VIN, age, and current owner of the vehicle.
Car registration plates in Peru use the /CheckPeru endpoint and return the following information:
- Make & Model
- Age
- Representative image
- Owner
- VIN number
Sample Registration Number:
B6U175
Sample Json:
{
“Description”: “HYUNDAI TUCSON”,
“RegistrationYear”: “2012”,
“CarMake”: {
“CurrentTextValue”: “HYUNDAI”
},
“CarModel”: {
“CurrentTextValue”: “TUCSON”
},
“MakeDescription”: {
“CurrentTextValue”: “HYUNDAI”
},
“ModelDescription”: {
“CurrentTextValue”: “TUCSON”
},
“DeliveryPoint”: “ASOCIACIÓN AUTOMOTRIZ DEL PERÚ – LIMA”,
“Date”: “10/05/2012 16:18:48”,
“VIN”: “KMHJT81BBCU481538”,
“Make”: “HYUNDAI”,
“Model”: “TUCSON”,
“Owner”: “TOKASHIKI TOKASHIKI JENNY / CORNEJO CORRALES CARLOS ALFREDO”,
“Use”: “Vehiculos Particulares ( Categoria M )”,
“ImageUrl”: “http://pe.placaapi.com/image.aspx/@SFlVTkRBSSBUVUNTT04=”
}
Connect to #Microsoft #SQL server from #Node

Yes, it’s possible to connect to Microsoft SQL Server from Node JS, even on a Mac OSX environment.
First, install msssql via NPM as follows
npm install mssql
Then, you can write some node code as follows;
const sql = require(‘mssql’)
const config = {
user: ‘xxxxx’,
password: ‘xxxxx’,
server: ‘yoursqlserver.com’,
database: ‘master’,
options: {
encrypt: true
}
}
sql.connect(config, err => {
console.log(err);
new sql.Request().query(‘select @@version’, (err, result) => {
console.dir(result)
});
});sql.on(‘error’, err => {
console.log(err);
});
Which, in my case gives the output;
{ recordsets: [ [ [Object] ] ],
recordset:
[ { ”:
‘Microsoft SQL Server 2016 (RTM-GDR) (KB4019088) – 13.0.1742.0 (X64) \n\tJul 5 2017 23:41:17 \n\tCopyright (c) Microsoft Corporation\n\tEnterprise Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 <X64> (Build 9600: )\n’ } ],
output: {},
rowsAffected: [ 1 ] }