Skip to content

Instantly share code, notes, and snippets.

View chrisnicola's full-sized avatar

Chris Nicola chrisnicola

View GitHub Profile
@chrisnicola
chrisnicola / xirr.rb
Last active August 29, 2015 14:02 — forked from sapient/xirr.rb
Performs XIRR calculations using Ruby's Newton#nlsolve
require 'date'
require 'bigdecimal/newton'
require 'bigdecimal/math'
class XIRR
include Newton
def initialize(trans)
@trans = trans
@zero = 0.to_d
# Provides angular filters for lodash or underscore functions
module = angular.module('_filters', [])
_(_).functions().each (name) ->
n = name
module.filter '_' + n, -> _[n]
@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 / 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"
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 / 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;
@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 / 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 / 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 / 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];