Skip to content

Instantly share code, notes, and snippets.

View christo8989's full-sized avatar

Christopher Jeffery christo8989

View GitHub Profile
@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)
{

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 / global.service.ts
Last active February 9, 2018 22:43
One way to pass objects around in an angular2 app using RxJS.
import { Injectable } from '@angular/core';
import {
Subject,
BehaviorSubject,
Subscription } from 'rxjs';
@Injectable()
export class GlobalService {
private subjects: object = {};
@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
@christo8989
christo8989 / link.service.spec.ts
Last active May 8, 2018 16:23
This does not work with lazy loading modules (with routes) but I wanted to keep.
@christo8989
christo8989 / _svg-optimized.scss
Last active February 7, 2019 17:44
SASS mixin that optimizes the svg markup to a background style.
// Optimize svg text --> http://petercollingridge.appspot.com/svg-optimiser
// Helpfule Article --> https://css-tricks.com/using-svg
// Credit where credit is due --> https://codepen.io/jakob-e/pen/doMoML
// SVG Alignment and Aspect Ratio --> http://tutorials.jenkov.com/svg/svg-viewport-view-box.html
// Function to create an optimized svg url
// Version: 1.0.6 (plus my changes)
@mixin svg($svg){
width: 100%;
@christo8989
christo8989 / HttpClientManager.cs
Last active February 8, 2019 23:16
HttpClients are difficult to use in C#. This class will manage them for you.
// http://www.tomdupont.net/2014/11/net-45-httpclient-is-thread-safe.html
// http://www.nimaara.com/2016/11/01/beware-of-the-net-httpclient
public static class HttpClientManager
{
private static readonly ConcurrentDictionary<string, HttpClient> clients = new ConcurrentDictionary<string, HttpClient>();
private static readonly object lockobj = new Object();
public static HttpClient Get(string url)
@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);
},
};
@christo8989
christo8989 / parameter.service.ts
Created March 16, 2020 16:21
Angular ParameterService
import { Injectable } from "@angular/core"
import { ActivatedRoute, ActivatedRouteSnapshot } from "@angular/router"
@Injectable({ providedIn: "root" })
export class ParameterService {
constructor(private route: ActivatedRoute) { }
get(property: string, defaultValue: string = null): string {
const value = this.findProperty(this.route.root.snapshot, property)