Adam Craig Johnston | Software Developer

Software Developer, Technology Enthusiast, Husband and Dad based in Melbourne.

NovuscodeLibrary update for Delphi 10.4

An update to the NovuscodeLibrary – a Delphi library of utility functions and non-visual classes for Delphi 10.4 is now ready.

https://github.com/novuslogic/NovuscodeLibrary

The next big goal will be a Documentation Wiki using CodeImatic.codegen – CodeDoc plugin. Still a work in progress.

https://github.com/novuslogic/NovuscodeLibrary/issues/11

Also an upgrade and new samples.

https://github.com/novuslogic/NovuscodeLibrary/issues/12

Changelog

ToDo

and that was 2020 in Review.

There has been little content on this blog, due to the human malware sweeping the world.

Some people have loss their jobs, or had reduced hours in my case I have been hyper-busy with my main employment.

It seems my work still is keeping me away, from my side projects and adding content to this blog. However, some progress has happened.

So my thoughts for the new year … more time on my side projects with luck.

Say safe and happy new year.

and that was 2019 in Review.

This blog has been very quiet this year, lots of reasons, mostly work-related has kept me away.

Some milestones were achieved this year:

NovuscodeLibrary

NovuscodeLibrary is a Delphi library of utility functions and non-visual classes.

  • New package NovusCodeLibrary_cURL.dpk – cURL function library
  • New package NovusCodeLibrary_WebUtils.dpk – Web functions library
  • Now support Delphi 10.3 and packages

https://github.com/novuslogic/NovuscodeLibrary

Changelog

ToDo

Adding features or fixing bugs to Novuscodelibrary, it’s general done organically. The next feature supported:

CodeImatic

CodeImatic is a PascalScript based toolchain for building and deployment.

CodeImatc.build

CodeImatic.build is a PascalScript based build and deployment engine.

https://github.com/novuslogic/CodeImatic.build

CodeImatc.codegen

CodeImatic.codegen is a PascalScript template driven source code and static website generator.

https://github.com/novuslogic/CodeImatic.codegen

CodeImatic – Multiple features have been added and moving towards  an early beta release next year.

DelphiAWSSDK

The Delphi AWS SDK enables Delphi/Pascal developers to easily work with Amazon Web Services.

DelphiAWSSDK

Changelog

The next version of DelphiAWSDK v.04 will have a full translation of Amazon DynamoDB https://aws.amazon.com/dynamodb/ using the new experimental Code-Generation based on CodeImatic.codegen https://github.com/novuslogic/CodeImatic.codegen

Using WordPress on Amazon Lightsail

https://leanpub.com/wordpressawslightsail/

I’m develpoing  a new book called “Using WordPress on Amazon Lightsail” which will be pushlished early next year, so sign up with the “Notify Me When This Is Published” button.

Happy New Year.

DelphiAWSSDK v0.2.0

The Delphi AWS SDK enables Delphi/Pascal developers to easily work with Amazon Web Services.

https://github.com/novuslogic/DelphiAWSSDK/releases/tag/v0.2.0

Summary of updates

  • Updated support Delphi XE to Delphi X10.2
  • Tested support for Windows 32/64Bit, MacOSX 32Bit
  • New TAmazonIndyRESTClient and TAmazonDelphiRESTClient classes
  • Updated TAmazonSignatureV4 class to be less reliant on Indy,  allowing for cross-platform development.
  • THashSHA2 supported in unit Amazon.Utils for Delphi XE8 and up.

 

DelphiLibSass – A Delphi wrapper for LibSass

DelphiLibSass is Delphi wrapper around libsass a C/C++ implementation of a Sass compiler.

Based on the version of libsass 3.4 http://libsass.org

DelphiLibSass API is simply composed of a main TDelphiLibSass class:

TDelphiLibSass.ConvertToCss converts a SCSS string to a CSS

Try
  FDelphiLibSass := TDelphiLibSass.Create('libsass.dll');
  FDelphiLibSass.LoadDll;

  FScssResult := FDelphiLibSass.
      ConvertToCss('$font-stack: Helvetica, sans-serif; body { font: 100% $font-stack; }');

  writeln(FScssResult.CSS);
Finally
  FScssResult.Free;
  FDelphiLibSass.Free; 
end;

TDelphiLibSass.ConvertFileToCss converts a SCSS file to a CSS

Try
  FDelphiLibSass := TDelphiLibSass.Create('libsass.dll');
  FDelphiLibSass.LoadDll;

  FScssResult := FDelphiLibSass.ConvertFileToCss('test.scss');

  writeln(FScssResult.CSS);
Finally
  FScssResult.Free;
  FDelphiLibSass.Free; 
end;

Basic example on how to use the Delphi wrapper

https://github.com/novuslogic/DelphiLibSass/tree/master/Sample

References

DelphiLibSass
https://github.com/novuslogic/DelphiLibSass/

Simple 301 Redirect for ASP.NET

A 301 Redirect is a way of sending search engines and user traffic to a specific? URL ,? also telling the search engines to do a permanently move on? that URL.

Implementing 301 redirect in ASP.NET Webforms or ASP.NET MVC; Simply use the Application_BeginRequest event in Global.asax. Then retrieve the URL from the Web.Config file or a Repository.

protected void Application_BeginRequest(Object sender, EventArgs e)
{
string path = "";
switch (Request.Url.Scheme)
{

case "https":
Response.AddHeader("Strict-Transport-Security", "max-age=300");
break;
case "http":
    if (Request.Url.PathAndQuery == "/")
     {

    path = "https://" + WebUtils.WebConfigUtils.GetAppSettingskey("SiteURL") + "/";

    }
else
    {
     path = "https://" + WebUtils.WebConfigUtils.GetAppSettingskey("SiteURL") + "/" + Request.Url.PathAndQuery;

    }
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location", path);
    break;
   }
}

  • When a URL request for an http is made, the switch statement responses by inserting a 301 Moved Permanently and the new location path into the HTTP header .
  • Store the SiteURL in the Web.Config or a Repository.
  • When a URL request for an https is made,the switch statement responses by in inserting Strict-Transport-Security telling the browser to prevent any communications from being sent for HTTP.

Test this function locally in your development environment use IIS Express SSL option.?

References

301 Moved Permanently
http://moz.com/learn/seo/redirection

HTTP Strict Transport Security
https://www.owasp.org/index.php/HTTP_Strict_Transport_Security

Global.asax
http://msdn.microsoft.com/en-us/library/1xaas8a2%28v=vs.71%29.aspx

NovusCodeLibrary.NET – Utilities Library for .NET
https://github.com/novuslogic/NovuscodeLibrary.NET

Working with SSL at Development Time is easier with IISExpress
Working with SSL at Development Time is easier with IISExpress

Encoding a ASP.NET MVC 4 Model for Javascript within a Razor Page

Sometimes you want to pass a property of a model to a Javascript variable, by encoding an ASP.NET 4 model into a Javascript variable, ?using ?HTML Helper and a strongly-typed model within a Razor Page. Razor Page

Razor Page

@model MyWebApp.Models.Foo
@{
ViewBag.Title = "Foo";
}

<script type="text/javascript">
var _model = @Html.Raw(Json.Encode(Model))
</script>
@Scripts.Render("/scripts/Foo.js")

 

  • The model must be strongly-typed.
  • Model encoding must be done at the top of the Razor page to allow the encoded JSON variable to be accessible.
  • JQuery must be included.

 

Example output

<script type="text/javascript">
var _model = {"Firstname":"Adam","Lastname":"Johnston"}
</script>

_model.Firstname
_model.Lastname

Using LESS.JS and ASP.NET MVC 4

Using LESS.JS with ASP.NET MVC 4 is a great for extending the behaviour of CSS with variables, operations and functions.

There are two ways to use LESS with CSS and ASP.NET MVC 4 either dotlesscss or LESSCSS.JS for this post I will be focusing on LESSCSS.JS because dotlesscss doesn’t support all features of LESS.JS.

IIS

A ?.less? MIME Type must be registered with IIS at the command line with in the IIS directory e.g C:\Program Files (x86)\IIS Express:

appcmd set config /section:staticContent /+[fileExtension='.less',mimeType='text/css']

web.config

Next add the mine type to the web.config of the ASP.NET MVC 4 project:

<system.webServer> 
    <staticContent> 
       <mimeMap fileExtension=".less" mimeType="text/css" /> 
   </staticContent >  
</system.webServer>

Razor Page

Add ?.less? files before the less.min.js to avoid namespace issues and always add the ?less.js? last of your ?.less? files.

<head> 
    <link rel="stylesheet/less" type="text/css" href="@Href("~/Content/theme.less")" /> 
    <script src="@Href("/scripts/less.min.js")"></script> 
</head> 

Links

LESS CSS JS
http://lesscss.org/

dotlesscss
http://www.dotlesscss.org/

Add a MIME Type
http://technet.microsoft.com/en-au/library/cc725608%28v=ws.10%29.aspx