Skip to content

Instantly share code, notes, and snippets.

View danstuken's full-sized avatar

Dan Kendall danstuken

View GitHub Profile
@danstuken
danstuken / gist:3699804
Created September 11, 2012 16:55
Dump mvc ModelState errors to Debug console.
using System.Linq;
using System.Web.Mvc;
public static class ModelStateDictionaryExtensions
{
#if DEBUG
public static void DumpErrors(this ModelStateDictionary modelState)
{
var errors = modelState.Where(a => a.Value.Errors.Count > 0)
@danstuken
danstuken / gist:3625841
Last active February 8, 2021 11:43
Batch Convert XCF to JPEG in GIMP
(define (script-fu-xcf2jpg-batch xcfDirectory inQuality)
(let* ((xcfList (cadr (file-glob (string-append xcfDirectory "/*.xcf") 1))))
(while (not (null? xcfList) )
(let* ((xcfFilename (car xcfList))
(jpgFilename (string-append (substring xcfFilename 0 (- (string-length xcfFilename) 4) ) ".jpg"))
(xcfImage (car (gimp-file-load RUN-NONINTERACTIVE xcfFilename xcfFilename)))
(xcfDrawable (car (gimp-image-flatten xcfImage))) )
(file-jpeg-save RUN-NONINTERACTIVE xcfImage xcfDrawable jpgFilename jpgFilename
inQuality 0.0 0 0 "" 0 1 0 2)
)
public static class EntityLinqExtensions
{
public static bool None<TEntity>(this IEnumerable<TEntity> items, Func<TEntity, bool> predicate)
{
return !items.Any(predicate);
}
}
@danstuken
danstuken / gist:3517864
Created August 29, 2012 19:47
Update EF Entity
public static class EntityExtensions
{
public static void MergeChanges<TEntity>(this TEntity targetEntity, TEntity sourceEntity) where TEntity: IPersistable
{
var publicWritableProps = typeof(TEntity).GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var prop in publicWritableProps)
{
if (prop.Name != "PersistenceKey")
{
var newValue = prop.GetValue(sourceEntity, null);
@danstuken
danstuken / gist:3335235
Created August 12, 2012 23:14
Noddy templating script
#!/bin/bash
LAYOUTROOT=/put/a/directory/here
layoutName=$1
projectName=$2
[ -n "$layoutName" -a -n "${projectName}" -a -d "${LAYOUTROOT}/${layoutName}" ] && (
layout="${LAYOUTROOT}/${layoutName}"
echo "Templating from ${layout}"
@danstuken
danstuken / gist:3019205
Created June 29, 2012 16:57
Simple Powershell Drives for Git repos in a folder.
Get-ChildItem $myGitRepoPath | foreach { $rootDir = $_.FullName; $gitPath = join-path $_.FullName ".git"; $driveName = $_.BaseName.Replace('.','_'); if(test-path $gitPath){ New-PSDrive -name $driveName -psprovider FileSystem -root $rootDir } }
@danstuken
danstuken / gist:2352702
Created April 10, 2012 16:37
Trap Backspace to prevent dialog closing.
function portfolioEditorDialogdialogRequestedHandler() {
$(document).bind('keydown', function (event) {
if (event.which == 8) {
var target = $(event.target);
if (!target.is('input'))
event.preventDefault();
}
});
}
@danstuken
danstuken / nancymodule.dotsettings
Created February 14, 2012 16:12
Quick Resharper template for NancyFX module.
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=5F96955EB47AE94FA37A304345ABFE15/@KeyIndexDefined">True</s:Boolean>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=5F96955EB47AE94FA37A304345ABFE15/Description/@EntryValue">Nancy Module</s:String>
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=5F96955EB47AE94FA37A304345ABFE15/Text/@EntryValue">&#xD;
namespace $NAMESPACE$&#xD;
{&#xD;
using Nancy;&#xD;
&#xD;
public class $NEW_MODULE$ : NancyModule&#xD;
{&#xD;
@danstuken
danstuken / from_svn_to_git.sh
Created January 27, 2012 11:37
Very simple script to import from svn repos to an initialised central git repo.
#!/bin/bash
usage()
{
echo "Usage: $0 <svn_url> <git_url> <svn_authorsfile> [--branches]"
exit 1
}
create_svn_fetch_dir()
{
@danstuken
danstuken / gist:1334293
Created November 2, 2011 17:26
Umbraco Fuzzy Search
var toSearchForm = searchTerm.Split(' ');
var searcher = ExamineManager.Instance.SearchProviderCollection["SiteQuickSearchSearcher"];
var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);
var fieldsToSearch = new[]
{
"nodeName", "pageTitle", "menuText", "pageBody", "metaKeywords",
"metaDescription"
};