Skip to content

Instantly share code, notes, and snippets.

View sgharms's full-sized avatar

Steven G. Harms sgharms

View GitHub Profile
@sgharms
sgharms / gist:1601458
Created January 12, 2012 16:31
GET /tasks Rails log
#===============================================================================
## INITIAL PAGE VISIT ##
#===============================================================================
GET /tasks (no params)
Processing by TasksController#index as HTML
Employee Load (0.5ms) SELECT "employees".* FROM "employees" WHERE "employees"."id" = 1 LIMIT 1
Task Load (0.9ms) SELECT DISTINCT(completed_on) FROM "tasks" WHERE "tasks"."employee_id" = 1 AND (completed_on <= '2012-01-12') ORDER BY completed_on DESC LIMIT 5
class Employee < ActiveRecord::Base
...
def recent_tasks(options = {})
completed_on = if options[:completed_on].present?
Date.parse options[:completed_on]
else
Date.current
end
completed_on = 2.business_days.after(completed_on.to_time).to_date
<a id="previous" href="#"></a>
<% for task in @tasks: %>
<span class="date <%= task.status() %>" data-date="<%= task.get 'completed_on' %>">
<p class="time"><%= task.get 'time' %></p>
<p class="name"><%= Date.parse(task.get('completed_on')).toString 'ddd' %></p>
<p class="range">
<a href="#"><%= Date.parse(task.get('completed_on')).toString 'MM/dd' %></a>
</p>
</span>
<% end %>
class Timesheet.Views.DateScrollView extends Backbone.View
el: '.DateScrollPane'
template: JST['tasks/date_scroll_view']
initialize: ->
@collection.bind 'reset', @render
...
@model.bind 'change:completed_on', @refreshSelection
...
render: =>
completedOn = Date.parse @model.get('completed_on')
@sgharms
sgharms / gist:1603633
Created January 12, 2012 22:46
Add line numbers to your GitHub gists from within Markdown within a WordPress installation
<script type="text/javascript">
/*
* Add this to the top of your post. This will get interpreted in and applies to your page
* e.g.
*
* (this code)
*
* # My Summer Vacation
*
@sgharms
sgharms / gist:1607419
Created January 13, 2012 16:44
Rails to Javascript passing with reset
:javascript
$(function () {
Timesheet.Tasks.reset(#{@tasks.to_json.html_safe});
...
});
@sgharms
sgharms / gist:1607438
Created January 13, 2012 16:45
BB reset documentation
reset collection.reset(models, [options])
Adding and removing models one at a time is all well and good, but
sometimes you have so many models to change that you'd rather just
update the collection in bulk. Use reset to replace a collection with a
new list of models (or attribute hashes), triggering a single "reset"
event at the end. Pass {silent: true} to suppress the "reset" event.
Using reset with no arguments is useful as a way to empty the
collection.
@sgharms
sgharms / gist:1607443
Created January 13, 2012 16:47
Event handling for BB objects
events:
"click .date": "selectDate"
"click #previous": "previous"
"click #next": "next"
@sgharms
sgharms / gist:1607448
Created January 13, 2012 16:47
Options for controllers in BB doc
There are several special options that, if passed, will be attached
directly to the view: model, collection, el, id, className, and tagName.
@sgharms
sgharms / gist:1607452
Created January 13, 2012 16:48
BB Router for Timesheet
class Timesheet.Routers.TasksRouter extends Backbone.Router
routes:
"": "index",
"new?completed_on=:completedOn": "new"
initialize: ->
@newTask = new Timesheet.Models.Task Timesheet.localGet('task')
...
@dateScrollView = new Timesheet.Views.DateScrollView
model: @newTask
collection: Timesheet.Tasks