Skip to content

Instantly share code, notes, and snippets.

@tonysneed
tonysneed / gist:d7f6533e12e5f7e1c0fc
Last active March 29, 2024 14:27
Serialization Helper for ASP.NET Web API
using System;
using System.Net.Http.Formatting;
using System.Runtime.Serialization;
using Newtonsoft.Json;
using WebApiContrib.Formatting;
namespace WebApiContrib
{
public static class SerializationHelper
{
@tonysneed
tonysneed / gist:4cac4f4dae2b22e45ec4
Last active May 15, 2018 14:01
Configure EF7 to Log to the Console
public static class DbContextExtensions
{
public static void LogToConsole(this DbContext context)
{
IServiceProvider contextServices = ((IDbContextServices)context).ScopedServiceProvider;
var loggerFactory = contextServices.GetRequiredService<ILoggerFactory>();
loggerFactory.AddConsole(LogLevel.Verbose);
}
}
@tonysneed
tonysneed / .gitignore
Last active August 29, 2018 22:54
VS Code .gitignore
# Build and package folders
###################
build
dist
packages
typings
.tmp
# System folders
###################
@tonysneed
tonysneed / git-add-remote
Last active April 27, 2016 15:12
Command to add a remote git repository
# Sets the new remote
git remote add origin <remote repository URL>
# Verifies the new remote URL
git remote -v
# Pushes the changes
git push origin master
@tonysneed
tonysneed / Startup.cs
Last active November 10, 2019 11:42
ASPNetCore: App_Data with LocalDb File
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv)
{
// Set up configuration sources ...
// Set up data directory
string appRoot = appEnv.ApplicationBasePath;
AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(appRoot, "App_Data"));
}
<connectionStrings>
<!--<add name="NorthwindSlimContext" connectionString="Data Source=.\sqlexpress;Initial Catalog=NorthwindSlim;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />-->
<add name="NorthwindSlimContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NorthwindSlim.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
using System.Collections.Generic;
using System.Threading.Tasks;
using HelloMvcWithDI.Entities;
using HelloMvcWithDI.Patterns;
namespace HelloMvcWithDI.Tests
{
public class FakeProductRepository : IProductRepository
{
private List<Product> _products = new List<Product>
@tonysneed
tonysneed / Mac OS X: Open in Visual Studio Code
Last active June 14, 2024 04:16
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"
@tonysneed
tonysneed / keybindings.json
Last active October 23, 2016 13:55
VS Code Keyboard Shortcuts
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "shift+cmd+g", "command": "workbench.view.git" },
{ "key": "shift+cmd+x", "command": "workbench.action.tasks.terminate" },
{ "key": "cmd+.", "command": "editor.action.quickFix", "when": "editorTextFocus" }
]
@tonysneed
tonysneed / settings.json
Last active October 23, 2016 07:06
VS Code User Settings
// Place your settings in this file to overwrite the default settings
{
"window.reopenFolders": "none",
"editor.fontSize": 15
}