Skip to content

Instantly share code, notes, and snippets.

View danstuken's full-sized avatar

Dan Kendall danstuken

View GitHub Profile
@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 / 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: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: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);
public static class EntityLinqExtensions
{
public static bool None<TEntity>(this IEnumerable<TEntity> items, Func<TEntity, bool> predicate)
{
return !items.Any(predicate);
}
}
@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)
)
@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)