Skip to content

Instantly share code, notes, and snippets.

View Eonasdan's full-sized avatar

Eonasdan Eonasdan

View GitHub Profile
@Eonasdan
Eonasdan / !ReadMe
Last active July 14, 2018 14:42
SQLite EF Style Migrations
Note: IFileService is not completely necessary unless you’re doing Xamarin Forms and need.
@Eonasdan
Eonasdan / SerializeViewModel.cs
Created March 1, 2018 15:56
a C# MVC helper to take an model object and convert it to a serialized object
public static HtmlString SerializeViewModel(this HtmlHelper helper, object viewModel, JsonSerializerSettings serializer = null)
{
if (serializer == null)
{
serializer =
new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()};
}
return new HtmlString(JsonConvert.SerializeObject(viewModel, serializer));
}
@Eonasdan
Eonasdan / AddClassHelper.cs
Last active February 15, 2018 16:58
MVC core tag helper for my Bootstrap 4 datapicker https://github.com/tempusdominus/bootstrap-4. Easy to modify for BS3.
/// <summary>
/// Adds <paramref name="newClass"/> to <paramref name="output"/> or appends it.
/// </summary>
/// <param name="output"></param>
/// <param name="newClass"></param>
public static void AddClass(this TagHelperOutput output, string newClass)
{
var classAttribute = output.Attributes.FirstOrDefault(a => a.Name == "class");
if (classAttribute == null)
{
@Eonasdan
Eonasdan / ExceptionHandlerMiddleware.cs
Last active February 9, 2018 21:33
Borrowed ExceptionHandlerMiddleware from Microsoft.AspNetCore.Diagnostics/Internal/DiagnosticsLoggerExtensions.cs that takes area into effect.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
@Eonasdan
Eonasdan / Packages XML to C# paste
Created December 31, 2016 04:06
parsing package.config for nuget package explorer
/// <remarks/>
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class packages
{
private packagesPackage[] packageField;
@Eonasdan
Eonasdan / css steal.html
Created September 26, 2016 19:27
CSS Steal
<script>
(function () {
var CSSSteal = function () {
var api = {}, html = null, styles = [], indent = ' ', elements = false, args = arguments;
var requirements = function () {
if (args.length === 0) {
throw new Error('CSSSteal expects at least one argument (DOM element)');
}
@Eonasdan
Eonasdan / A generic repository.md
Last active July 11, 2022 06:03
This is my attempt at a very flexible generic repository for an n-layer MVC project.

Generic Repo

This is my attempt at a very flexible generic repository for an n-layer MVC project.

IRepository

I've got this placed in my business/service layer which any DAL (Data Access Layer) project can reference and implement.

PagedEntities

@Eonasdan
Eonasdan / Amazon Book to public library search.md
Last active January 17, 2018 21:28
Search local public libraries from Amazon using these Bookmarklets

Amazon Book to public library search

image

Each of the sections below allow you to click on a bookmark/favorite to quickly search your local public library for a book you are looking at on Amazon. The goal is to save money (and bookshelf clutter :)) so you can check out a book (see what I did there?) instead of buying it first.

##Quick Guide

Here's how you use these. It's probably going to be easiest to copy the bookmarklet code by clicking "Raw":

@Eonasdan
Eonasdan / Routing-Areas.tt
Last active April 3, 2016 20:14
Creates a strongly typed MVC urls: see http://vikutech.blogspot.com/2014/11/strong-typed-mvc-routing-on.html. Routing-Areas.tt is an enhancement to the original attempting to check if the route is in a Area. Routing-JsonResults.tt limits the generation to JsonResult Actions
<#@ template debug="true" hostSpecific="true" #>
<#@ assembly name="System.Core" #>
<#@ Assembly Name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".ts" #>
module Routing {
<#
@Eonasdan
Eonasdan / gist:4ade9cad3755ff62fd80
Last active August 29, 2019 13:46
zensharp tempaltes
// C# templates
// Sample file
space ::= " "
cursor ::= "$END$"
cursorb ::= "(" cursor ")"
// Resharper macros:
identifier ::= <name default="$name$" macros = "complete()">
identifier2 ::= <name2 default="$name2$" macros = "complete()">
//