Skip to content

Instantly share code, notes, and snippets.

View scottmessinger's full-sized avatar

Scott Ames-Messinger scottmessinger

View GitHub Profile
@scottmessinger
scottmessinger / output.sass
Created July 29, 2011 18:13
compass sprite "rocky16/*.png"
@import compass/utilities/sprites/base
// General Sprite Defaults
// You can override them before you import this file.
$rocky16-sprite-base-class: ".rocky16-sprite" !default
$rocky16-sprite-dimensions: false !default
$rocky16-position: 0% !default
$rocky16-spacing: 0 !default
$rocky16-repeat: no-repeat !default
$rocky16-prefix: "" !default
@scottmessinger
scottmessinger / memoryleak.js
Created July 30, 2011 20:33
JS Memory Leak :-(
Unit.prototype.toJSON = function(){
var copy = ko.toJS(this)
copy.content_ids = _.map(copy.contents, function(content){return content.id})
copy.children_ids = _.map(copy.units, function(unit){return unit.id})
return {
course_slug : course_slug
id : copy.id
,title : copy.title
,subtitle : copy.subtitle
@scottmessinger
scottmessinger / leak.js
Created August 2, 2011 01:27
More memory leaks
var addTrackers = function(vm, vms){
vm.units = ko.dependentObservable(function(){
if (vms.unit() !== undefined){
_.each(vms.unit().dirtyUnits(), function(unit){
unit.save(vms.course)
unit.dirtyFlag.reset()
})
}
})
vm.unit = ko.dependentObservable(function(){
@scottmessinger
scottmessinger / **What ends up happening***
Created August 4, 2011 22:09
Tracking isn't working :-(
In short, the tracking of the dirty units stops working.
Scenario:
1. User hits the "show_course" route which loads a course then loads the first unit.
2. User then clicks on a new unit and hits the "show_unit" course.
3. User then clicks a link which takes them to the "show_course" route.
When they hit 3, the change tracking stops working. Why is this? In addition, when I call App.VMs.unit().dirtyUnits.getSubscriptionsCount(), the count goes up after each time a user hits "show_course" or "show_unit." It appears the subscriptions and the dependentObservables are just sticking around even though the unit they're observing has been changed.
Any ideas how to do this?
@scottmessinger
scottmessinger / fog.rb
Created August 23, 2011 17:03
Monkeypatching a Gem
# utilities > carrierwave > storage > fog.rb
# utilities is in my autoload path
# after this, carrierwave ceased to work. I commented out the method, still nothing.
# it appears that the class completely clobbers the existing class....
module CarrierWave
module Storage
class Fog < Abstract
class File
@scottmessinger
scottmessinger / 1.router.js
Created September 21, 2011 22:29
Routing in KO with Backbone.js
App.Router = Backbone.Router.extend({
routes : {
"" : "home"
,"/" : "home"
,"!" : "home"
,"!/" : "home"
,"!/:username" : "show_user"
,":username" : "show_user"
,":username/" : "show_user"
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@rails31/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:419: stack level too deep (SystemStackError)
rake aborted!
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@rails31/gems/rspec-core-2.6.4/lib/rspec/core/rake_task.rb:139:in `rescue in block (2 levels) in initialize'
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@rails31/gems/rspec-core-2.6.4/lib/rspec/core/rake_task.rb:135:in `block (2 levels) in initialize'
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@global/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:57:in `verbose'
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@rails31/gems/rspec-core-2.6.4/lib/rspec/core/rake_task.rb:131:in `block in initialize'
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/ScottMessinger/.rvm/gems/ruby-1.9.2-p180-patched@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/ScottMessinger/.rvm/gems
@scottmessinger
scottmessinger / url.rb
Created October 7, 2011 06:30
Authenticated Url Stats
class Document
mount_uploader :doc, DocumentUploader
def auth_url
self.doc.file.authenticated_url
end
def public_url
self.doc.file.url
@scottmessinger
scottmessinger / problems.html
Created November 28, 2011 23:39
Rails 3.1 asset pipelining is not working.
// THIS:
<script type="text/javascript">
var src_app = "<%=javascript_path('application')%>";
var src_frm = "<%=javascript_path('frameworks')%>";
var src_tiny = "<%=javascript_path('tiny_mce/tiny_mce_joined')%>";
</script>
// PRODUCES THIS:
<script type="text/javascript">
@scottmessinger
scottmessinger / gist:1541530
Created December 30, 2011 21:26
Nested Item Tallies
CURRICULUM PUBLISHING APP
=========================
This is a rough estimate of the number of items on a reasonably complex page. The document data might be delivered as one big JSON blob or as separate JSON arrays and combined client side.
BASIC OUTLINE
=============
A curriculum has three tiers
Unit > Concept > Lesson