Skip to content

Instantly share code, notes, and snippets.

@tonysneed
tonysneed / Mac OS X: Open in Visual Studio Code
Last active March 27, 2024 10:02
Add a command to Finder services in Mac OSX to open a folder in VS Code
- Open Automator
- File -> New -> Service
- Change "Service Receives" to "files or folders" in "Finder"
- Add a "Run Shell Script" action
- Change "Pass input" to "as arguments"
- Paste the following in the shell script box: open -n -b "com.microsoft.VSCode" --args "$*"
- Save it as something like "Open in Visual Studio Code"
@anthonyvscode
anthonyvscode / UnitOfWork.cs
Last active December 31, 2015 14:08
DbEntityValidationException with useful message returned for logging to Elmah.
public void Save()
{
try
{
context.SaveChanges();
}
catch(DbEntityValidationException ex)
{
var errorMessages = (from eve in ex.EntityValidationErrors
let entity = eve.Entry.Entity.GetType().Name
@lukencode
lukencode / octobuild.build
Created February 7, 2013 03:22
Octopack build script
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<DeployFiles>$(MSBuildStartupDirectory)\DeployFiles.msbuild</DeployFiles>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>0</VersionPatch>
<ChangesetNumber>0</ChangesetNumber>
<NugetFileShare>\\itsmanv01\Releases</NugetFileShare>
@lukencode
lukencode / ListDiff.cs
Last active October 11, 2015 23:28
Quick class for determining changes (additions, removals) in lists
public static class ListDiff
{
public static List<ListDiffItem<T>> GetDiff<T>(List<T> oldList, List<T> newList, Func<T, T, bool> equalsFunction = null)
{
var combined = new List<ListDiffItem<T>>();
foreach(var i in newList)
{
var diff = new ListDiffItem<T>();
diff.Item = i;
public static DownloadableFile ToDownloadableXmlFileForExcel2003(this System.Xml.Linq.XDocument file, string fileName)
{
MemoryStream ms = new MemoryStream();
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings() { Encoding = Encoding.UTF8 };
XmlWriter xmlWriter = XmlWriter.Create(ms, xmlWriterSettings);
file.Save(xmlWriter); //.Save() adds the <xml /> header tag!
xmlWriter.Close(); //Must close the writer to dump it's content its output (the memory stream)
@paulirish
paulirish / gist:366184
Created April 14, 2010 18:59
html5 geolocation with fallback.
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
// doublecheck the ClientLocation results because it may returning null results
;(function(geolocation){
if (geolocation) return;