Friday 20 March 2020

Best Practices for Personal Productivity


Best Practices for Personal Productivity:

  1. Structure your day like you would in the office: When working from home, you're your own personal manager. Without things like an in-person meeting schedule to break up your day, you can be quick to lose focus or burn out. To stay on schedule, segment what you'll do and when for the day. 
  2. Choose a dedicated workspace: Just because you're not working at an office doesn't mean you can't, well, have an office. Rather than cooping yourself up in your room or on the couch -- spaces that are associated with leisure time -- dedicate a specific room or surface in your home to work.
  3. Your calendar is sacred: Set timers for food breaks, leisure walks, time off, family obligations, etc. Call out good work! Do this more often than usual and with consistency. Start your meetings with kudos.
  4. Make it harder for yourself to mess around on social media: Social media is designed to make it easy for you to open and browse quickly. At work, though, this convenience can be the detriment of your productivity. To counteract your social networks' ease of use during work hours, remove them from your browser shortcuts and, according to Fast Company, log out of every account. You might even consider working primarily in a private or if you're using Chrome, an "Incognito" browser window. This ensures you stay signed out of all your accounts and each web search you conduct doesn't autocomplete the word you're typing. It's a guarantee that you won't be tempted into taking too many social breaks during the day.
  5. Commit to doing more: Projects always take longer than you initially think they will. For that reason, you'll frequently get done less than you set out to do. So, just as you're encouraged to overestimate how much time you'll spend doing one thing, you should also overestimate how many things you'll do during the day. Even if you come up short of your goal, you'll still come out of that day with a solid list of tasks filed under 'complete.'
  6. Work when you're at your most productive: Nobody sprints through their work from morning to evening -- your motivation will naturally ebb and flow throughout the day. When you're working from home, however, it's all the more important to know when those ebbs and flows will take place and plan your schedule around it.
    To capitalize on your most productive periods, save your harder tasks for when you know you'll be in the right headspace for them. Use slower points of the day to knock out the easier, logistical tasks that are also on your plate. Verily Magazine calls these tasks "small acts of success," and they can help build your momentum for the heavier projects that are waiting for you later on.
  7. Communicate expectations with anyone who will be home with you: Of course, you might be working from home but still have "company." Make sure any roommates, siblings, parents, spouses, etc. respect your space during work hours. Just because you're working from home doesn't mean you're home.
  8. Take clear breaks: It can be so easy to get distracted as a telecommuter that you avoid breaks altogether. Don't let the guilt of working in the building you sleep in prevent you from taking five to relax. Rather than just opening YouTube and watching some comfort clips, however, use your breaks to get away from your desk. Go for a walk outside or spend time with others who might also be in the house.
  9. Eat on time, eat healthy, stay hydrated: Set timelines for this on your calendar so you’re not skipping meals. Hydrate. Stretch every 30 minutes. Hydrate. Have strict timelines on when you eat. 
  10. Prepare your meals the night before: When you're in your own home, it can be tempting to spend time preparing a really nice breakfast and lunch for yourself, chopping and cooking included. Don't use precious minutes making your food the day of work -- cook it the night before.
    Preparing food ahead of time ensures you can actually use your meal times to eat, and that you aren't performing non-work tasks that spend energy better used at your desk.
  11. Pick a definitive finishing time each day: You might be under the impression that working from home establishes more work-life balance, but be careful with that assumption. Working from home can also feel confusing -- you can get so caught up in your activity, in a relaxing environment, that you lose complete track of time.
  12. Call out good work! : Do this more often than usual and with consistency. Start your meetings with kudos.

Wednesday 18 March 2020

Web API authentication using certificate

RestSharp Example:




Get Example 
NameSpace

using RestSharp;

public IRestResponse GetExample(string URL)
{

var client = new RestClient(URL);
var request = new RestRequest(Method.GET);
//Add Header value
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
IRestResponse response = client.Execute(request);
return response;
}

Get Example  With Certificate 
public IRestResponse GetExampleWithCertificate(string URL)
{

var client = new RestClient(URL);
var request = new RestRequest(Method.GET);
//Add Header value
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
  X509Certificate2 certificate = new X509Certificate2();
 certificate.Import(System.Web.Hosting.HostingEnvironment.MapPath("Cerficate"), "", X509KeyStorageFlags.MachineKeySet);
                client.ClientCertificates = new X509CertificateCollection() { certificate };
IRestResponse response = client.Execute(request);

 SecurityProtocolType securityProtocols = ServicePointManager.SecurityProtocol;
            if (securityProtocols.HasFlag(SecurityProtocolType.Ssl3) || securityProtocols.HasFlag(SecurityProtocolType.Tls) || securityProtocols.HasFlag(SecurityProtocolType.Tls11))
            {
                securityProtocols &= ~(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11);
                if (securityProtocols == 0)
                {
                    securityProtocols |= SecurityProtocolType.Tls12;
                }
                ServicePointManager.SecurityProtocol = securityProtocols;
            }
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
IRestResponse response = client.Execute(request);
return response;
}



Post Example

public IRestResponse PostExample(string URL)
{

var client = new RestClient(URL);
var request = new RestRequest(Method.Post);
//Add Header value
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
//Post Json
request.AddParameter("application/json", Requestjson, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
return response;
}

Get Example  With Certificate 
public IRestResponse PostExampleWithCertificate(string URL)
{

var client = new RestClient(URL);
var request = new RestRequest(Method.Post);
//Add Header value
request.AddHeader("Cache-Control", "no-cache");
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/json");
//Post Json
request.AddParameter("application/json", Requestjson, ParameterType.RequestBody);
// Add Certificate
  X509Certificate2 certificate = new X509Certificate2();
 certificate.Import(System.Web.Hosting.HostingEnvironment.MapPath("Cerficate"), "", X509KeyStorageFlags.MachineKeySet);
                client.ClientCertificates = new X509CertificateCollection() { certificate };
IRestResponse response = client.Execute(request);

 SecurityProtocolType securityProtocols = ServicePointManager.SecurityProtocol;
            if (securityProtocols.HasFlag(SecurityProtocolType.Ssl3) || securityProtocols.HasFlag(SecurityProtocolType.Tls) || securityProtocols.HasFlag(SecurityProtocolType.Tls11))
            {
                securityProtocols &= ~(SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11);
                if (securityProtocols == 0)
                {
                    securityProtocols |= SecurityProtocolType.Tls12;
                }
                ServicePointManager.SecurityProtocol = securityProtocols;
            }
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
IRestResponse response = client.Execute(request);
return response;
}

Sunday 15 March 2020

sqlcmd - Run Transact-SQL Script Files

Run the script file

  • Open a command prompt window.
  • In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql
  • Press ENTER.


Save the output to a text file

  • Open a command prompt window.
  • In the Command Prompt window, type: sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt
  • Press ENTER.
Run the script file with the Database username and password

  • Open a command prompt window.
  • In the Command Prompt window, type: SQLCMD -S <DBServerName> -U <DBUserName> -P <DBPassword> -d <DBName> -i C:\myScript.sql -o C:\EmpAdds.txt
  • Press ENTER.
sqlcmd Utility Syntax

sqlcmd   

  •    -a packet_size  
  •    -A (dedicated administrator connection)  
  •    -b (terminate batch job if there is an error)  
  •    -c batch_terminator  
  •    -C (trust the server certificate)  
  •    -d db_name  
  •    -e (echo input)  
  •    -E (use trusted connection)  
  •    -f codepage | i:codepage[,o:codepage] | o:codepage[,i:codepage] 
  •    -g (enable column encryption) 
  •    -G (use Azure Active Directory for authentication)
  •    -h rows_per_header  
  •    -H workstation_name  
  •    -i input_file  
  •    -I (enable quoted identifiers)  
  •    -j (Print raw error messages)
  •    -k[1 | 2] (remove or replace control characters)  
  •    -K application_intent  
  •    -l login_timeout  
  •    -L[c] (list servers, optional clean output)  
  •    -m error_level  
  •    -M multisubnet_failover  
  •    -N (encrypt connection)  
  •    -o output_file  
  •    -p[1] (print statistics, optional colon format)  
  •    -P password  
  •    -q "cmdline query"  
  •    -Q "cmdline query" (and exit)  
  •    -r[0 | 1] (msgs to stderr)  
  •    -R (use client regional settings)  
  •    -s col_separator  
  •    -S [protocol:]server[instance_name][,port]  
  •    -t query_timeout  
  •    -u (unicode output file)  
  •    -U login_id  
  •    -v var = "value"  
  •    -V error_severity_level  
  •    -w column_width  
  •    -W (remove trailing spaces)  
  •    -x (disable variable substitution)  
  •    -X[1] (disable commands, startup script, environment variables, optional exit)  
  •    -y variable_length_type_display_width  
  •    -Y fixed_length_type_display_width  
  •    -z new_password   
  •    -Z new_password (and exit)  
  •    -? (usage) 



Wednesday 4 March 2020

Corona virus - COVID-19

कोरोना वायरस साइज में बड़ा होता है जिसका साइज 400-500 माइक्रोन का होता है, इसलिए ये नार्मल मास्क से भी रुक जाता है इसके लिए किसी खास मास्क की ज़रूरत नहीं है.

ये वायरस हवा में नही तैरता पर ज़मीन पर ज़िंदा रहता है, किसी भी तरह के मेटल पर ये 12 घंटे ज़िंदा रहता है, इसलिए हाथ को साबुन से धोते रहें!

ये कपड़ो पर 9 घंटे ज़िंदा रहता है तो इसलिए कपड़ो को रोज़ धोएं और धूप में सुखाये, 2 घण्टे धूप लगाये.

हाथों पे ये 10 मिनट ज़िंदा रहता है तो अल्कोहल वाला sanitizer उसे करें.

ये 26-27℃ से ज़्यादा का तापमान नहीं झेल पाता इसलिए धूप में ज़रूर जाएं और गरम पानी की गरारे करें ये मुँह में ही मर जायेगा, और फेफड़ों में नहीं जाएगा.

ठंडी चीज़े, icecream वगैरह ना खाएं.

इन् सब चीजों को धयान रख कर कोरोना से काफी हद तक बचा जा सकता है!

सुरक्षा टिप्स: 

१. हाथ के बजाये अपनी कोहनी, कन्धों का प्रयोग दरवाजों को खोलने और बंद करने के लिए करें
२. नमस्कार करें . हैंडशेक न करें.
३. अपनी नाक, आँख, और मुंह को अपने हाथ से न छुएँ (आप लगभग १०० x बार दिन भर में अपना हाथ मुंह पर ले जाते है)
४. ६०% से अधिक अल्कोहल वाले sanitizer की शीशी अपने जेब में ले कर चलें. जब भी कुछ छुएं हाथ साफ़ कर लें
५. मास्क वायरस से बचने के लिए नहीं है, बल्कि आप को अपने मुंह को छूने से रोकने के लिए पहने.
६. यह वायरस हवा में नहीं होगा. बल्कि खासने और छीकने पर उसके छीटों में होगा. यदि आप खांस रहे हैं तो डिस्पोजेबल टिश्यू का प्रयोग करें
७. और यदि कोई खांस रहा है तो उससे कुछ दूर रहे.
८. यह वायरस आपके फेफड़ों के सेल् को ही affect करता है. इसलिए यह केवल आपके हाँथ के द्वारा आपके नाक या मुहं से होता हुआ फेफड़ों में जाएगा या यदि कोई व्यक्ति आपके नाक या मुंह पर सीधे खांसे या छीक दे तब जायेगा .
९. जिंक Lozenges ले कर रख लें और जब गले या फेफड़ों में कुछ अजीब सा लगे तो उसे पीठ के बल लेट कर मुंह के एक दम पीछे वाले हिस्से में रख कर चूसें
१० अपना गला सूखने न दें. हर १० / १५ मिनट में पानी का सिप लेते रहे.
११ आपको कोरोना वायरस है की नहीं - जानने के लिये गहरी सांस लें और १० सेकंड के लिए सांस रोक लें. यदि आपको खांसी नहीं आये, सीने में कुछ भारीपन न हो, discomfort न  हो तो समझिये की आपको कोरोना नहीं है. रोज़ चेक करें

Tuesday 31 December 2019

SQL Query Table Name with Rows Counts


SELECT
    TableName = t.NAME,
    TableSchema = s.Name,
    RowCounts = p.rows
FROM
    sys.tables t
INNER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN     
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
WHERE
    t.is_ms_shipped = 0

GROUP BY
    t.NAME, s.Name, p.Rows
ORDER BY
    s.Name, t.Name 

Monday 16 December 2019

SQL Performance Report Queries

--Query 1: logical reads

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_reads DESC -- logical reads

--Query 2: logical writes

SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_logical_writes DESC -- logical writes

--Query 3: CPU time
SELECT TOP 10 SUBSTRING(qt.TEXT, (qs.statement_start_offset/2)+1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(qt.TEXT)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2)+1),
qs.execution_count,
qs.total_logical_reads, qs.last_logical_reads,
qs.total_logical_writes, qs.last_logical_writes,
qs.total_worker_time,
qs.last_worker_time,
qs.total_elapsed_time/1000000 total_elapsed_time_in_S,
qs.last_elapsed_time/1000000 last_elapsed_time_in_S,
qs.last_execution_time,
qp.query_plan
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
ORDER BY qs.total_worker_time DESC -- CPU time

--Query 4: Missing Index

SELECT  
dm_mid.database_id AS DatabaseID, 
dm_migs.avg_user_impact*(dm_migs.user_seeks+dm_migs.user_scans) Avg_Estimated_Impact, 
dm_migs.last_user_seek AS Last_User_Seek, 
OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) AS [TableName], 
'CREATE INDEX [IX_' + OBJECT_NAME(dm_mid.OBJECT_ID,dm_mid.database_id) + '_' 
+ REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.equality_columns,''),', ','_'),'[',''),']','')  
+ CASE 
WHEN dm_mid.equality_columns IS NOT NULL 
AND dm_mid.inequality_columns IS NOT NULL THEN '_' 
ELSE '' 
END 
+ REPLACE(REPLACE(REPLACE(ISNULL(dm_mid.inequality_columns,''),', ','_'),'[',''),']','') 
+ ']' 
+ ' ON ' + dm_mid.statement 
+ ' (' + ISNULL (dm_mid.equality_columns,'') 
+ CASE WHEN dm_mid.equality_columns IS NOT NULL AND dm_mid.inequality_columns  
IS NOT NULL THEN ',' ELSE 
'' END 
+ ISNULL (dm_mid.inequality_columns, '') 
+ ')' 
+ ISNULL (' INCLUDE (' + dm_mid.included_columns + ')', '') AS Create_Statement 
FROM sys.dm_db_missing_index_groups dm_mig 
INNER JOIN sys.dm_db_missing_index_group_stats dm_migs 
ON dm_migs.group_handle = dm_mig.index_group_handle 
INNER JOIN sys.dm_db_missing_index_details dm_mid 
ON dm_mig.index_handle = dm_mid.index_handle 
WHERE dm_mid.database_ID = DB_ID() 
ORDER BY Avg_Estimated_Impact DESC 
GO
--Query 5: Query Time Execution
SELECT   
    qs.total_elapsed_time / qs.execution_count / 1000000.0 AS average_seconds, 
    qs.total_elapsed_time / 1000000.0 AS total_seconds, 
    qs.execution_count, 
    SUBSTRING (qt.text,qs.statement_start_offset/2,  
         (CASE WHEN qs.statement_end_offset = -1  
            THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2  
          ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) AS individual_query, 
    o.name AS object_name, 
    DB_NAME(qt.dbid) AS database_name 
FROM sys.dm_exec_query_stats qs 
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as qt 
    LEFT OUTER JOIN sys.objects o ON qt.objectid = o.object_id 
WHERE qt.dbid = DB_ID() 
ORDER BY average_seconds DESC;

----------Query 6: AvgIo
SELECT 
creation_time
, last_execution_time
, total_logical_reads AS [LogicalReads] , total_logical_writes AS [LogicalWrites] , execution_count
, total_logical_reads+total_logical_writes AS [AggIO] , (total_logical_reads+total_logical_writes)/(execution_count+0.0) AS [AvgIO] , st.TEXT
, DB_NAME(st.dbid) AS database_name
, st.objectid AS OBJECT_ID
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(sql_handle) st
WHERE total_logical_reads+total_logical_writes > 0
AND sql_handle IS NOT NULL
ORDER BY [AggIO] DESC

Upload valid file in C#

    protected bool CheckFileExtandLength(HttpPostedFile HtmlDocFile)     {         try         {             Dictionary<string, byte[]>...