Skip to content

Instantly share code, notes, and snippets.

@danshultz
danshultz / unicorn.rb
Last active August 29, 2015 13:57
Monitoring your unicorn workers with Sensu
# Monitor the unicorn processes on 10 second intervals
unicorn_monitor = Proc.new {
require 'socket'
require 'json'
require 'raindrops'
address = "0.0.0.0:8080"
socket = Raindrops::InetDiagSocket.new
udp = UDPSocket.new
while(true) do
@danshultz
danshultz / .bash_profile
Created September 3, 2014 19:21
bashrc
# source ~/bin/git-completion.bash
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
source `brew --prefix`/Library/Contributions/brew_bash_completion.sh
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
@danshultz
danshultz / application.js
Created February 19, 2015 20:33
Nested Url Support - Ember Data
import Ember from 'ember';
export default DS.ActiveModelAdapter.extend({
findQuery: function(store, type, query) {
// wrap the query in an Ember.Object and pass it through as the "record" to the buildUrl method
var url = this.buildURL(type.typeKey, null, Ember.Object.create(query));
return this.ajax(url, 'GET', { data: query });
},
@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?