Skip to content

Instantly share code, notes, and snippets.

Avatar

David Tellander derantell

View GitHub Profile
@derantell
derantell / Job.cs
Last active Nov 8, 2017
EPiServer scheduled job template
View Job.cs
using EPiServer;
using EPiServer.Logging.Compatibility;
using EPiServer.PlugIn;
using EPiServer.Scheduler;
using EPiServer.ServiceLocation;
using System;
using System.Collections.Generic;
namespace <namespace> {
// The docs: http://world.episerver.com/documentation/developer-guides/CMS/scheduled-jobs/
@derantell
derantell / Logger snippet
Last active Aug 22, 2016
Visual studio snippet for EPiServer log field
View Logger snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>EPiServer class logger</Title>
<Description>Adds a static EPiServer Log logger field</Description>
<Shortcut>log</Shortcut>
</Header>
<Snippet>
@derantell
derantell / bumpversion.ps1
Last active Jun 3, 2016
Powershell semver bump function
View bumpversion.ps1
function bumpVersion {
param ( $v, $part = 'patch' )
$v -match '^(\d+)\.(\d+)\.(\d+)(.*)$' | out-null
$major, $minor, $patch, $rest = [int]$matches[1], [int]$matches[2], [int]$matches[3], $matches[4]
switch ($part) {
'major' { $major += 1; $minor = 0; $patch = 0 }
'minor' { $minor += 1; $patch = 0 }
'patch' { $patch += 1 }
@derantell
derantell / OgMetaFetcher.cs
Created Sep 9, 2015
Fetch og metadata with CsQuery
View OgMetaFetcher.cs
// Fetch meta data from a web page
// Depends on CsQuery [https://github.com/jamietre/CsQuery]
// Nuget: install-package csquery
using CsQuery;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@derantell
derantell / gist:5df4df934a1da2259f99
Last active Aug 29, 2015
Get formatted byte size from long value
View gist:5df4df934a1da2259f99
public static string FriendlyFileSize( long size) {
const double @base = 1024d;
const string format = "{0:0.#} {1}";
if (size == 0L) {
return "0 b";
}
var magnitudes = new Dictionary<int, string> {
{0, "B" }, {1, "kB"}, {2, "MB"},
@derantell
derantell / Profiler.cs
Created May 29, 2013
Simple profiler class for .Net apps.
View Profiler.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
public static class Profiler {
public static ProfilerTimer Profile(string name) {
return new ProfilerTimer(name);
}
@derantell
derantell / ProcessIndicator.cs
Created May 20, 2013
C# console process indicator
View ProcessIndicator.cs
class ProcessIndicator : IDisposable {
public ProcessIndicator(string message, int count, int step = 1, Func<string, int, int, int, string> getIndicator = null) {
_count = count;
_step = step;
_counter = 0;
_getIndicator = getIndicator ?? Bar;
Console.Write(message + " ");
}
@derantell
derantell / StringRegexExtensions
Created Feb 18, 2013
C# string extensions methods wrapping common regex tasks.
View StringRegexExtensions
public class StringRegexExtensions{
/// <summary>
/// Matches a string against a regular expression.
/// </summary>
/// <param name="self">The string self.</param>
/// <param name="pattern">The regular expression.</param>
/// <returns>True if it is match, otherwise false.</returns>
public static bool IsMatch(this string self, string pattern) {
return Regex.IsMatch(self, pattern);
@derantell
derantell / SubstringExtensions
Created Feb 18, 2013
C# substring extensions inspired by XPath's substring-before and substring-after functions.
View SubstringExtensions
public static class SubstringExtensions {
/// <summary>
/// Gets the substring after the first occurence of the specified character.
/// </summary>
/// <param name="self">The string self.</param>
/// <param name="ch">The character.</param>
/// <returns>The substring after the first occurrence of the specified character. If
/// The character does not occur in the string, the empty string is returned.</returns>
public static string SubstringAfter(this string self, char ch) {
int index = self == null ? -1 : self.IndexOf(ch);
You can’t perform that action at this time.