Skip to content

Instantly share code, notes, and snippets.


Mikael Högberg mikaelnet

View GitHub Profile
mikaelnet / controller.js
Last active Aug 29, 2015
Node client for Raspberry PI Deployer
View controller.js
var argv = require('argv');
var https = require('https');
var xml2js = require('xml2js');
var inspect = require('eyes').inspector({maxLength: false});
var gpio = require('gpio');
var xmlParser = new xml2js.Parser();
var teamCityHost = 'your team city host';
mikaelnet / IPAddressExtensions
Created Apr 17, 2015
Extension methods for handling IPv4 addresses
View IPAddressExtensions
public static class IPAddressExtensions
/// <summary>
/// Tests if a given IPv4 address is within any of the private
/// IP address ranges,, or
/// </summary>
/// <param name="address"></param>
/// <returns>True if the address is private, otherwise false.
/// Note: IPv6 address always returns false</returns>
/// <exception cref="NotSupportedException">For unknown address families (other than IPv4 and IPv6)</exception>
mikaelnet / LevenshteinDistanceComputer
Created Apr 17, 2015
Computes Levenshtein Distance of two strings
View LevenshteinDistanceComputer
public static class LevenshteinDistanceComputer
public static int LevenshteinDistance(this string s, string t)
return Compute(s, t);
public static int Compute(string s, string t)
if (string.IsNullOrEmpty(s))
mikaelnet / EnumerableExtensions
Created Apr 17, 2015
Extension methods for enumerables
View EnumerableExtensions
public static class EnumerableExtensions
public static IEnumerable<T> ToEnumerable<T>(this T item, bool nullAsEmpty = true)
if (EqualityComparer<T>.Default.Equals(item, default(T)) && nullAsEmpty)
yield break;
yield return item;
public static bool None<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)
mikaelnet / Upload-MediaItems.ps1
Created Nov 19, 2015
Sitecore Powershell Image upload
View Upload-MediaItems.ps1
function Update-MediaItem {
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Parameter(Position=1, Mandatory=$true)]
mikaelnet / table-sizes.sql
Created Apr 4, 2016
List the size of all tables in database on SQL Server
View table-sizes.sql
select 'Database Name: ', db_name()
set nocount on
if exists(select name from tempdb..sysobjects where name='##tmp') drop table ##tmp
create table ##tmp(nam varchar(50), rows int, res varchar(15),data varchar(15),ind_sze varchar(15),unsed varchar(15))
declare @tblname varchar(50)
declare tblname CURSOR for select name from sysobjects where xtype='U'
open tblname
Fetch next from tblname into @tblname
mikaelnet / find-text-in-database.sql
Created Apr 5, 2016
Find a piece of text in any column in any table in a SQL Server database
View find-text-in-database.sql
DECLARE @SearchStr nvarchar (100)
SET @SearchStr = 'string to find'
CREATE TABLE #Results ( ColumnName nvarchar( 370), ColumnValue nvarchar(3630 ))
DECLARE @TableName nvarchar (256), @ColumnName nvarchar( 128), @SearchStr2 nvarchar(110 )
SET @TableName = ''
SET @SearchStr2 = QUOTENAME( '%' + @SearchStr + '%','''' )
mikaelnet / TouchItem.cs
Created Apr 15, 2019
Sitecore Touch-Item Powershell Cmdlet
View TouchItem.cs
using System.Management.Automation;
using Sitecore.Data.Items;
[OutputType(typeof(Item)), Cmdlet("Touch", "Item")]
public class TouchItem : Cmdlet
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public Item Item { get; set; }
protected override void ProcessRecord()
mikaelnet / Broken links Report.ps1
Created Aug 21, 2019
Updated Sitecore SPE Broken links Report
View Broken links Report.ps1
mikaelnet / invalid-chars-in-sitecore-fields.sql
Created Nov 26, 2019
Finds invalid characters in any Sitecore field
View invalid-chars-in-sitecore-fields.sql
SELECT ItemId, FieldId, Value FROM [SharedFields] (nolock)
SELECT ItemId, FieldId, Value FROM [UnversionedFields] (nolock)
SELECT ItemId, FieldId, Value FROM [VersionedFields] (nolock)
) A
WHERE Value Like '%' + CHAR(0x01) + '%'
OR Value Like '%' + CHAR(0x08) + '%'
OR Value Like '%' + CHAR(0x10) + '%'