Connecting to MSSQL With Windows Authentication in Nodejs

Install npm package npm install mssql msnodesqlv8 --save Sample code const sql = require('mssql/msnodesqlv8'); var dbConfig = { connectionTimeout : 30000, database: "<DB Name>", server: "<server Name>", options: { trustedConnection: true, } }; var dbConfig2 = { connectionTimeout : 30000, connectionString: 'Driver={SQL Server Native Client 11.0};Server=<Server Name>;Database=<DB Name>;Trusted_Connection=yes;', options: { } }; (async () => { try { console.log("start"); await sql.connect(dbConfig); // both format of dbConfig or dbConfig2 will work const result = await sql.

Run Teamcity Job Remotely

Create build with rest api curl --data "@job.json" -H "Authorization: Bearer <token>" -H "Content-Type: application/json" -H "Accept: application/json" -X POST http://<teamcity url>/app/rest/buildQueue The property value in the message body shouldn’t include whitespace if executing with paramters, or use ==Custom Script== instead Sample job.json file { "branchName": "master", "buildType": { "id": "TestBuild" }, "comment": { "text": "Test Build" }, "properties": { "property": [ { "name": "Environment", "value": "SIT" } ] } } Check build status curl -H "Authorization: Bearer <token>" http://<teamcity url>/app/rest/builds/?

Resize Storage in Centos7

Recently one of the VirtualBox system (OS is Centos7) is running out of space, so trying to enlarge the storage. Change disk/snapshot size in VirtualBox Open Vitual Media Manager Select the disk or snapshot to be resized, current is 20GB Enter the new size 40GB and click Apply turn on the system, and check with lsblk # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 19G 0 part ├─centos-root 253:0 0 17G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] Allocate the Free Space Enter command cfdisk Select the Free Space one Select New and Press Enter Select Primary and Press Enter Update Size or keep default to use full free space, and Press Enter Select Write and type yes to write the partition table to disk Select Quit to exit from cfdisk Extend partition # fdisk /dev/sda Enter p to print the initial partition table Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 83886079 20971520 83 Linux Enter t then 3 then 8e to change the new partion type to “Linux LVM” Enter p to print the new partition table Device Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 41943039 19921920 8e Linux LVM /dev/sda3 41943040 83886079 20971520 8e Linux LVM Enter w to write the partition table to disk Update kernel in-memory partition table Update the kernel in-memory partition table, and we can see sda3

How to Steer Frame in Selenium

Switch to frame Select a frame by its (zero-based) index driver.switchTo().frame(int index) Select a frame by its name or ID driver.switchTo().frame(String nameOrId) Select a frame by WebElement driver.switchTo().frame(WebElement frameElement) Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged driver.switchTo().parentFrame(); Selects either the first frame on the page, or the main document when a page contains iframes driver.

Using JavaMail to Search GMail With IMAP

Enable IMAP in GMail Log into your GMail account and go to Settings Switch to tab “Forwarding and POP/IMAP” Select Enable IMAP Set Folder size limits to Limit IMAP folders to contain no more than this many messages 1,000 Less secure app access Go to https://myaccount.google.com/lesssecureapps?pli=1 Turn on Allow less secure apps if this is not turned on, we will get following exception javax.mail.AuthenticationFailedException: [AUTHENTICATIONFAILED] Invalid credentials (Failure) at com.

Reusing Existing Browser Session in Selenium

During script development or debugging in selenium, if we can attach the code to an existing browser session, it will make things easier. Here is how to do it with Chrome. Open chrome with remote debugging port "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 Start chrome driver WebDriver wdriver =null; ChromeOptions options = new ChromeOptions(); options.setExperimentalOption("debuggerAddress", "127.0.0.1:9222"); driver = new ChromeDriver(options);

How to Use AWS KMS to Encrypt Data

Create KMS CMS Key # create a key and save the key id from the response aws kms create-key --description "Test CMK" # create a alias for the key aws kms create-alias --target-key-id {key_id} --alias-name "alias/testcmk" aws kms list-keys Encrypt and Decrypt a file echo "this is a test message" > test.txt aws kms encrypt --key-id "alias/testcmk" --plaintext file://test.txt --output text --query CiphertextBlob | base64 --decode > test.txt.encrypted aws kms decrypt --ciphertext-blob fileb://test.

Deployment With AWS Codedeploy

Env Setup Create a new EC2 service role, which have access to S3 bucket Launch a new EC2 instance with the role from previous step attached Install CodeDeploy agnet on the EC2 instance sudo yum update sudo yum install ruby sudo yum install wget cd /home/ec2-user wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install chmod +x ./install sudo ./install auto sudo service codedeploy-agent status Create a CodeDeploy service role and attach AWSCodeDeployRole policy Code Deploy Create the application and upload code aws deploy create-application --application-name mywebapp aws deploy push --application-name mywebapp --s3-location s3://{bucket_name}/webapp.

Add Contact Form in Hugo Site

Create a lambda function to send the contact message Setup SES and verify sender email address Create an IAM role for lambda with policy details below { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "ses:SendEmail", "logs:CreateLogStream", "logs:PutLogEvents" ], "Resource": "*" } ] } Create the lambda function const aws = require("aws-sdk"); const ses = new aws.SES({ region: "ap-southeast-2" }); exports.handler = async function (event) { console.

Enable Raw Html in Hugo

Enable support of raw html Hugo disables html element rendering by default, we need to enable it. Enable for an entire site Add below in the config file [markup.goldmark.renderer] unsafe= true Enable for a single page Create layout/shortcodes/unsafe.html with the following content: {{ .Inner }} In the markdown page, use it like this, {{< unsafe >}} <ul> <li>First item</li> <li>Second item <li>Third item</li> </ul> {{< /unsafe >}} above will be rendered like this, First item Second item Third item Reference How To Escape Shortcode In Hugo Template Configure Markup Create Your Own Shortcodes Enable unsafe=true for a single page