ASP.NET Core App with Nginx on Linode

  • Create a server on Linode(e.g. $5 monthly Nanode with Ubuntu)
  • Install Nginx https://www.linode.com/docs/web-servers/nginx/nginx-installation-and-basic-setup/
    Configure the app and nginx for proxy: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2
  • Upload your project with SFTP (e.g. WinSCP )
  • Run your app: dotnet run (Project files or published DLL)
  • Test your app by going to URL you set on Nginx config file.

That’s all. Next steps would be creating a service for your app which is explained here as well: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2

If you need to stop the app before creating a service, get PID of your app ps -ef and stop it by using sudo kill PID

In order to use a custom domain / subdomain with your Linode machine / server, just create an A record in your DNS manager pointing the IP of your Linode.

Nginx example config:

#nginx #dotnet #net-core #linode

Advertisements

Compiling vs Transpiling

A question that I heard recently: Compiling vs Transpiling 

It seems that Wikipedia has enough information as well: “A source-to-source compiler, transcompiler or transpiler is a type of compiler that takes the source code of a program written in one programming language as its input and produces the equivalent source code in another programming language. A source-to-source compiler translates between programming languages that operate at approximately the same level of abstraction, while a traditional compiler translates from a higher level programming language to a lower level programming language.”

Here is the part that NativeScript has in its tooling section: https://docs.nativescript.org/tooling/transpilers

Well, considering how Typescript plays an important role nowadays, transpiling will be a term that we hear a lot.

#typescript #angular #nativescript

SQL and sending emails with Powershell

Run SQL Command

Invoke-Sqlcmd -Query "SELECT COUNT(*) AS Count FROM Table" -ConnectionString "YourConnectionString"

Invoke commands in a script file and save the output in a text file

Invoke-Sqlcmd -InputFile "C:\ScriptFolder\TestSqlCmd.sql" | Out-File -FilePath "C:\ScriptFolder\TestSqlCmd.rpt"

Invoke sql script and write the results into CSV file.

Invoke-Sqlcmd -InputFile "C:\Users\Mehmet\Desktop\Users.sql" -ConnectionString "connection-string" | export-csv "C:\Users\Mehmet\Desktop\SqlResults.csv" 

Invoke sql script and write the results into JSON file.

Invoke-Sqlcmd -InputFile "C:\Users\Mehmet\Desktop\Users.sql" -ConnectionString "connection-string" | ConvertTo-Json | export-csv "C:\Users\Mehmet\Desktop\SqlResults.csv" 

Invoke a script and pass in variable values from a string

C:\> $StringArray = "MYVAR1='String1'", "MYVAR2='String2'"
C:\> Invoke-Sqlcmd -Query "SELECT `$(MYVAR1) AS Var1, `$(MYVAR2) AS Var2" -Variable $StringArray

Send Mail

$PSEmailServer = "smtp-mail-server"
$mypassword = ConvertTo-SecureString "your-password" -AsPlainText -Force
$mycredential = New-Object System.Management.Automation.PSCredential ("your-username", $secpasswd)

Send-MailMessage -From "from@mehmet.es" -To "to@mehmet.es" -Subject "Test email" -Body "This is a test email" -Credential $mycredential

A scenario: Retrieve data from a database and send it as a CSV file.

$CsvFileName = "./Users.csv"
$SqlScriptFile = "Users.sql"
$ConnectionString = "your-connection-string"
$SmtpAddress = "your-smtp"
$UserName = "username"
$Password = "password"
$FromEmail = "from"
$ToEmail = "to"
$EmailSubject = "your-subject"
$EmailBody = "hi there"

$PSEmailServer = $SmtpAddress
$mypassword = ConvertTo-SecureString $Password -AsPlainText -Force
$mycredential = New-Object System.Management.Automation.PSCredential ($UserName, $mypassword)

# Run sql command and create the file
Invoke-Sqlcmd -InputFile $SqlScriptFile  -ConnectionString $ConnectionString  | export-csv $CsvFileName 

# Send the file 
Send-MailMessage -From $FromEmail -To $ToEmail -Subject $EmailSubject -Body $EmailBody -Credential $mycredential -Attachments $CsvFileName

# Remove the file
Remove-Item $CsvFileName

"DONE!"

Note: Invoke-Sqlcmd does not work on Azure WebJobs, it is not installed.

#powershell #powershell-send-email #powershell-sql-commands #powershell-sql-to-csv

Whenever you publish a webjob,…

Whenever you publish a webjob, it is located under the App_Data/jobs/ {triggered or scheduled} of your App Service …
Hence, you can publish the webjobs via FTP or directly from vstudio. If you do so, settings.jobs file need to be created manually.

#azure #webjobs

The 7 Steps of Machine Learning

Machine learning simply Yufeng explains…

Visit the whole playlist too: https://www.youtube.com/playlist?list=PLIivdWyY5sqJxnwJhe3etaK7utrBiPBQ2

#machinelearning

OpenCV 3.4.1 with Visual Studio 2017

  1. Download the prebuilt libraries and extract it (https://opencv.org/releases.html)
  2. Create a Visual C++ Console Project by using Visual Studio 2017
  3. Open the project properties by right-clicking the project and clicking Properties
  4. Select x64 from Platform
  5. Under C/C++ go to General > Additional Include Directories, Edit and add directory: YOUR_OPENCV_FOLDER\build\include
  6. Under Linker go to General > Additional Library Directories, Edit and add the directory: YOUR_OPENCV_FOLDER\build\x64\vc15\lib
  7. Under Linker go to Input, Aditional Dependencies add the name of the lib file opencv_world341d.lib which is under the folder build\x64\vc15\lib
  8. Write the code to read an image and display it
  9. Build the project
  10. In the directory of your solution, there is a folder named x64 and sub-folder Debug. Put your image in that folder and run yourProject.exe that you see in the same folder.

Read an image and display it.

include "stdafx.h"
include <opencv2/core/core.hpp>
include <opencv2/highgui/highgui.hpp>
include <iostream>
using namespace cv; using namespace std;

int main(int argc, char** argv) {

Mat image;

image = imread("MehmetImage.jpg", IMREAD_COLOR);

if (!image.data) // Check for invalid input
{
    cout << "Could not open or find the image" << std::endl;
    return -1;
}

namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.

waitKey(0); // Wait for a keystroke in the window
return 0;
}

#opencv #opencvwithvisualstudio2018 #computervision #machinelearning

Microsoft Build 2018

So many videos and not enough time for all, here is Build 2018 https://channel9.msdn.com/Events/Build/2018
I will share the ones I watch and note them here.
#build2018