Skip to content

Instantly share code, notes, and snippets.

@danshultz
danshultz / sqladapter_rake_test_fail1.txt
Created June 7, 2011 14:49
Stack Trace from running rake test:dblib on windows against the activerecord-sqlserver-adapter gem
> bundle exec rake test:dblib
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
C:/Ruby192/bin/ruby.exe -I"lib;test;test/connections/native_sqlserver_dblib;C:\git\rails/activerecord/test" -I"C:/Ruby19
2/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib" "C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/rake_test_loader.rb"
"test/cases/aaaa_create_tables_test_sqlserver.rb" "test/cases/adapter_test_sqlserver.rb" "test/cases/attribute_methods_
test_sqlserver.rb" "test/cases/batches_test_sqlserver.rb" "test/cases/belongs_to_associations_test_sqlserver.rb" "test/c
ases/binary_test_sqlserver.rb" "test/cases/bind_parameter_test_sqlserver.rb" "test/cases/calculations_test_sqlserver.rb"
"test/cases/column_test_sqlserver.rb" "test/cases/connection_test_sqlserver.rb" "test/cases/eager_test_sqlserver.rb" "t
est/cases/execute_procedure_test_sqlserver.rb" "test/cases/finder_test_sqlserver.rb" "test/cases/has_and_belongs_to_many
_associations_test_sqlserver.rb" "test/cases/inheritance_test_sqlserver.rb" "t
@danshultz
danshultz / gist:1683178
Created January 26, 2012 15:07
Services and Dependency Injection in Ruby
class Discussion
def initialize(roundtable, resources_proc, themes_proc)
@subject = roundtable.subject
@body = roundtable.body
@resource_proc = resources_proc
@themes_proc = themes_proc
end
def resources
@resources_proc.call
@danshultz
danshultz / gist:1683709
Created January 26, 2012 16:44
Find number of commits after a commit
git log |egrep "^commit "|sed -n "1,/f3ec962800287e8078f56b77860d4e96be56ec71/ p" | wc -l
@danshultz
danshultz / index.html
Created April 18, 2012 00:41
"Stitch" solution
<html>
<header>
<script type="text/javascript" src="stitch_header.js"></script>
<script type="text/javascript" src="my-module/name.js"></script>
<script type="text/javascript">
var Name = window.require("my-module/name");
window.nameApp = new Name("My App");
</script>
</header>
<body></body>
window.require.define("app/controllers/house_controller": function(exports, require, module) {
var HouseController = function(house) {
//initializer
this.house = house;
};
HouseController.prototype.render = function() {
//rendering...
};
{promise} = require('model_promise')
render: (discussion) ->
# render stuff
change: (discussion_id) ->
@discussion_id = discussion_id
$.when(promise(Discussion, discussion_id)).then =>
@render(Discussion.find(discussion_id))
@danshultz
danshultz / explanation.md
Created May 7, 2012 19:00
mocha.js -r --require and custom assertion libraries

Explaination

I have been using mocha for a little while with the "should" assertion library on the node side and chai in the web browser. I determined I wanted to use chai for my server side js testing as well but I didn't want to require chai explicitly at the top of each file so I looked at the --require parameter for mocha and determined that I could leverage this to setup my testing framework as well as any custom matchers/other framework uils

The command I now use to run mocha is mocha -r ./test/support/setup test/my_stuff.test.js

In doing this - you no longer have to explicitly register chai/sinon

Thoughts? Good idea/bad idea - gotchas that I'm unaware of thus far?

@danshultz
danshultz / problem67.coffee
Created June 5, 2012 14:30
Project Euler Problem 67 Solution in Multiple Languages
fs = require('fs')
triangle = fs.readFileSync('../triangle.txt', 'utf-8')
.split('\r\n')
.map((x) -> x.split(' ').map((y) -> +y))
.reverse()
.splice(1)
reduction = (prev, current) ->
current.map (x, i) ->
@danshultz
danshultz / liquid_view.rb
Created June 12, 2012 03:11
liquid/lib/extras/liquid_view.rb file to use in Rails 3 with layouts
# LiquidView is a action view extension class. You can register it with rails
# and use liquid as an template system for .liquid files
#
# Example
#
# ActionView::Base::register_template_handler :liquid, LiquidView
class LiquidView
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template
_response url _request _cookies variables_added _flash params _headers request cookies
ignore_missing_templates flash _params logger before_filter_chain_aborted headers )
@danshultz
danshultz / nil_patch.rb
Created October 19, 2012 01:17
ActiveRecord nil patch
def nil.method_missing(method, *args)
(@@activeRecordClasses ||= ObjectSpace.each_object(Class).find_all { |c|
c.respond_to?(:ancestors) && c != ActiveRecord::Base && c.ancestors.include?(ActiveRecord::Base)
}).choice.order("rand()").first || self.method_missing(method, *args)
rescue
self.method_missing(method, *args)
end