Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
🏠
Working from home

Randle csharpforevermore

🏠
Working from home
View GitHub Profile
@csharpforevermore
csharpforevermore / UrlToHyperlink.cs
Created October 13, 2014 11:00
Convert URL's in a string to hyperlink anchors (<a href="#">Link</a>)
@csharpforevermore
csharpforevermore / CompletelyClearLog.bat
Created October 12, 2014 11:00
Delete all log entries from Windows Event Logs
@echo off
FOR /F "tokens=1,2*" %%V IN ('bcdedit') DO SET adminTest=%%V
IF (%adminTest%)==(Access) goto noAdmin
for /F "tokens=*" %%G in ('wevtutil.exe el') DO (call :do_clear "%%G")
echo.
echo goto theEnd
:do_clear
echo clearing %1
wevtutil.exe cl %1
goto :eof
@csharpforevermore
csharpforevermore / NotAllowedHtml.cs
Created September 26, 2014 16:14
NotAllowedHtml.cs is a data annotation addi
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Xml;
using System.Xml.Linq;
namespace CommonFunctions.Validation
{
@csharpforevermore
csharpforevermore / CheckStringEndsWithAnyArrayElement.cs
Created September 15, 2014 11:46
Check if string ends with any value in string array
public book IsValid(string fileName, string[] extensions) {
return (fileName != null && !((extensions.All(fileName.EndsWith))))
}
@csharpforevermore
csharpforevermore / Main.cs
Created August 27, 2014 12:46
Output current object. Describe it and any hierarchies it has.
public class Main
{
public static void Main()
{
var dump = ObjectDumper.Dump(user);
}
}
@csharpforevermore
csharpforevermore / changeImageSizeToQueryString.js
Last active August 29, 2015 14:05
Changes the images dimensions based on the parameters in the SRC attribute URL. In the case below, the image is 100 x 100 but needs to be sized according to the URL used (i.e. there is a server side plugin but we want a JS fallback)
function getQueryVariable(query, variable) {
if (query== '') query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
if (decodeURIComponent(pair[0]) == variable) {
return decodeURIComponent(pair[1]);
}
}
//console.log('Query variable %s not found', variable);
@csharpforevermore
csharpforevermore / GetMethodDetails.cs
Created August 22, 2014 10:58
Get current method name
System.Reflection.MethodBase currentMethod = System.Reflection.MethodBase.GetCurrentMethod();
System.Diagnostics.Debug.WriteLine(currentMethod.Name);
System.Diagnostics.Debug.WriteLine(currentMethod.DeclaringType.Name);
System.Diagnostics.Debug.WriteLine(currentMethod.DeclaringType.Namespace);
MethodBase.GetCurrentMethod().DeclaringType;
@csharpforevermore
csharpforevermore / AppSettingsWrapper.cs
Created August 1, 2014 16:47
Web.Config AppSettings wrapper for dynamic values
public class AppSettingsWrapper : DynamicObject
{
private NameValueCollection _items;
public AppSettingsWrapper()
{
_items = ConfigurationManager.AppSettings;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
@csharpforevermore
csharpforevermore / web.config
Created July 31, 2014 13:58
Add folders to your App_Code folder. This will compile any classes found in /App_Code/Extensions/
<configuration>
<system.web>
<compilation>
<codeSubDirectories>
<add directoryName="Extensions"/>
</codeSubDirectories>
</compilation>
</system.web>
</configuration>
@csharpforevermore
csharpforevermore / QueryStringParser.cs
Created July 31, 2014 13:46
Strongly typed reading of querystring collection items.
public static T GetValue<T>(this NameValueCollection collection, string key)
{
if(collection == null)
{
throw new ArgumentNullException("collection");
}
var value = collection[key];
if(value == null)