Oracle - Extract Characters from String, Extract Date from Timestamp

Extract Characters from a string in Oracle using Regular Expression
function f_extract_string(in_position in number, iv_string in varchar2) return varchar2 is    
lv_retun_value varchar2(50);
begin             
        SELECT REGEXP_SUBSTR(iv_string,'[^,]+', 1,in_position)
        into lv_retun_value
        FROM DUAL;        
        
        return lv_retun_value;        
end f_extract_string;
Extract Date from Timestamp
function f_timestamp_to_date(iv_timestamp in varchar2) return date is    
  ldte_date date;
begin    

  select to_date(trunc(to_timestamp(iv_timestamp)))
  into ldte_date
  from dual;
  
  return ldte_date;          
end f_timestamp_to_date;

Calculate Iron Condor MAX Gain in SQL Server

This is one of many functions used on MTR Investors Group to calculate option return values.
Create FUNCTION [dbo].[f_get_condor_gain_pct] 
(
 @SellStrike decimal(18,2),
 @BuyStrike decimal(18,2), 
 @PutSellPrice decimal(18,2),
 @PutBuyPrice decimal(18,2),
 @CallSellPrice decimal(18,2),
 @CallBuyPrice decimal(18,2)
)
RETURNS decimal(18,2)
AS
BEGIN
declare @GainAmount decimal(18,2);
declare @SpreadAmount decimal(18,2);

--The Option Sell > Buy - On Strikes the call side is flipped.
set @GainAmount = ((@PutSellPrice - @PutBuyPrice) + (@CallSellPrice - @CallBuyPrice)) * 100 ;
set @SpreadAmount = (@SellStrike - @BuyStrike) * 100;
if (@GainAmount = 0 or @SpreadAmount = 0) return 0;

return (@GainAmount / @SpreadAmount);

END

Run Batch Jobs In ASP.NET & IIS

I had a site running on a shared hosting server (later moved to a VM) and had the need to run a batch process controlled by C# and processing data to SQL Server.  The issue on a shared hosting environment (in most cases) is that you cannot create a scheduled job or upload a console application. I got around this by creating a Batch Job in ASP.NET using Threading. 

For long running jobs you can simply PING your site URL every so often to prevent the worker process from shutting down.

There is one gotcha with this approach. You cannot access Httpcontext.current.  This should not present an issue. I have many ASP.NET batch jobs running for downloading and processing data. 

Here is how this process is setup: 

1. Create a web page BatchProcess.aspx. When this page gets called a parameter is passed to control what batch process to start. In my case I call this web page by creating a monitor at SiteUptime.com.  If you only want the job to run at a certain time SiteUptime has blackout periods for the monitor or you can code a time stamp check to only run the job at a certain time.
switch (Job)
{
    case "update-blabla1":
        UpdateSomeData();
        break;
    case "update-blabla2":
        UpdateSomeData2();
        break;
    default:
        Response.Redirect("~/default.aspx");
        break;
}
2. Instantiated an object of the batch process class and start the job
//Create new object and start processing
MySite.Data.ProcessData Batch = new Data.ProcessData();
Batch.StartBatchProcessing();

//The StartBatchProcessing() Creates the new thread
public void StartBatchProcessing()
{    
    //ProcessMyData is the main method that will process the batch data
    Thread newThread = new Thread(this.ProcessMyData);
    newThread.Priority = ThreadPriority.Normal;
    newThread.Start();
}
3. For long running jobs you will need to PING your site or the worker process may stop if the site is idle for a while. Use the following method to call a URL on the site to keep the working process alive. 
//Pass your site URL to the following method to PING it. 
//This method can be used to pull HTML for page scraping as welll
public string GetHTML(string url)
{
    System.Net.WebClient WC = new System.Net.WebClient();
    WC.Credentials = System.Net.CredentialCache.DefaultCredentials;
    string HTML;

    try
    {
        System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
        HTML = UTF8.GetString(WC.DownloadData(url));
    }
    catch (Exception ex) {throw ex;}

    return HTML;
}