Archive

Author Archive

Clean up expired #S3 files in #AWS using C#

s3

If you use Amazon S3 to store temporary files, that are perhaps autogenerated, then emailed to customers, or are otherwise obsolete after a few hours, then it’s a good idea to delete them – to keep your storage costs low, and prevent any leaks of sensitive data later down the line.

Here is some C# code that reads all files in a specified bucket, and deletes files older than 12 hours old. – This example is hard-coded to the EU West Region (Ireland).

First, you need to install the NUGET package:

Install-package AWSSDK.S3

Then, create a class called S3, with the following code – I’ve ommited the keys, that you can get from IAM

using Amazon.S3;
using Amazon.S3.Transfer;
using System;
using System.Collections.Generic;
using System.IO;
using Amazon.S3.Model;

namespace S3Cleanup
{
/// <summary>
/// Amazon S3 functionality
/// </summary>
public static class S3
{
private static readonly AmazonS3Config Cfg = new AmazonS3Config { RegionEndpoint = Amazon.RegionEndpoint.EUWest1 };
private static readonly AmazonS3Client S3Client = new AmazonS3Client(“xxxx”, “xxx”, Cfg);

public static IEnumerable<S3Object> ListBucket(string bucket)
{

var request = new ListObjectsRequest {BucketName = bucket};
var lS3 = new List<S3Object>();
do
{
var response = S3Client.ListObjects(request);
lS3.AddRange(response.S3Objects);
if (response.IsTruncated)
{
request.Marker = response.NextMarker;
}
else
{
request = null;
}
} while (request != null);
return lS3;
}

public static void DeleteObject(string bucket, S3Object s3Object)
{
var request = new DeleteObjectRequest { BucketName = bucket, Key = s3Object.Key };
S3Client.DeleteObject(request);
}

public static string Upload(string bucket, byte[] data, string extension)
{
var ms = new MemoryStream(data);
var filename = Guid.NewGuid().ToString(“D”) + extension;
var fileTransferUtility = new TransferUtility(S3Client);
var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = bucket,
InputStream = ms,
StorageClass = S3StorageClass.ReducedRedundancy,
Key = filename,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(fileTransferUtilityRequest);
return “https://s3-eu-west-1.amazonaws.com/&#8221; + bucket + “/” + filename;
}
}
}

Then you can write come code in your Main() method to do the following:

if (args.Length == 0)
{
Console.WriteLine(“Pass bucket name as argument”);
return;
}
var strBucketName = args[0];
var s3Objects = S3.ListBucket(strBucketName);
Console.WriteLine(“Found ” + s3Objects.Count() + ” objects in bucket”);
foreach (var s3object in s3Objects)
{
var age = DateTime.Now – s3object.LastModified;
if (age.TotalHours <= 12) continue;
Console.WriteLine(“Deleting ” + s3object.Key);
S3.DeleteObject(strBucketName, s3object);
}

Then, if you set that up as a scheduled task, you can delete your old S3 files, and keep your costs down.

Categories: Uncategorized

Create a Real #IOS App with no coding in two minutes.

If you’ve got a mobile-friendly website, then you can also create an app for that website quickly and easily with CreateFreeApp.com – The video above shows just how simple it is to create a real iOS app that can run on your iPhone, you could share with your employees, or even submit to the iOS App store (* Although apple have strict quality guidelines, so you may not pass review)

The video above does gloss over the whole digital signing step – which is the toughest part of the process, and professional iOS developers struggle with this too. However, here are a few steps to create what’s known as an Ad-hoc provisioning profile used in the video above. This allows you to install the app on up to 100 iPhones / iPads without any review by Apple.

If you try to install an app that is not digitally signed, then you get an error message saying “Unable to download App, “CreateFreeApp.com” could not be downloaded at this time.”, and you get a darkened icon on the home screen called “CreateFreeApp”, that says “Unable to Install “CreateFreeApp.com” Please try again later.” if you click it.

You’ll need a developer account at apple, and I’m assuming you’ve got a Distribution certificate set up already – so go log in to developer.apple.com , and select “Certificates, IDs & profiles” – Click Devices > All Then press the plus icon in the top right

Now, on your iphone, go to “get.udid.io” in the Safari browser. Press “Tap to Find UDID”, Press “Allow” then “Install”, “Install”, and your UDID will be displayed on-screen.

Going back to the Apple, enter in the Name of the Device “Dave’s iPhone”, and fill in the UDID in the box below. Press “Continue”.

Now, go to App IDs under Indentifiers on the left hand side, and press the Plus icon in the top right.

Enter the App ID Decription “Create Free App”, and select a wildcard App ID named:

com.createfreeapp.*

Press Continue.

Select iOS provisioning profiles > All, then press the plus icon in the top right. Select Distribution > Ad Hoc then continue.

Select CreateFreeApp in the App ID box then continue.

Select your iOS Distribution Certifcate (Hoping you’ve already set this up!) then continue

Press Select All for the devices list, then press Continue

Enter a name for the profile, i.e. “Create Free App AdHoc” > Continue, then Download the mobileprovision file, and put it in a safe place, as you’ll need it later.

To create your p12 certificate, you will need to open the KeyChain Access utility on your Mac

Select “My Certificates” on the left hand side, and look down to find your “iPhone Distribution” certificate. Control-Click on the certificate, and select Export. Press Save, Enter a password, and again into the verify box, then press OK. You will need this password later, so don’t forget it!. Press “Allow”, and you should have a file on your desktop named Certificates.p12.

When creating an app on Create Free App.com, you will need your mobileprovision file, the p12 certificate, and the password for the certificate, and the app will work on every device that you have obtained a UDID for.

 

 

 

 

 

 

 

 

Categories: Uncategorized

Create an #Android and #iOS app for #free with no coding

Categories: Uncategorized

Own Domain #email backed by #GMail without paying for #GSuite

own-domain

Many domain registrars offer the option for email forwarding on your domain for free, so you can set email sent to info@yourdomain.com to go to you@gmail.com – however, when you reply to an email, the sender is you@gmail.com, not info@yourdomain.com, so the illusion is lost. – But there is a trick.

So, First off, you set up your email forwarding at your registrar, or if your registrar can’t do this, then you can also use the forwarding option at http://www.domaindeflect.com/

Now, you need to set up a SMTP server that will handle outbound email from your domain, I recommend Elastic Email to set this up:

https://elasticemail.com/account#/create-account?r=20b444a2-b3af-4eb8-bae7-911f6097521c

Once you have set up a SMTP server to handle your outbound email, then you go into Gmail, click Settings > Accounts and Import > Add another Email Address

Enter in your name, email address (info@yourdomain.com), enter in your SMTP server, SMTP username and password from Elastic Email, and then press next step. An email will be sent to info@yourdomain.com from the “Gmail Team”, to verify the process. Click on this link.

You should also select the option to “Reply from the same address the message was sent to”, so that by default, the email address is maintained.

 

 

Categories: Uncategorized

Calculate #PHP equivalent #MD5 Hash in MS #SQL Server

md5

The MD5 hash is a pretty standard and secure hashing algorithm, that is often used to create one-way encryption of sensitive data. Quite often the hash code is generated from the application layer, such as PHP, and needs to be verified at the database layer.

So, let’s say you want to hash the word “password” in SQL server – you just write

select CONVERT(varchar(max),HASHBYTES(‘MD5’, ‘password’),2)

which results in

5F4DCC3B5AA765D61D8327DEB882CF99

Possibly the least secure password in the world!

 

Categories: Uncategorized

#Austrian #NatCode API for #BMVIT

KONICA MINOLTA DIGITAL CAMERA

Austria has a system of NatCode id numbers (“Nationaler Code”) developed by Eurotax / Glasss’ that uniquely identifies each make and model of vehicle within for Road tax purposes, and this is now available via an API at http://www.natcode.at

The data can be downloaded in bulk for import into your own database via the following link:  https://payhip.com/b/tS0x

The Austrian API accepts Eurotax NatCode (Nationaler Code) numbers instead of number plates. A NatCode is a unique number under which is registered with the BMVIT.

This API is accessed via the /CheckAustria endpoint, where NatCode is an integer. It returns the following data:

  • Make & Model
  • Engine Size in KW and HorsePower (PS)
  • Engine Capacity
  • Indicative price (new)
  • Date range
  • Transmission
  • Representative image

Sample KBA Number:

223089

Sample Json:

{
“Description”: “Abarth Abarth 124 Spider Aut. “,
“CarMake”: {
“CurrentTextValue”: “Abarth ”
},
“CarModel”: {
“CurrentTextValue”: “Abarth 124 Spider”
},
“MakeDescription”: {
“CurrentTextValue”: “Abarth ”
},
“ModelDescription”: {
“CurrentTextValue”: “Abarth 124 Spider”
},
“PowerKW”: 125,
“PowerHP”: 169,
“EngineSize”: 1368,
“IndicativeValue”: 44000,
“DateRange”: “2016”,
“ImageUrl”: “http://www.natcode.at/image.aspx/@QWJhcnRoICBBYmFydGggMTI0IFNwaWRlcg==&#8221;
}

Categories: Uncategorized

Get #GooglePlus Profile page from #Email

25ba7

If you want to get a person’s Google Plus profile page from their email address, here is the trick to do it.

  1. Get the user’s profile picture from AvatarAPI.com
  2. Take the digits between the last forward-slash “/” and the dot “.”

So, for instance, if you wanted to get the Google Plus page of “peter.smith@gmail.com”, you plug this into AvatarAPI, and you get

lh3.googleusercontent.com/-06yJmZ9VFKI/AAAAAAAAAAI/AAAAAAAAAAA/KHOss3osMJ4/s181-c/117841766777955842390.jpg

Where 117841766777955842390 is the Google Plus Profile ID.

You can navigate to the Google Plus Profile page now using

https://plus.google.com/117841766777955842390

Categories: Uncategorized

#KBA API for Germany based on #Kraftfahrt-Bundesamt data

GERMANY-AUTOMOBILE-VOLKSWAGEN-RECALL

We just launched KbaAPI.de this morning, which is an API that allows a lookup of the German KBA (“Kraftfahrt-Bundesamt”) data. Unlike other countries in the network, the German API accepts KBA numbers instead of number plates.

The data can be purchased as a CSV import for your own database here https://payhip.com/b/PqsL

A KBA number (“Kraftfahrt-Bundesamt”) is a unique number under which is registered with the Federal Motor Transport Authority. The KBA number can be found on the vehicle registration in boxes 2 and 3 or in the registration certificate Part 1 under 2.1.
and 2.2. This API is accessed via the /CheckGermany endpoint, where KBANumber is in the format HSN/TSN (Herstellerschlüsselnummer / Typschlüsselnummer), it returns the following data:
● Make & Model
● Engine Size in KW and HorsePower (PS)
● Engine Capacity
● Fuel type
● Representative image
Sample KBA Number:
4000/305
Sample Json:
{
“Description”: “ALFA GIULIETTA Spider 1.3 [196101 – 196212] (59kW 80hp Otto AR 00508)”,
“CarMake”: {
“CurrentTextValue”: “alfa romeo”
},
“CarModel”: {
“CurrentTextValue”: “GIULIETTA SPIDER”
},
“MakeDescription”: {
“CurrentTextValue”: “alfa romeo”
},
“ModelDescription”: {
“CurrentTextValue”: “GIULIETTA SPIDER”
},
“PowerKW”: 59,
79
“PowerHP”: 80,
“EngineSize”: 1281,
“Fuel”: “Benzin”,
“ImageUrl”:
http://www.kbaapi.de/image.aspx/@YWxmYSByb21lbyBHSVVMSUVUVEEgU1BJREVS&#8221;
}

Categories: Uncategorized

#Jquery #Ajax progress indicator

68747470733a2f2f7261772e6769746875622e636f6d2f4b656e616469612f63697263756c61722d70726f67726573732d696e64696361746f722f6d61737465722f73637265656e73686f742e706e67

If you are using JQuery Ajax to upload a file, or other large blob of data, you might want to show the user that something is happening, rather than just showing an animated gif.

Here’s a JQuery Plugin by Chad Engler which can extend the default $.ajax behavior to report progress updates as a percentage.

(function ($, window, undefined) {
//is onprogress supported by browser?
var hasOnProgress = (“onprogress” in $.ajaxSettings.xhr());

//If not supported, do nothing
if (!hasOnProgress) {
return;
}

//patch ajax settings to call a progress callback
var oldXHR = $.ajaxSettings.xhr;
$.ajaxSettings.xhr = function () {
var xhr = oldXHR.apply(this, arguments);
if (xhr instanceof window.XMLHttpRequest) {
xhr.addEventListener(‘progress’, this.progress, false);
}

if (xhr.upload) {
xhr.upload.addEventListener(‘progress’, this.progress, false);
}

return xhr;
};
})(jQuery, window);

To use it, you would write code allong the lines of:

Upload: function(data,  callback, progressCallback)
{
var strUrl = “/Upload.aspx”;
$.ajax({
method: ‘POST’,
url: strUrl,
dataType: ‘json’,
data: {
Data: data
},
success: function (result)
{
callback(result);
},
error: function () { },
progress: function (e) {
if (e.lengthComputable) {
progressCallback(Math.round(e.loaded / e.total * 100));
}
}
});
}

I’ve just used this on the upload feature of https://httpsimage.com

Categories: Uncategorized

Make an authenticated #Http Request with #Kotlin

kotlin_250x250

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 RegCheck.org.uk – 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.io.IOException
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;

fun main(vararg args: String) {
val response = sendGet(“https://www.regcheck.org.uk/api/json.aspx/Check/LA15ECT&#8221;,”**username**”,”**password**”);
println(response);
}

 

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”)
connection.connect();
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”:”http://www.regcheck.org.uk/image.aspx/@SG9uZGEgQ2l2aWM=&#8221;,”VehicleInsuranceGroup”:”21″}

Categories: Uncategorized