Some helpful GIT Commands:
Just another Tech blog
Mar 15, 2024
Jun 28, 2022
How to check if your machine supports SSL or TLS 1.1, 1.2 or 1.3
Open the following link in the browser: https://clienttest.ssllabs.com:8443/ssltest/viewMyClient.html
Scroll down to section: Protocol Features
Dec 7, 2021
Avoid CORS issues in Chrome, Firefox, Safari and Edge for local JavaScript development
Setup a simple proxy using nodejs and npm to bypass CORS issues.
This will solve the following issue in the web browsers:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disableInstall the following npm package globally:
npm install -g local-cors-proxyNow you are ready to setup a local proxy. Let's say the URL that's throwing the CORS issue is:
https://www.example.com/v1/api
To start the proxy, execute the following command:
lcp --proxyUrl https://www.example.com
You will get the following output:
Note: Do not close this window as long as you need the proxy.
Now, in the JavaScript code, API endpoint will be:
http://localhost:8010/proxy/v1/api
This will make a request to URL: https://www.example.com/v1/api without any issues.
Additional options to setup the proxy:
Option | Example | Default |
---|---|---|
--proxyUrl | https://www.google.ie | |
--proxyPartial | foo | proxy |
--port | 8010 | 8010 |
--credentials | (no value needed) | false |
--origin | http://localhost:4200 | * |
Original article can be viewed here.
Jul 15, 2020
Creating an angular service to share data between components using session storage
Create the session storage service as:
To store and retrieve the session storage data, use the service as:
To store and retrieve the session storage data, use the service as:
Creating an angular service to share data between components
Create a Data store to save data as key and values. E.g:
Note: It uses build in Map data structure and it already has function to add, remove, delete and check objects.
Now let's create a service.
To store and save data call the service as:
Note: It uses build in Map data structure and it already has function to add, remove, delete and check objects.
Now let's create a service.
To store and save data call the service as:
May 22, 2020
Using C# to read an update excel files
Create a new solution and add the DocumentFormat.OpenXml Nuget packages to this solution.
Add a new class ExcelManager.cs with the following code:
This provides the basic items like rows of excel data and functions to save text based on column header names and retrieve cell values.
To add logging, refer to my blog here.
Add a new class ExcelManager.cs with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.IO;
using Logger;
using DocumentFormat.OpenXml;
namespace Demo
{
class ExcelManager : IDisposable
{
#region Private Variables
SpreadsheetDocument _document;
Sheet _sheet;
Worksheet _worksheet;
#endregion
#region Public Properties
public IEnumerable<Row> Rows { get; private set; }
#endregion
#region Constructor
public ExcelManager(string filePath)
{
if(!File.Exists(filePath))
{
Logger.log.Error($"Error in DataManager(). File with the following path does not exists:{filePath}");
return;
}
else
{
Logger.log.Info($"Processing file at path: {filePath}");
//Open the Excel file in Edit Mode using OpenXml.
_document = SpreadsheetDocument.Open(filePath, true);
_sheet = _document.WorkbookPart.Workbook.Sheets.GetFirstChild<Sheet>();
_worksheet = (_document.WorkbookPart.GetPartById(_sheet.Id.Value) as WorksheetPart).Worksheet;
Rows = _worksheet.GetFirstChild<SheetData>().Descendants<Row>();
}
}
#endregion
public void Dispose()
{
_document.Dispose();
_document = null;
_sheet = null;
_worksheet = null;
}
#region Public Excel Functions
public string GetCellValue(Cell cell)
{
return _document.WorkbookPart.SharedStringTablePart.SharedStringTable.Elements<SharedStringItem>().ElementAt(Convert.ToInt32(cell.InnerText)).InnerText;
}
public string GetCellValueByReference(string cellReference)
{
var cell = _worksheet.Descendants<Cell>().Where(c => c.CellReference == cellReference).FirstOrDefault();
if (cell != null)
{
return GetCellValue(cell);
}
else
{
return null;
}
}
public void UpdateCell(string columnName, uint rowIndex, string value)
{
try
{
Cell cell = GetCellByColumnName(columnName, rowIndex);
if (cell != null)
{
cell.CellValue = new CellValue(value);
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
// Save the worksheet.
_worksheet.Save();
}
else
{
Logger.log.Warn($"Error in DataManager.UpdateCell(). Error: Cell is null");
}
}
catch (Exception ex)
{
Logger.log.Error($"Error in DataManager.UpdateCell().Error: {ex.Message} StackTrace:{ex.StackTrace}");
}
}
#endregion
#region Private Excel functions
private Cell GetCellByColumnName(string columnName, uint rowIndex)
{
Row row = GetRow(rowIndex);
if (row == null)
return null;
string cellReference = GetColumnReference(columnName).FirstOrDefault().ToString();
if (cellReference == null)
{
Logger.log.Warn($"Error in DataManager.GetCellByColumnName(). Error: Cell Reference is null");
return null;
}
else
return row.Elements<Cell>().Where(c => string.Compare(c.CellReference.Value, cellReference + (rowIndex + 1), true) == 0).First();
}
private string GetColumnReference(string columnName)
{
var cell = GetRow(0).Elements<Cell>().FirstOrDefault(c => GetCellValue(c) == columnName);
if (cell == null)
{
Logger.log.Warn($"Error in DataManager.GetColumnReference(). Error: Cannot retrieve cell with column name: {columnName}");
return null;
}
else
return cell.CellReference.Value;
}
private Row GetRow(uint rowIndex)
{
return Rows.ElementAt(int.Parse(rowIndex.ToString()));
}
#endregion
}
}
This provides the basic items like rows of excel data and functions to save text based on column header names and retrieve cell values.
To add logging, refer to my blog here.
Subscribe to:
Posts (Atom)