Resize image in .NET

This will resize image to be 1024 height or width (whichever is bigger). Explore other options to look for things like image quality. using (var image = Image.FromFile(file.FullName)){ int newHeight, newWidth; if (image.Height > image.Width) { newHeight = 1024; newWidth = (int)(1024.0 * image.Width / image.Height); } else { newWidth = 1024; newHeight = (int)(1024.0 […]

NodeJS Request

“use strict”;const fs = require(“fs”);const request = require(“request”);// Simple GETrequest(“http://localhost:14519/Test/GetHtml”, (err, resp, body) => { console.log(“err: ” + err); console.log(“statusCode: ” + resp.statusCode); console.log(“body: ” + body);});// Output GET results to filerequest(“http://localhost:14519/Test/GetJson”).pipe(fs.createWriteStream(“result.json”));// POST with form parametersrequest.post({ url: “http://localhost:14519/Test/PostParams”, form: { name: “John Smith” },}, (err, resp, body) => { console.log(“err: ” + err); console.log(“statusCode: ” […]

Javascript promises array

“use strict”;const request = require(“request”);go((err, data) => { if (err) { console.error(`ERROR: ${err}`); } else { console.log(“———————————–“); data.forEach(x => { console.log(`success: ${x.success}`); console.log(`URL: ${x.url}`); console.log(`bodyLength: ${x.bodyLength}`); console.log(`error: ${x.err}`); console.log(“———————————–“); }); } console.log(“DONE”);});function go(callback) { var results = []; const urls = [ “http://www.google.com”, “http://www.yahoo.com”, “http://www.bing.com”, “asdf”, “http://www.apple.com” ]; let seq = Promise.resolve(); urls.forEach(url => { […]

Demonstrating a SQL deadlock with .NET

  var conn1 = new SqlConnection(cs); conn1.Open(); var comm1 = conn1.CreateCommand(); comm1.CommandText = “Proc1;”; new Thread(() => { try { Console.WriteLine(“Executing comm1”); comm1.ExecuteNonQuery(); Console.WriteLine(“comm1 done”); } catch (Exception ex) { Console.WriteLine(“comm1: ” + ex); } }).Start(); var conn2 = new SqlConnection(cs); conn2.Open(); var comm2 = conn2.CreateCommand(); comm2.CommandText = “Proc2”; new Thread(() => { try { […]

Async/await in console app

// PM> Install-Package Nito.AsyncEx using Nito.AsyncEx; class Program { static void Main(string[] args) { AsyncContext.Run(() => MainAsync(args)); } static async void MainAsync(string[] args) { // await Something… }} This was an answer on StackOverflow by async/await superstar and blogger Stephen Cleary, who wrote the referenced NuGet package.

SQL Server Identity Info

WITH cte AS ( SELECT s.name + ‘.’ + t.name AS TableName, c.name AS ColumnName FROM sys.tables t INNER JOIN sys.schemas s ON t.schema_id = s.schema_id INNER JOIN sys.columns c ON c.object_id = t.object_id AND c.is_identity = 1 ) SELECT TableName, ColumnName, IDENT_SEED(TableName) AS Seed, IDENT_INCR(TableName) AS Increment, IDENT_CURRENT(TableName) AS LastIdentity FROM cte order by […]

SQL Server basic maintenance

Refresh Views: create procedure util.RefreshViewsasbegin declare @msg nvarchar(1000); set @msg = ‘————- Executing RefreshViews ————-‘; raiserror(@msg, 0, 1) with nowait; set nocount on; declare @viewNames table ( FullName nvarchar(261) — ‘[‘ + 128 + ‘].[‘ + 128 + ‘]’ ); insert @viewNames (FullName) select ‘[‘ + object_schema_name([object_id]) + ‘].[‘ + [name] + ‘]’ from sys.views; […]

JavaScript Destructuring

Destructuring allows you to take an object or array, and pull pieces of it out into local variables. This can be useful to keep code more readable and avoid holding a reference to an object when you don’t need it any longer. You can use this in both JavaScript and TypeScript. View code on GitHub