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 / Animal.cs
Created March 27, 2015 10:28
Example of GetType, typeof and "is".
class Animal { }
class Dog : Animal { }
void PrintTypes(Animal a) {
print(a.GetType() == typeof(Animal)) // false
print(a is Animal) // true
print(a.GetType() == typeof(Dog)) // true
}
Dog spot = new Dog();
@csharpforevermore
csharpforevermore / UmbracoMediaRenderMacro.xslt
Created March 27, 2015 09:58
Render Umbraco media item
<umbraco:Macro runat="server" language="cshtml">
<img src="@Library.MediaById(Model.YourPropertyAlias).umbracoFile" alt"@Library.MediaById(Model.YourPropertyAlias).nodeName">
</umbraco:Macro>
@csharpforevermore
csharpforevermore / 3col.css
Created March 18, 2015 10:44
Make 3 columns out of UL LI elements
ul#school-location-list {
display: block;
font-size: 0;
}
li {
display: inline-block;
width: 33.333%; /* if you have a margin, subtract from this */
font-size: 13px;
}
@csharpforevermore
csharpforevermore / MyCompilerClass.cs
Created March 15, 2015 21:17
Find all instances of an interface within a loaded assembly
namespace PrimaryAssembly
{
using System;
using System.Linq;
using System.Reflection;
class MyCompilerClass
{
public MyCompilerClass()
{
@csharpforevermore
csharpforevermore / AddToCache.cs
Created January 23, 2015 14:02
Example of caching an object in c#
string key = GetClickTrackerCacheKey(clickTrackerReportQueryParameters);
Cache cache = HttpRuntime.Cache;
if (cache[key] == null)
{
clickTrackerReport = CreateRenderModelValue(clickTrackerReportQueryParameters, clickTrackerReport);
cache.Add(key, clickTrackerReport, null,
DateTime.Now.AddMinutes(Utility.ReadConfigurationSetting("DataCacheTime", 0)), TimeSpan.Zero,
CacheItemPriority.Normal, null);
}
@csharpforevermore
csharpforevermore / PaginationHelper.cs
Created January 23, 2015 11:38
Get number of results per page
public static class PaginationHelper
{
public static int GetPageCount(int records, int recordsPerPage)
{
//int pageCount1 = (records + recordsPerPage - 1) / recordsPerPage; // original solution
int pageCount2 = (records - 1) / recordsPerPage + 1; // simplified version of pageCount1
return pageCount2;
}
@csharpforevermore
csharpforevermore / DateTimeToFromTicksParser.cs
Created January 22, 2015 13:06
Parse date time to or from ticks
public class DateTimeToFromTicksParser
{
public static long ConvertDateTimeToTicks(DateTime dtInput)
{
long ticks = dtInput.Ticks;
return ticks;
}
public static DateTime ConvertTicksToDateTime(long lticks)
{
@csharpforevermore
csharpforevermore / ConsoleApplication.cs
Created January 20, 2015 15:31
Custom web.config appSettings sections. can have multiple custom config sections in web.config
using System.Collections.Specialized;
using System.Configuration;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
NameValueCollection settings = (NameValueCollection)ConfigurationManager.GetSection("myAppSettingsGroup");
@csharpforevermore
csharpforevermore / CustomGlobal.cs
Created January 12, 2015 04:20
Custom Global.asax.cs for Umbraco 7
public class CustomGlobal : UmbracoApplication
{
public void Init(HttpApplication application)
{
application.PreRequestHandlerExecute += application_PreRequestHandlerExecute;
application.BeginRequest += this.Application_BeginRequest;
application.EndRequest += this.Application_EndRequest;
application.Error += Application_Error;
}