Skip to content

Instantly share code, notes, and snippets.

View glcheetham's full-sized avatar

glcheetham glcheetham

View GitHub Profile
@glcheetham
glcheetham / UmbracoLinqpad.cs
Last active July 23, 2016 11:27
Umbraco LINQPad CSV Import
// Helper method enumerates over and returns lines in a file
static IEnumerable<string> ReadFrom(string file)
{
string line;
using(var reader = System.IO.File.OpenText(file))
{
while((line = reader.ReadLine()) != null)
{
yield return line;
}
@glcheetham
glcheetham / spec.js
Created May 30, 2016 09:34
Chai object comparison (right)
describe('housecat comparison', () => {
it('should let me know that both objects are the same', () => {
expect({
name: 'Tiger',
species: 'Felis Catus',
favouriteSnack: 'Tuna',
schedule: {
breakfast: '08:00',
naptime: '10:00',
@glcheetham
glcheetham / spec.js
Created May 30, 2016 09:31
Chai object comparison (wrong)
expect({
name: 'Tiger',
species: 'Felis Catus',
favouriteSnack: 'Tuna',
schedule: {
breakfast: '08:00',
naptime: '10:00',
dinner: '12:00',
tea: '18:00'
}
@glcheetham
glcheetham / UmbracoApplication.cs
Created May 27, 2016 21:41
Umbraco IOC Implementation that works properly
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using MyApp.Services;
using MyApp.Services.Interfaces;
@glcheetham
glcheetham / UmbracoApplication.cs
Last active May 27, 2016 21:35
UmbracoApplication with components registered in the DI container
using Autofac;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using MyApp.Services;
using MyApp.Services.Interfaces;
@glcheetham
glcheetham / MyContentService.cs
Created May 27, 2016 21:17
Class that we can inject an Umbraco IContentService into
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
namespace MyApp.Services
{
@glcheetham
glcheetham / UmbracoApplication.cs
Created May 27, 2016 21:01
Umbraco DI Composition Root
using Autofac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Optimization;
using Umbraco.Core;
using Umbraco.Core.Services;
namespace MyApplication
@glcheetham
glcheetham / react-component-strategy-pattern.js
Last active May 20, 2016 19:23
React component using strategy pattern instead of switch
// React componey using the strategy pattern instead of switch
import React from 'react'
const Registration extends React.Component {
constructor(props) {
super(props)
}
render() {
@glcheetham
glcheetham / react-state-strategy-pattern.js
Created May 20, 2016 19:19
React state with strategy pattern
// Example of a React state. Manage this with Flux, Redux, black magic, etc...
import AccountFields from '../Components/AccountFields'
import SurveyFields from '../Components/SurveyFields'
import Confirmation from '../Components/Confirmation'
let pages = [
{"Title": "Account Fields", "ActiveComponent": React.createFactory(AccountFields) },
{"Title": "Survey Fields", "ActiveComponent": React.createFactory(SurveyFields) },
{"Title": "Confirmation", "ActiveComponent": React.createFactory(Confirmation) }
]
@glcheetham
glcheetham / strategy-pattern.js
Last active December 13, 2017 22:27
Strategy Pattern JS example
// Example. Let's sort the apples, pears, and oranges into the right baskets.
const fruits = ["apple", "pear", "apple", "apple", "orange", "pear", "orange", "pear", "apple"]
let appleBasket = []
let pearBasket = []
let orangeBasket = []
let strategies = []
const appleSortStrategy = (fruit) => {