Skip to content

Instantly share code, notes, and snippets.

View christo8989's full-sized avatar

Christopher Jeffery christo8989

View GitHub Profile
@christo8989
christo8989 / nginx.conf
Last active February 11, 2018 17:39 — forked from plentz/nginx.conf
Best nginx configuration for improved security(and performance). Complete blog post here http://tautt.com/best-nginx-configuration-for-security/
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048

Owin Authentication with Web API 2

Using Microsoft.Owin.Security along with .NET Web API 2 for authentication on Single Page Applications.

My example is split up into 2 different projects, API which is WebAPI2 project and MyProj which is a basic MVC that contains primarily only JavaScript/CSS/etc and the startup classes.

Installed NuGet Packages

Microsoft.AspNet.Identity.Owin

Microsoft.Owin.Host.SystemWeb

@christo8989
christo8989 / DateTimeExtensions
Created June 28, 2017 21:06
Extending DateTime for common queries. Follows the same method names as MomentJs.
//http://momentjs.com/docs/#/query
public static class DateTimeExtensions
{
public static bool IsSame(this DateTime source, DateTime value)
{
return source.CompareTo(value) == 0;
}
public static bool IsBefore(this DateTime source, DateTime value)
{
@christo8989
christo8989 / Maybe<T>.cs
Last active October 2, 2019 04:26
Maybe<T>
public class Maybe<T>
{
private readonly IEnumerable<T> values;
public T Value
{
get
{
if (!this.HasValue)
{
@christo8989
christo8989 / Element Custom Binding - Knockoutjs.js
Last active October 2, 2019 04:30
Custom binding handler that passes the element to the viewmodel. Typically, this should not be used but sometimes its easier to just get the element. In my case, some event happens and I want to focus on my input element.
ko.bindingHandlers.element = {
init: function (element, valueAccessor) {
var vmElement = valueAccessor();
if (ko.isObservable(vmElement) === false)
throw Error("The binding handler needs an observable.");
vmElement(element);
},
};