Skip to content

Instantly share code, notes, and snippets.

View dampee's full-sized avatar

Damiaan dampee

View GitHub Profile
@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 / 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 / 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 / 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 / gist:a77654eef93df7322753
Created April 14, 2015 15:11
create umbraco macro with custom properties
// Using old namespace to create Macro, since Umbraco.Core.Models.Macro is still an internal class in Umbraco V7.1.8
var macro = new Macro.Macro { Alias = alias, Name = name, ScriptingFile = scriptingFile, UseInEditor = useInEditor, RenderContent = renderContent };
macro.Save();
var newMacro = Services.MacroService.GetByAlias(alias);
foreach (var macroProperty in macroProperties)
{
newMacro.Properties.Add(macroProperty);
}
Services.MacroService.Save(newMacro);
### Keybase proof
I hereby claim:
* I am dampee on github.
* I am damiaan (https://keybase.io/damiaan) on keybase.
* I have a public key whose fingerprint is 8916 1EB8 0874 7B83 C747 A50C 09B2 0515 7944 DF39
To claim this, I am signing this object:
@dampee
dampee / ContentServiceTests.SortOrder.cs
Created June 11, 2015 13:04
Sort Order check after Content Delete unit test (U4-6642)
[Test]
public void Delete_SortOrder_Is_Correct()
{
// Arrange
var contentService = ServiceContext.ContentService;
var root = contentService.GetById(NodeDto.NodeIdSeed + 4);
var contentType = ServiceContext.ContentTypeService.GetContentType("umbTextpage");
var contentList = CreateChildrenOf(contentType, root, 3);
contentService.Save(contentList);
@dampee
dampee / ImagesApiController.cs
Last active March 2, 2020 18:34
Resave all images. After an umbraco Upgrade from 6 to 7 you might have empty .URL's when using the image cropper. Resave all images by calling this API endpoint once.
using System.Web.Http;
using System.Collections.Generic;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi;
namespace Our.Umbraco
{
public class UpgradeHelperController : UmbracoAuthorizedApiController
{
[HttpGet()]
@dampee
dampee / umbraco db cleanup.sql
Last active November 9, 2021 12:57
Umbraco Database cleanup. After pulling in an umbraco database from production, you don't need all history or log.
-- Umbraco Clear Old Document Versions To Decrease Database Size And Improve Performance
-- http://borism.net/2008/12/16/fixing-a-large-cmspropertydata-table-in-umbraco/
DECLARE @createdDate Datetime = DATEADD(m, -1, getdate())
-- dump logs
-- TRUNCATE TABLE umbracolog -- faster if log table is very big and you don't need anything
DELETE FROM umbracolog WHERE Datestamp < @createdDate
-- clean up old versions
DELETE FROM cmsPropertyData WHERE
@dampee
dampee / umbracoTraceLog.txt
Created February 15, 2016 13:54
log after clean install of umbraco 7.4 using nuget
2016-02-15 14:52:56,906 [P1364/D2/T1] INFO Umbraco.Core.CoreBootManager - Umbraco 7.4.0 application starting on DESKTOP-JJOR4ST
2016-02-15 14:52:56,927 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Determining hash of code files on disk
2016-02-15 14:52:56,934 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Hash determined (took 7ms)
2016-02-15 14:52:56,973 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Starting resolution types of umbraco.interfaces.IApplicationStartupHandler
2016-02-15 14:52:57,129 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Completed resolution of types of umbraco.interfaces.IApplicationStartupHandler, found 0 (took 156ms)
2016-02-15 14:52:57,138 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Starting resolution types of Umbraco.Core.PropertyEditors.IPropertyEditorValueConverter
2016-02-15 14:52:57,145 [P1364/D2/T1] INFO Umbraco.Core.PluginManager - Completed resolution of types of Umbraco.Core.PropertyEditors.IPropertyEditorValueConverter, found 0 (took 6ms)
2016-02