Skip to content

Instantly share code, notes, and snippets.

@murven
murven / Random_AES_Key_and_IV.cs
Created March 22, 2011 06:35
This snippet generates a random 256-bit Key and IV to be used for encryption purposes using the AES algorithm. Better when used from LINQPad.
var aesAlgorithm = new System.Security.Cryptography.AesManaged();
aesAlgorithm.GenerateIV();
aesAlgorithm.GenerateKey();
var key = aesAlgorithm.Key;
var iv = aesAlgorithm.IV;
Console.WriteLine(key.Length);
Console.WriteLine(key);
Console.WriteLine(iv.Length);
Console.WriteLine(iv);
@murven
murven / gist:902954
Created April 5, 2011 03:07
Leibniz formula for PI
let inverse x = 1.0/x
let inverseNext x = 1.0/(x+2.0)
let substractNextInverse x = inverse x - inverseNext x
let skip4List accuracy = [1.0 .. 4.0 .. accuracy]
let add a b = a + b
let inverses accuracy = (List.map substractNextInverse (skip4List accuracy))
let PI accuracy = (List.reduce add (inverses accuracy)) * 4.0
let pi10000000 = PI 10000000.0
@murven
murven / gist:1073101
Created July 8, 2011 23:47
How to check if an URI is FTP
Uri sourceBaseUri;
var isValidUri = Uri.TryCreate("ftp://somedomain.com/somefolder/someotherfolder/somefile.zip", UriKind.Absolute, out sourceBaseUri);
if(isValidUri)
{
Console.WriteLine("URI is valid");
}
if(sourceBaseUri.Scheme == Uri.UriSchemeFtp)
{
@murven
murven / DependencyObjectExtensions.cs
Created January 16, 2012 23:16
WPF - Dependency object extensions
public static class DependencyObjectExtensions
{
/// <summary>
/// Creates a new instance of the same type and copies all properties and values.
/// </summary>
/// <typeparam name="T">A type that extends DependencyObject</typeparam>
/// <param name="source"></param>
/// <returns>A new instance that represents a copy of the properties and values of the original instance.</returns>
@murven
murven / gist:a629784004ba072405f9
Created May 27, 2015 17:33
ASP.NET list all cookies
<% foreach (var key in Request.Cookies.AllKeys)
{
Response.Write(string.Format("Key:{0}|Value:{1}|\r\n", key, Request.Cookies[key].Value));
} %>
@murven
murven / Master.cshtml
Created March 8, 2016 18:52
Sitecore Master Layout
@using Sitecore.Mvc.Presentation
@using Sitecore.Mvc
@model RenderingModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
@murven
murven / vsdiffmerge.ps1
Created March 11, 2016 09:32
Visual Studio 2015 Diff Tool
& 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\vsdiffmerge' "file1.txt" "file2.txt"
@murven
murven / project.csproj
Created March 15, 2016 01:14
Include all Unicorn files in the project in a single content tag in csproj file
<Content Include="Sitecore_Data\Unicorn\Default Configuration\\**\*.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
@murven
murven / Write-Renderings.ps1
Last active April 6, 2016 22:10
Sitecore PowerShell Script to show renderings per content item
$targetFileName = 'c:\temp\ItemRenderings.txt'
function Show-Rendering
{
param ($renderingItem)
$renderingName = $renderingItem.Name
$renderingId = $renderingItem.Id
$placeholderName = $renderingItem.Placeholder
"Rendering Item: $renderingId | $renderingName | $placeholderName" | Out-File $targetFileName -Append
}
$devices = [Sitecore.Configuration.Factory]::GetDatabase("master").Resources.Devices.GetAll()
@murven
murven / project.csproj
Created April 26, 2016 15:19
Exclude files from deployment
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<ExcludeFilesFromDeployment>File1.aspx;Folder2\File2.aspx</ExcludeFilesFromDeployment>
<ExcludeFilesFromDeployment>**\.svn\**\*.*</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>Folder1;Folder2\Folder2a</ExcludeFoldersFromDeployment>
</PropertyGroup>