Skip to content

Instantly share code, notes, and snippets.

View dampee's full-sized avatar

Damiaan dampee

View GitHub Profile
@dampee
dampee / ReCaptcha.cs
Created March 19, 2015 15:00
recaptcha v2
using System.Collections.Generic;
using System.Web;
using Newtonsoft.Json;
/// <summary>
/// Captcha helper
/// </summary>
/// <remarks>
/// Original http://stackoverflow.com/questions/27764692/validating-recaptcha-2-no-captcha-recaptcha-in-asp-nets-server-side
/// </remarks>
@dampee
dampee / SearchController.cs
Last active August 29, 2015 14:17
Simple full text search in Umbraco
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace Controllers
{
/// <summary>
@dampee
dampee / filesize.cs
Created March 16, 2015 14:51
formats a number as filesize with GB, MB, KB or bytes
public class FileSize
{
public static string FormatBytes(string bytes, int scale = 1024)
{
long bytesNumber = Convert.ToInt64(bytes);
return FormatBytes(bytesNumber, scale);
}
public static string FormatBytes(long bytes, int scale = 1024)
@dampee
dampee / gist:b276deb7ddd889be9542
Created September 4, 2014 19:46
OEmbed for slideshare
// uses Newtonsoft Json
var slideshareOembedUrl = "http://www.slideshare.net/api/oembed/2?url=" + urlToRender + "&maxwidth=800&maxheight=400&format=json";
var wc = new WebClient();
var json = wc.DownloadString(slideshareOembedUrl);
var jsonObject = JObject.Parse(json);
return jsonObject.Property("thumbnail").Value.ToString();
@dampee
dampee / LastChance404Finder
Last active October 14, 2015 15:58
Umbraco ContentLastChanceFinder for 404 pages
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
@dampee
dampee / CreateNewAdminUser
Created August 4, 2014 15:26
Create a new admin user in umbraco
/// 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 / LoremIpsumBuilder.cs
Created July 3, 2014 18:42
Lorem ipsum generator in c#
/// <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 / gist:4b4fb227a86ce64e4155
Created June 13, 2014 11:09
example segment provider
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 / gist:8165323
Created December 28, 2013 23:00
XPATH: Get All documents of type X and Y
var joinedDoctypes = Umbraco.TypedContentAtXPath("//*[self::DocType1 or self::DocType2]")
// http://stackoverflow.com/questions/721928/xpath-to-select-multiple-tags
@dampee
dampee / MultiNodeTreePickerPropertyEditorValueConverter.cs
Last active January 1, 2016 05:39
Umbraco MultiNodeTreePicker PropertyEditorValueConverter
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;