Skip to content

Instantly share code, notes, and snippets.

Avatar

Damiaan dampee

View GitHub Profile
@dampee
dampee / gist:8020337
Created Dec 18, 2013
format size as bytes, kb, mb, gb
View gist:8020337
public static string FormatBytes(long bytes, int scale = 1024)
{
string[] orders = new string[] { "GB", "MB", "KB", "Bytes" };
long max = (long)Math.Pow(scale, orders.Length - 1);
foreach (string order in orders)
{
if (bytes > max)
{
return String.Format("{0:##.##} {1}", Decimal.Divide(bytes, max), order);
@dampee
dampee / Cache.cs
Last active Dec 31, 2015
Generic http cache with locking
View Cache.cs
using System;
using System.Web;
using System.Web.Caching;
using Umbraco.Core.Logging;
/// <summary>
/// Generic cache class
/// </summary>
/// <typeparam name="T">The type of the object to be cached</typeparam>
/// <remarks>
@dampee
dampee / gist:8053121
Created Dec 20, 2013
get specific umbraco dictionary item
View gist:8053121
select d.pk, lt.pk, d.[key], lt.languageId, l.languageISOCode, lt.value
from cmsDictionary d inner join cmsLanguageText lt on d.id = lt.UniqueId
left join umbracoLanguage l on lt.languageId = l.id
where d.pk = 6
@dampee
dampee / MediaPickerPropertyEditorValueConverter.cs
Created Dec 23, 2013
Media Picker Property Editor Value Convertor - without DB hits from uQuery
View MediaPickerPropertyEditorValueConverter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Models;
using umbraco.editorControls;
using Umbraco.Web;
@dampee
dampee / MultiNodeTreePickerPropertyEditorValueConverter.cs
Last active Jan 1, 2016
Umbraco MultiNodeTreePicker PropertyEditorValueConverter
View MultiNodeTreePickerPropertyEditorValueConverter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Models;
using umbraco.editorControls;
using Umbraco.Web;
@dampee
dampee / gist:8165323
Created Dec 28, 2013
XPATH: Get All documents of type X and Y
View gist:8165323
var joinedDoctypes = Umbraco.TypedContentAtXPath("//*[self::DocType1 or self::DocType2]")
// http://stackoverflow.com/questions/721928/xpath-to-select-multiple-tags
@dampee
dampee / gist:4b4fb227a86ce64e4155
Created Jun 13, 2014
example segment provider
View gist:4b4fb227a86ce64e4155
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Strings;
@dampee
dampee / LoremIpsumBuilder.cs
Created Jul 3, 2014
Lorem ipsum generator in c#
View LoremIpsumBuilder.cs
/// <summary>
/// Lorem Ipsum Generator
/// </summary>
/// <remarks>
/// Based on Javascript Version of Marcus Campbell - Version 2.0 (Copyright 2003 - 2005)
/// Open-source code under the GNU GPL: http://www.gnu.org/licenses/gpl.txt
/// </remarks>
/// <example>
/// LoremIpsumBuilder _lib = new LoremIpsumBuilder();
/// string test = _lib.GetLetters();
@dampee
dampee / CreateNewAdminUser
Created Aug 4, 2014
Create a new admin user in umbraco
View CreateNewAdminUser
/// ApplicationBase: prior to 4.8
public class AdminUserPwdReset : ApplicationBase //: ApplicationStartupHandler
{
public AdminUserPwdReset()
{
var userTYpe = UserType.GetUserType(1); // admins
User adminUser = User.MakeNew("damiaan", "damiaan", hashPassword("default"), userTYpe);
adminUser.addApplication("users");
adminUser.addApplication("settings");
adminUser.addApplication("developer");
@dampee
dampee / LastChance404Finder
Last active Oct 14, 2015
Umbraco ContentLastChanceFinder for 404 pages
View LastChance404Finder
using System;
using System.Globalization;
using System.Linq;
using umbraco.cms.businesslogic.web;
using Umbraco.Core;
using Umbraco.Web;
using Umbraco.Web.Routing;
/// <summary>
/// Summary description for NotFoundHandler