Skip to content

Instantly share code, notes, and snippets.

View gregjsmith's full-sized avatar

Greg Smith gregjsmith

  • Kent, England
View GitHub Profile
{
"name": "advanced-react",
"version": "1.0.0",
"description": "Advanced React",
"main": "lib/server.js",
"author": "Greg Smith",
"license": "MIT",
"scripts": {
"dev": "nodemon lib/server.js --exec babel-node",
"webpack": "webpack -wd",
var possibleCombinationSum = function(arr, n) {
if (arr.indexOf(n) >= 0) { return true; }
if (arr[0] > n) { return false; }
if (arr[arr.length - 1] > n) {
arr.pop();
return possibleCombinationSum(arr, n);
}
var listSize = arr.length, combinationsCount = (1 << listSize)
for (var i = 1; i < combinationsCount ; i++ ) {
var combinationSum = 0;
const Stars = (props) => {
return(
<div className="col-5">
{_.range(props.numberOfStars).map(i =>
<i key={i} className="fa fa-star"></i>
)}
</div>
)
}
const Card = (props) => {
return (
<div style={{margin: '1em'}}>
<img width="75" src={props.avatar_url} />
<div style={{display: 'inline-block', marginLeft: 10}}>
<div style={{fontSize: '1.25em', fontWeight: 'bold'}}>
{props.name}
</div>
<div>{props.company}</div>
@gregjsmith
gregjsmith / FunqDependencyResolver
Last active August 29, 2015 13:58
FunqDependencyResolver
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Funq;
using ServiceStack.ServiceHost;
namespace Somewhere
{
public class FunqDependencyResolver : IDependencyResolver
@gregjsmith
gregjsmith / tests.js
Created February 14, 2014 07:15
Test setup for Angular / QUnit / Sinon
var serviceLocator = angular.injector(['ng', 'nameOfAngularApp']); // used to get dependencies like controllers / filters etc
var scope = {}; // a clean scope to test
var $controllers = serviceLocator.get('$controller'); //get injector that can retrieve controllers
var $filters = serviceLocator.get("$filter"); // get filter injector
var someService; // define a global used in all tests
QUnit.module('the module name', { // define the module - qualify with QUnit namespace to avoid conflict with Angular
setup: function () {
scope = serviceLocator.get('$rootScope').$new(); // get a clean scope
$controllers('theControllerBeingTested', { $scope: scope }) // get the controller to test
@gregjsmith
gregjsmith / EventLogger
Created January 4, 2014 19:23
A class to log arbitrary information / objects graphs / Exceptions to the event logs
public sealed class EventLogger
{
private static readonly EventLogger Singleton = new EventLogger();
private static readonly EventLogTraceListener EventListener;
private static readonly string LogLevel;
public static EventLogger Instance
{
get { return Singleton; }
public class SomeController : Controller
{
public ActionResult Stuff()
{
var user = GetUser();
ViewBag.User = user;
return View();
}