Skip to content

Instantly share code, notes, and snippets.

View sotirisf's full-sized avatar

Sotiris Filippidis sotirisf

View GitHub Profile
@sotirisf
sotirisf / Comma Delimited List from IPublishedContent IDs
Last active August 29, 2015 14:15
Create a comma-delimited list from an IEnumerable collection of Umbraco IPublishedContent Ids
var storedVal = content.Aggregate<IPublishedContent, StringBuilder, string>(
new StringBuilder()
, (sb, x) => sb.Append(x.Id).Append((content.Last().Id==x.Id) ? "" : ",")
, (sb) => sb.ToString()
);
@sotirisf
sotirisf / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@sotirisf
sotirisf / Update Querystring Parameter
Last active August 29, 2015 14:15
Updates a querystring parameter with a new value
/// <summary>
/// Updates a querystring parameter with a new value
/// </summary>
/// <param name="req">The HTTPRequest object</param>
/// <param name="parameterName">The parameter name to update</param>
/// <param name="parameterValue">The new value for the parameter</param>
/// <returns></returns>
public static string UpdateQueryString(HttpRequest req, string parameterName, string parameterValue)
{
@sotirisf
sotirisf / Match at least one element from a comma delimited string with a second comma delimited string
Last active August 29, 2015 14:15
Compares two comma delimited strings in order to find at least one matching element (an element both strings contain)
/// <summary>
/// Compares two comma delimited strings in order to find at least one matching element
/// </summary>
/// <param name="sourceElements">The first comma delimited string</param>
/// <param name="searchElements">The second comma delimited string</param>
/// <returns>True if there is at least one match</returns>
public static bool MatchesAtLeastOne(this string sourceElements, string searchElements)
{
if (string.IsNullOrEmpty(sourceElements) || string.IsNullOrEmpty(searchElements)) return false;
@sotirisf
sotirisf / Parse Delimited Strings
Created February 23, 2015 19:54
UDF that gets a delimited string and returns a table variable with the values of the string as rows
CREATE Function [dbo].[fn_ParseDelimitedStrings]
(
@String nvarchar(max),
@Delimiter char(1)
)
Returns @Values Table
(
RowId int Not Null Identity(1,1) Primary Key,
Value nvarchar(3000) Not Null
)
@sotirisf
sotirisf / ContentHelper.cs
Created August 28, 2016 20:32
Umbraco Picker Extensions
using System.Web;
using Umbraco.Web;
namespace DotSee.UmbracoExtensions
{
/// <summary>
/// Helps with Umbraco content.
/// </summary>
public static class ContentHelper
{
@sotirisf
sotirisf / FixNodeswithoutTemplates.cs
Created September 6, 2017 20:47
Bulk update documents with their default template in case they have no template assigned
using System.Linq;
using System.Reflection;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace DotSee.Common
{
public class FixNodesWithoutTemplates : ApplicationEventHandler
@sotirisf
sotirisf / DotSee.ImageExtensions.cs
Created November 14, 2017 15:47
Umbraco image srcset with image cropper
using System.Linq;
using System.Text;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Web;
namespace DotSee.Common
{
public static class ImageExtensions
{
@sotirisf
sotirisf / GetDictionaryEntries.sql
Created January 12, 2018 22:57
Get Umbraco dictionary entries for all languages in a pivoted table (each language with its own column)
DECLARE @DynamicColumns NVARCHAR(MAX);
DECLARE @DynamicSQL NVARCHAR(MAX);
SELECT @DynamicColumns = COALESCE(@DynamicColumns+', ', '')+QUOTENAME(languageISOCode)
FROM
(
SELECT DISTINCT
languageISOCode
FROM umbracolanguage
) AS FieldList;
@sotirisf
sotirisf / ImageExtensions.cs
Last active February 4, 2018 15:07
Umbraco Responsive Background Images (Extension Method)
using System;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Web;
using Umbraco.Web.Models;
namespace DotSee.Common
{
public static class ImageExtensions
{