Posts

Formula

WITH DateSequence AS (     SELECT CAST(GETDATE() AS DATE) AS BusinessDate     UNION ALL     SELECT DATEADD(DAY, -1, BusinessDate)     FROM DateSequence     WHERE DATEADD(DAY, -1, BusinessDate) > DATEADD(DAY, -14, GETDATE()) -- Generate enough days to cover weekends ), BusinessDays AS (     SELECT BusinessDate     FROM DateSequence     WHERE DATENAME(WEEKDAY, BusinessDate) NOT IN ('Saturday', 'Sunday') ) SELECT MIN(BusinessDate) AS TMinus5BusinessDay FROM (     SELECT BusinessDate, ROW_NUMBER() OVER (ORDER BY BusinessDate DESC) AS RowNum     FROM BusinessDays ) AS NumberedBusinessDays WHERE RowNum = 5 OPTION (MAXRECURSION 100);

PROCEDURE GetTopResults

CREATE PROCEDURE GetTopOrBottomResults     @N INT,              -- Accepts number of top/bottom results     @OrderType VARCHAR(10) -- Accepts 'Top', 'Bottom', or 'All' AS BEGIN     SET NOCOUNT ON;     -- Determine the number of rows in the table if 'All' is specified     DECLARE @TotalRows INT;     SET @TotalRows = (SELECT COUNT(*) FROM YourTable);     -- Handle the 'All' case by setting @N to the total number of rows     IF @OrderType = 'All'     BEGIN         SET @N = @TotalRows;     END     -- Determine the query to execute based on the @OrderType parameter     IF @OrderType = 'Top' OR @OrderType = 'All'     BEGIN         -- Select top N results ordered by SomeColumn         SELECT TOP (@N) *         FROM YourTable         ...

CurrencyReference Table

 -- Create the CurrencyReference table CREATE TABLE CurrencyReference (     CurrencyDescription NVARCHAR(100),     CurrencyShortName CHAR(3) ); -- Insert all possible currency descriptions and their corresponding ISO codes INSERT INTO CurrencyReference (CurrencyDescription, CurrencyShortName) VALUES     ('Afghan Afghani', 'AFN'),     ('Albanian Lek', 'ALL'),     ('Algerian Dinar', 'DZD'),     ('Angolan Kwanza', 'AOA'),     ('Argentine Peso', 'ARS'),     ('Armenian Dram', 'AMD'),     ('Aruban Florin', 'AWG'),     ('Australian Dollar', 'AUD'),     ('Azerbaijani Manat', 'AZN'),     ('Bahamian Dollar', 'BSD'),     ('Bahraini Dinar', 'BHD'),     ('Bangladeshi Taka', 'BDT'),     ('Barbadian Dollar', 'BBD'),     ('Belarusian Ruble', 'BYN'),     ('Belize Dollar', ...

Python Dash App: Calculate Difference

 # Import necessary libraries import dash from dash import dcc, html from dash.dependencies import Input, Output, State # Initialize the Dash app app = dash.Dash(__name__) # Global default values DEFAULT_VALUE1 = 1000 DEFAULT_VALUE2 = 400 # Function to calculate the difference between two values def calculate_difference(value1, value2):     return value1 - value2 # Define the layout of the app app.layout = html.Div([     html.Div([         html.Label('Value1'),         dcc.Input(             id='input-box-1',              type='number',              value=DEFAULT_VALUE1,              placeholder='Enter first value'         ),     ]),     html.Div([         html.Label('Value2'),         dcc.Input(     ...

PowerShell Function to get the last business day from today's date

# Function to get the last business day from today's date function Get-LastBusinessDay {     # Get today's date     $today = Get-Date     # Determine the last business day based on today's day of the week     switch ($today.DayOfWeek) {         'Monday'   { $lastBusinessDay = $today.AddDays(-3) } # Last Friday         'Sunday'   { $lastBusinessDay = $today.AddDays(-2) } # Last Friday         'Saturday' { $lastBusinessDay = $today.AddDays(-1) } # Last Friday         default    { $lastBusinessDay = $today.AddDays(-1) } # Previous day     }     # Return the last business day     return $lastBusinessDay } # Get and print the last business day $lastBusinessDay = Get-LastBusinessDay Write-Output "The last business day from today's date is: $($lastBusinessDay.ToString('yyyy-MM-dd'))"

Grovey

@echo off @echo off REM Set environment variable to suppress the welcome screen set STREAMLIT_SERVER_HEADLESS=true  set STREAMLIT_BROWSER_GATHERUSAGESTATS=false REM Change to the directory containing your Streamlit app cd /d "C:\path\to\your\streamlit\app" REM Run the Streamlit app using the specified Python executable "C:\Python39\python.exe" -m streamlit run app.py REM Close the command prompt window after execution exit REM Change to the directory containing your Streamlit app cd /d "C:\path\to\your\streamlit\app" REM Run the Streamlit app using the specified Python executable "C:\Python39\python.exe" -m streamlit run app.py REM Keep the command prompt open after execution pause path - C:\Windows\System32\cmd.exe C:\path\to\your\batchfile Step 4: Configure the Service Using NSSM GUI Path : In the Application tab, for the Path field, browse to your cmd.exe executable, typically located at C:\Windows\System32\cmd.exe . Startup Directory : Set...

Step-by-Step Guide for Offline Installation of python packages

  Step-by-Step Guide for Offline Installation of Dash Step 1: Download All Required Packages and Dependencies Download Packages on an Online Machine : sh Copy code mkdir dash_packages pip download -d dash_packages dash This command downloads the dash package and all its dependencies into the dash_packages directory. Step 2: Transfer Packages to the Offline Environment Transfer the dash_packages Directory : Use a USB drive, external hard drive, or any other method to copy the dash_packages directory to the offline environment. Step 3: Install Packages in the Offline Environment Install Packages Using pip : sh Copy code pip install --no-index --find-links=dash_packages dash This command tells pip to install the dash package and its dependencies from the local dash_packages directory instead of looking for them online. Handling Complex Dependencies In some cases, a package may have very complex dependencies. Here’s how you can ensure all dependencies are captured: Use pip wit...