Skip to content

Instantly share code, notes, and snippets.

@tekguy
tekguy / KoograRead.cs
Last active June 30, 2020 07:13
Read an excel file using Koogra
// This example shows how to read and excel file using the Koogra library (http://sourceforge.net/projects/koogra/)
// Supports .xls and .xlsx example
public static string ReadExcelContent(string filePath)
{
uint rowNum = 0;
uint colNum = 0;
var data = new StringBuilder();
try
{
@tekguy
tekguy / DeleteOldBackups.vbs
Last active December 18, 2015 11:39
VBScript to delete old .bak files from specified directory
'==============================
'Remove old backups
'http://gordondurgha.com
'=============================
'Definitions
iDaysOld = 3
strExtension = ".bak"
sDirectoryPath = "D:\MSSQL\Backups\"
@tekguy
tekguy / MyCompanySiteMapVisibilityProvider.cs
Last active January 2, 2016 17:49
Visiblity Provider for MVCSiteMapProvider 4.0
namespace MyCompany.Web
{
public class MyCompanySiteMapVisibilityProvider : MvcSiteMapProvider.SiteMapNodeVisibilityProviderBase
{
public override bool IsVisible(ISiteMapNode node, IDictionary<string, object> sourceMetadata)
{
if (node == null)
{
return true;
}
@tekguy
tekguy / LoggingOffACS.cs
Last active August 29, 2015 14:02
Logging off ACS
public ActionResult LogOff()
{
// Load Identity Configuration
FederationConfiguration config = FederatedAuthentication.FederationConfiguration;
// Get wtrealm from WsFederationConfiguation Section
string wtrealm = config.WsFederationConfiguration.Realm;
string wreply;
// Construct wreply value from wtrealm (This will be the return URL to your app)
@tekguy
tekguy / AntiForgeryTokenValidator.asp
Created July 2, 2014 16:00 — forked from lorddev/AntiForgeryTokenValidator.asp
Anti Forgery token class for classic asp
<%
' Use with a very short session (basically the page lifecycle, GET then POST)
Class AntiForgeryValidator
Private m_securityToken
Sub SetCookie()
m_securityToken = CreateWindowsGuid()
Response.Cookies("RequestVerificationToken") = m_securityToken
@tekguy
tekguy / GenerateX509Cert.sh
Last active August 29, 2015 14:03
Generate cert and private key then merge using p12
# Generate Cert and Key in seperate file
# Provide the .cert to the end user
openssl req -new -newkey rsa:1024 -days 365 -nodes -x509 -keyout QA.key -out QA.cert
# Merge cert and private key to make a p12 file, this file will be used by .NET's X509Certificate2 class, The private key will be accessible via the "PrivateKey" property
openssl pkcs12 -export -in qa.cert -inkey qa.key -out qa.p12 -name "QA"
@tekguy
tekguy / ElmahErrors.sql
Last active August 29, 2015 14:04
Elmah SQL Log Analysis
/* Useful for analyzing a Elmah logs stored in a SQL Server */
/* Version 1 */
/* --------------------------------------------------------------*/
DECLARE @StartDateTime datetime
DECLARE @EndDateTime datetime
DECLARE @HourlyThreshold int -- If error count for an hour is greater than this number display in the threshold overflow report
SET @HourlyThreshold = 10
SET @StartDateTime = DATEADD(d, -7, CAST(GETDATE() AS date))
@tekguy
tekguy / DbContextToSqlConnection.cs
Created October 23, 2014 15:19
Get a SqlConnection from a DbContext
private SqlConnection GetSqlConnection(DbContext dbContext)
{
var ec = dbContext.Database.Connection;
var adoConnStr = ec.ConnectionString;
return new SqlConnection(adoConnStr);
}
@tekguy
tekguy / XmlDocumentPrettyExtension.cs
Created November 10, 2014 18:43
An extension to prettyify your xml document with proper indentation
public static class XmlDocumentPrettyExtension
{
public static string Prettyify(this XmlDocument xmlDocument)
{
var stringWriter = new StringWriter(new StringBuilder());
var xmlTextWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented };
xmlDocument.Save(xmlTextWriter);
return stringWriter.ToString();
}
}
git config --global diff.tool bc4
git config --global difftool.bc4.path "c:/Program Files/Beyond Compare 4/bcomp.exe"
git config --global merge.tool bc4
git config --global mergetool.bc4.path "c:/Program Files/Beyond Compare 4/bcomp.exe"