Skip to content

Instantly share code, notes, and snippets.

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 / gist:f28ae2940c7ef08aa6bb
Last active November 16, 2017 14:00
EF DbContext setup/teardown for tests
[TestFixture]
public class FooController_Tests
{
FooDbContext _dbContext = new FooDbContext(@"SERVER=(localdb)\v11.0; DATABASE=FooControllerTests_"+ Guid.NewGuid().ToString("n"));
[TestFixtureSetUp]
public void Setup()
{
_dbContext.Database.CreateIfNotExists();
}
@duncansmart
duncansmart / ios-sms.sql
Created September 25, 2014 12:29
Query to extract iOS Messages from backup
-- Do a backup to iTunes and open "%APPDATA%\Apple Computer\MobileSync\Backup\*\3d0d7e5fb2ce288813306e4d4636395e047a3d28" as a SQLite database
SELECT chat.chat_identifier, message.is_from_me, datetime(message.date + 978307201, 'unixepoch') as date, message.text
FROM chat
JOIN chat_message_join on chat.ROWID = chat_message_join.chat_id
JOIN message on message.ROWID = chat_message_join.message_id
order by message.date
@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()
@duncansmart
duncansmart / icloud-reminders-as-text.js
Created April 23, 2015 10:59
Get iCloud Reminders as text
[].map.call(document.querySelectorAll('iframe[name=reminders]')[0].contentDocument.querySelectorAll('.reminder-not-completed-view .reminder-row .reminder-title'), function(el) {
return el.textContent;
}).join('\r\n');
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 / PrecompileWebApp.cs
Created January 21, 2016 10:33
How to ensure a an ASP.NET web app is fully compiled at startup
using System;
using System.Web;
// ...
namespace Foo
{
public class MyWebApp : System.Web.HttpApplication
{
protected void Application_Start()
{
var cbm = new System.Web.Compilation.ClientBuildManager(HttpRuntime.AppDomainAppId, null);
:: tracks all branches for a remote e.g. `git branch --track origin/foo foo`
:: based on info from http://stackoverflow.com/questions/67699/clone-all-remote-branches-with-git
git branch -r | for /f "delims=/ tokens=1,*" %%A IN ('find "origin/"') do (
@git branch --track %%A/%%B %%B
)
@duncansmart
duncansmart / env.aspx
Created April 12, 2016 17:59
Dump server environment variables
<%@ Page Language="C#" %>
<ul>
<% foreach (DictionaryEntry item in Environment.GetEnvironmentVariables()) { %>
<li><%:item.Key%>: <code><%:item.Value%></code></li>
<%}%>
<ul>