Skip to content

Instantly share code, notes, and snippets.

View chrisnicola's full-sized avatar

Chris Nicola chrisnicola

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
namespace JSONTestingAgain
{
class Program
{
static void Main(string[] args)
{
@chrisnicola
chrisnicola / serialization.rb
Created October 3, 2011 03:17
Serialization improvements for CouchRest Model
module CouchRest
module Serialization
extend ActiveSupport::Concern
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
include ActiveModel::Serializers::Xml
included do
class_attribute :include_root_in_json
self.include_root_in_json = false
@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

@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 / tddium_test_helper.rb
Created March 17, 2012 00:46
Tddium test log folder helper
# Returns a file located in /logs/ when running locally and in the Tddium log output on Tddium
# This allows custom logs and files to be included in the Tddium test results
class Helpers
def self.test_log_path filename
if (ENV['TDDIUM_SESSION_ID'])
File.expand_path("#{ENV['HOME']}/results/#{ENV['TDDIUM_SESSION_ID']}/#{ENV['TDDIUM_TEST_EXEC_ID']}/") + '/' + filename
else
File.expand_path('log/') + '/' + filename
end
@chrisnicola
chrisnicola / jQuery.contentChanged.coffee
Created July 28, 2012 00:58
jQuery content changed plugin
# $ contentChanged
# By: Chris Nicola
#
# Provides an attachable 'contentChanged' event for text inputs and allows an
# event to be fired whenever changed content is detected. For convenience the
# event incldues properties for `previous`, `current` and `hasContent`.
#
$.fn.extend
@chrisnicola
chrisnicola / Guardfile
Created September 19, 2012 22:37
Guard problems
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
@chrisnicola
chrisnicola / page-turner.js
Created December 19, 2012 17:45
Pagination using the History API
$(function() {
setPageState = function(current, next) {
$('#content').data('page', current);
history.replaceState({ page: current }, null, current);
if(!next) return;
history.pushState({ page: next }, null, current);
history.go(-1);
};
if (!history) return;
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz#36c852831d02cf90508c29852361d01b"
install_git "jamesgolick-ruby" "https://github.com/jamesgolick/ruby.git" "jamesgolick" autoconf standard verify_openssl
@chrisnicola
chrisnicola / facepalm.js
Created May 16, 2013 02:26
Face Palm Directive for AngularJS
var facepalm = function() {
return {
replace: true,
template: "<pre>"
+ " .-'---`-.\n"
+ ",' `.\n"
+ "| \\\n"
+ "| \\\n"
+ "\\ _ \\\n"
+ ",\\ _ ,'-,/-)\\\n"