Skip to content

Instantly share code, notes, and snippets.

View chrisnicola's full-sized avatar

Chris Nicola chrisnicola

View GitHub Profile
@chrisnicola
chrisnicola / MongoHelper.cs
Created December 22, 2011 20:33
Mongo C# extension to compare BsonDocument and BsonValue objects
public static bool SameAs(this BsonDocument source, BsonDocument other, params string[] ignoreFields)
{
var elements = source.Elements.Where(x => !ignoreFields.Contains(x.Name)).ToArray();
if (elements.Length == 0 && other.Elements.Where(x => !ignoreFields.Contains(x.Name)).Any()) return false;
foreach (var element in source.Elements)
{
if (ignoreFields.Contains(element.Name)) continue;
if (!other.Names.Contains(element.Name)) return false;
var value = element.Value;
var otherValue = other[element.Name];
@chrisnicola
chrisnicola / REST.md
Created December 20, 2011 17:26
Is REST specific to HTTP?

Davy Brion and Jef Claes were discussing whether or not you can have REST without HTTP. Is this another peanut butter and chocolate thing? I think it's hard to extract REST from HTTP because that is how it is defined. I mean quite literally how it is defined in Fielding's dissertation. REST, the term, is short for "representational state transfer" but it still specifically describes an architectural style of representing state transfer via the HTTP specification.

But what if we didn't let such a little thing like semantics get in our way here and only took REST for it's literal name definition and not as the specification laid out in Fielding's dissertation? What if REST only meant a representation of state transfers? I'm not muc

export function parseName(path) {
const name = path.toLowerCase()
// Remove starting ./
.replace(/^\.\//, '')
// Parameters
.replace(/\/_(\w+)(\/|\.vue$)/, '/:$1/')
// Remove file extension and 'index'
.replace(/(index)?\.vue$/, '')
// Remove trailing '/'
.replace(/\/$/, '');
@chrisnicola
chrisnicola / angularjs.md
Created March 20, 2014 20:25
AngularJS Tutorial Syllabus

Course Outline

  • 1 Overview of AngularJS (1hr)
    • 1.1 AngularJS architecture overview
    • 1.2 The Angular Batarang
    • 1.3 Using Karma
    • 1.4 Get Setup
    • 1.5 Angular Seed Tour
    • 1.6 Build: Hello World
  • Bind tweet to input
@chrisnicola
chrisnicola / GzipFilter.cs
Created August 15, 2011 19:36
Gzip Compression Filter for Nancy
/* A JSON gzip compression filter, which could easily be adapted to any pattern needed. This uses a custom AfterFilter
* type which is just a fancy wrapper of Action<NancyContext>. It's useful for convention based loading of filters
*/
public class GzipCompressionFilter : AfterFilter
{
protected override void Handle(NancyContext ctx)
{
if ((ctx.Response.ContentType == "application/json") && ctx.Request.Headers.AcceptEncoding.Any(
@chrisnicola
chrisnicola / type_compatibility.ts
Created October 27, 2016 21:56
Type inference limitations for Typescript
class TypeOne {
public one
private two
private three
}
class TypeTwo {
public one
}
@chrisnicola
chrisnicola / angular.d.ts
Created September 14, 2016 19:51
Fixed Angular type definition
// Type definitions for Angular JS 1.5
// Project: http://angularjs.org
// Definitions by: Diego Vilar <http://github.com/diegovilar>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="jquery" />
declare var angular: angular.IAngularStatic;
// Support for painless dependency injection
@chrisnicola
chrisnicola / useful_object.rb
Last active September 3, 2016 00:17
A Useful Object Support Module
# Provides a default implementation of the singleton methods of buildable and
# callable classes based on the Useful Object's concept.
#
module UsefulObject
def self.included(base)
base.extend(Builder)
end
module Builder
def build(*args, **kargs, &block)
@chrisnicola
chrisnicola / test_helper.rb
Last active August 3, 2016 20:15
Instance Eval'd blocks for ActionDispatch::Integration::Runner#open_session
class ActionDispatch::IntegrationTest
# Override Rails open_session so we can use an instance involved block
# instead of passing the session instance and using it. This allows the block
# to work exactly the same as the regular test.
def open_session(&block)
return super if block.nil? || block.arity > 0
super do |session|
session.instance_eval(&block)
end
end
@chrisnicola
chrisnicola / sorted_test_order.rb
Last active August 3, 2016 11:49
Examples of trying to set test order to be sorted. Note that I'm looking at the order that test files are being run as well. Perhaps that isn't controlled here.
# So far I have tried the following code in test_helper.rb
# Based on documentation here: http://api.rubyonrails.org/v4.2/classes/ActiveSupport/TestCase.html
class ActiveSupport::TestCase
def test_order
:sorted
end
end