Skip to content

Instantly share code, notes, and snippets.

@duncansmart
duncansmart / PdfSplitAndMerge.cs
Created February 3, 2014 13:51
Split PDFs into PDF per page (which can then be edited by InkScape) and merge
static void pdfSplitIntoPages()
{
// EO.Pdf.Runtime.AddLicense("...");
string sourceFile = @"C:\TEMP\Blah.pdf";
var pdf = new PdfDocument(sourceFile);
var pages = pdf.Split(Enumerable.Range(1, pdf.Pages.Count-1).ToArray());
var i = 1;
foreach (PdfDocument page in pages)
{
using System;
using System.Speech.Synthesis; // Add System.Speech from Add Reference
class Program
{
static void Main(string[] args)
{
Console.Write("Enter your name: ");
var name = Console.ReadLine();
@duncansmart
duncansmart / RouteUtils.cs
Last active August 29, 2015 14:08
GetRouteDataForPath: GetRouteData for a given path/URL (ASP.NET MVC)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;
public static class RouteUtils
{
/// <summary>
/// e.g. <code>var routeData = RouteTable.Routes.GetRouteDataForPath("~/foo/bar");</code>
@duncansmart
duncansmart / DotNetZipOneFile.cs
Last active August 29, 2015 14:11
Creates a single source file version of DotNetZip
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ZipReducedOneFile
{
class Program
{
static void Main()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Concurrent;
using System.Reflection;
static class ReflectionUtil
{
static ConcurrentDictionary<PropertyInfo, Func<object, object>> _propertyGettersCache = new ConcurrentDictionary<PropertyInfo, Func<object, object>>();
@duncansmart
duncansmart / IISExpress.cmd
Created March 10, 2011 15:16
IISExpress runner
:: Runs IIS Express and exits. IIS Express is kept alive by WScript.exe
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: NOTE, these are ignored if a file called IISExpress.config exists
set SITE_PORT=8080
set SITE_PATH=%~dp0
set SITE_CLR=v4.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
set IISEXPRESS=%ProgramFiles%\IIS Express\iisexpress.exe
@duncansmart
duncansmart / SortItOut.cs
Created March 30, 2011 09:00
Shows effect of culture on sorting
using System;
using System.Globalization;
using System.Threading;
class Program
{
static void Main(string[] args)
{
string[] words = "chat city cabs".Split(' ');
@duncansmart
duncansmart / CheckoutBuildAndPackage.cmd
Created April 7, 2011 19:55
A batch file that checks out a solution from SVN, builds it and packages it ready for MSDeploy.
@echo off
:: Required Config
set SVN_SOURCE=http://svnserver/svn/myrepo/mysolution
set WEB_PROJ_SUBDIR=Web
set PACKAGE_OUTPUT=C:\Builds\Packages
:: Required binaries
set SVN="%ProgramFiles(x86)%\CollabNet Subversion Client\svn.exe"
set MSBUILD="%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Diagnostics;
// Our model classes
class Person
{
public int Id { get; set; }
public FullName FullName { get; set; }
@duncansmart
duncansmart / gist:1601540
Created January 12, 2012 16:45
Dump SqlCommand
static void DumpCommand(SqlCommand command)
{
foreach (SqlParameter p in command.Parameters)
{
Debug.Write("DECLARE " + p.ParameterName + " " + p.SqlDbType.ToString().ToLower());
if (p.Size > 0)
Debug.Write("(" + p.Size + ")");
Debug.Write(" = ");
if (p.Value is Enum)
Debug.Write((int)p.Value);