Skip to content

Instantly share code, notes, and snippets.

View markjlorenz's full-sized avatar

Mark Lorenz markjlorenz

View GitHub Profile
@markjlorenz
markjlorenz / ApplicationController.rb
Created September 18, 2012 17:06
Rails and Coffee to render an object graph for any rails model
#As coded this is suiteable for adding to ApplicationController, or an included controller module
#It would also be cool to refactor this code to be added to fat models instead
def object_graph
@prune_nodes = params[:prune_nodes] #When the crawler hits a node of this class, it will stop
model_name = controller_name.classify
root_object = model_name.classify.constantize.find(params[:id])
edge_list = {} #This is implemented as an object instead of an array for lookup performance reasons
nodes = {}
object_ident = ->(object){"#{object.id}-#{object.class}"} #helper function
fill_object_data = ->(object, ident) do #add some data to the JSON object that will be used by the renderer
@markjlorenz
markjlorenz / Query String to Params Cheat.md
Last active October 17, 2022 19:11
Rails Query String to Params Cheat Sheet

#A hash of arrays: widget[]=first-widget&gadget[]=a-gadget&widget[]=another%20widget

Resulting Params:

{
    :widget => [ "first-widget",  "another widget"],
    :gadget => [ "a-gadget" ]
}
@markjlorenz
markjlorenz / function.coffee
Created August 21, 2012 01:30 — forked from sankage/function.coffee
CoffeeScript: self executing anonymous functions
# Is there a coffeescript way of doing this?
(function($, exports){
# doing random stuff here
})(jQuery, window);
# Other than this:
( ($, exports) ->
# doing random stuff here
@markjlorenz
markjlorenz / jquery weekcalendar update for multiday events
Created April 16, 2011 13:33
applicable sections copied from _renderEvents to _updateEventsInCalendar
/*
* update the events rendering in the calendar. Add if does not yet exist.
*/
_updateEventInCalendar : function (calEvent) {
var self = this;
self._cleanEvent(calEvent);
if (calEvent.id) {
self.element.find(".wc-cal-event").each(function() {