Archive

Posts Tagged ‘dwscript’

Enumerating network adapters in DWScript/Smart under Node.js

July 5, 2019 Leave a comment

This is something I never had the time to implement under Smart Pascal, but it should be easy enough to patch. If you are using DWScript with the QTX Framework this is already in place. But for Smart users, here is a quick recipe.

First, we need access to the node.js OS module:

unit qtx.node.os;

//#############################################################################
// Quartex RTL for DWScript
// Written by Jon L. Aasenden, all rights reserved
// This code is released under modified LGPL (see license.txt)
//#############################################################################

unit NodeJS.os;

interface

uses
  NodeJS.Core;

type

  TCpusResultObjectTimes = class external
    property user: Integer;
    property nice: Integer;
    property sys: Integer;
    property idle: Integer;
    property irq: Integer;
  end;

  TCpusResult = class external
    property model: String;
    property speed: Integer;
    property times: TcpusResultObjectTimes;
  end;

  JNetworkInterfaceInfo = class external
    property address:  string;
    property netmask:  string;
    property family:   string;
    property mac:      string;
    property scopeid:  integer;
    property internal: boolean;
    property cidr:     string;
  end;

  Jos_Exports = class external
  public
    function tmpDir: String;
    function hostname: String;
    function &type: String;
    function platform: String;
    function arch: String;
    function release: String;
    function uptime: Integer;
    function loadavg: array of Integer;
    function totalmem: Integer;
    function freemem: Integer;
    function cpus: array of TCpusResult;
    function networkInterfaces: variant;
    property EOL: String;
  end;

function NodeJSOsAPI: Jos_Exports;

implementation

function NodeJSOsAPI: Jos_Exports;
begin
  result := Jos_Exports(RequireModule("os") );
end;

end.

With that in place, we can start enumerating through the adapters. Remember that a PC can have several adapters attached, from a dedicated card to X number of USB wifi sticks.

Here is a little routine that goes through the adapters, and returns the first IPv4 LAN address it finds. This is very useful when writing servers, since you need the IP + port to setup a binding. And yes, you can just call HostName(), but the point here is to know how to run through the adapter array.

function GetMyV4LanIP: string;
begin
  var OSAPI := NodeJSOsAPI();
  var NetAdapters := OSAPI.networkInterfaces();

  for var Adapter in NetAdapters do
  begin
    // Skip loopback device
    if Adapter.Contains('Loopback') then
      continue;

    for var netIntf in NetAdapters[Adapter] do
    begin
      var address = JNetworkInterfaceInfo( NetAdapters[Adapter][netIntf] );
      if not address.internal then
      begin
        // force copy of string
        var lFam: string := string(address.family) + " ";

        // make sure its ipv4
        if lFam.ToLower().Trim() = 'ipv4' then
        begin
          result := address.address + " ";
          result := result.trim();
          break;
        end;
      end;
    end;
  end;

  if result.length < 1 then
    result := '127.0.0.1';
end;

Amazon + DWScript + Smart mobile = true

June 16, 2015 4 comments

I havent really had time to do much lately. We have two girls who each had their big birthday, and me with a back injury — well, let’s just cap it off to “slow work, but we got there”. Thankfully we had a couple of friends who helped out to get everything in order. But man, these two weeks of finals, school’s out and soccer finals on top of that has been a test.

Anyways, I decided it was time to get some work done – so I signed up for a normal Amazon EC2 Windows 2012 server account. Spent some time fiddling with how to make the server publicly available — but finally found out that you had to add the services to the security group (e.g “http” and so on). Which makes sense since we are talking virtual instances here. I’m used to doing this inside Windows on real hardware, but here Amazon’s flexible IP’s are managed and assigned from the outside.

DWScript up and running

I did the mistake of installing IIS first, figured that was the easiest way to get port 80 allocated — but it was not. So when that mistake was done I just downloaded the DWScript binaries, installed using the setup.exe as per usual — did some allowance in the firewall, and voila! DWScript is now running on it’s default 888 port ūüôā

Works like a charm, and really easy once you get passed the VPC stuff

Works like a charm, and really easy once you get passed the VPC stuff

But now the fun begins, because now I’ll install nodeJS and use Smart Mobile Studio from scratch to write my service layer’s. It’s going to be very interesting to see the performance of nodeJS vs. DWScript. I honestly feel DWScript will kick some serious node ass to be honest, and the fact that DWScript has a DB engine or two built-in saves a lot of time.

First up is to extent HexLicense with cloud management, which I have been tinkering for a while now, so that I can simply clone out VM’s to my customers who wants to deal with serial management via Amazon.

Well, that’s really all I have on my chest right now. Im knacker’d after all that rig work and I am going to have a glass of wine and just listen to music¬†(read: re-charge those internal batteries).

Tomorrow, puja for a friend of mine who is in the hospital and mantrayana for 2 hours at least — Om Nama Shivaya!

DelphiArmy.com is now a reality

December 16, 2014 11 comments

Well I guess congratulations are in order – we, the object pascal community now have our very own job service! Today I bought the software, database and hosting solution, which means that in a matter of days you will be able to visit delphiarmy.com and register as either employer or developer!

The service is global, meaning that it can be used by anyone, be they European, American, from the Middle-East, Africa or Asia. The server was setup yesterday (16 december), the DNS pointer is being set today, add a couple of days tuning, and it will be online

Welcome to the #1 site online for Delphi work

Welcome to the #1 site online for Delphi work

To date I only know of a single website which promotes Delphi jobs, somewhere in France, so for all means and purposes DelphiArmy.com will be the #1 site for object-pascal developers to look for work; and for companies to find serious employees with a solid background in pascal software development.

Features for developers

You will be happy to know that you can both upload your resume (or create one directly on-site), and also connect to your linked-in profile. This should be a great time-saver. Personally I hate having to fill out the same CV on X number of websites. Well, if you already have a nice linked-in profile you can import that.

Video presentations are likewise possible, but I have yet to decide if this should be allowed due to storage concerns.

In short: all the features you would expect from a professional job portal is in place.

  • Upload resume files
  • Linked-In support
  • Great¬†search functionality
  • Online CV builder
  • Video presentation
  • Recommendations
  • Email notification
  • Very reasonable registration fees (one time only)
  • Mobile app (in progress)
  • .. and more

I will also write articles about remote-work, what you need and what you should expect when applying for positions in Norway and Scandinavia at large. Similar articles will be provided for North-America, the Middle-East (Dubai) and Asia.

Features for Employers

  • Option for making your position features (front side spot)
  • Head-hunting services
  • Very reasonable fees (access subscription options).
  • Full access to our database of registered developers
  • Developer Feedback option
  • Email notification
  • .. and more

Your support

I hope I have your support in this endeavor, that you will take the time to register with the service and use it. While you may have a steady job right now, you might be open for weekend work? Perhaps your life will change in six months and you will be looking for a new job. It makes sense to register, both for the community and yourself.

There are thousands of companies, both large and small, using Delphi on a daily basis around the world, sadly¬†each of them live on their own ant-hill and have for some reason stopped talking to each other. Well, let’s get organized and start talking again. And like all great things in life, it begins with someone backing their ideas with action.

Investing in object pascal

As mentioned there are thousands of companies involved with Delphi around the globe. Many of them are maintaining legacy systems, many of them are developing new products – while others express insecurity¬†if Delphi is worth investing in. Now one of the factors which has led to such thinking, has to do with visibility of Delphi (read: object pascal in all it’s forms) in the marketplace and more importantly: the availability of professional Delphi programmers.

Delphi and object-pascal in general has no “official” organ which takes care of promotion and/or open job positions. As a result people have no clue where to look, and end up using local newspapers or recruitment agencies. Until now there havent been a place where employers could reach out to find quality personnel¬†fluent in Delphi. But what they do find are portals dedicated to Java, C#,¬†even PHP and Ruby¬†jobs.

As an example, the company I work for which is one of the biggest in Norway, have spent months trying to find a high-quality Delphi developer for their POS department. It took me less than 2 days to get them 20+ CV’s from professional Delphi programmers. Why? Because¬†I¬†know where to look. I also run Delphi Developer on Facebook with more than 2.600 active members, which¬†I built exactly for that purpose: to get active people talking and working together.

So¬†both employers and developers are there, in the thousands —¬†we just need to connect them.

Sincerely

Jon Lennart Aasenden