Skip to content

Instantly share code, notes, and snippets.

View markjlorenz's full-sized avatar

Mark Lorenz markjlorenz

View GitHub Profile
@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() {
@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 / 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 / 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 / AssociativeObject.rb
Created September 20, 2012 12:56
A Ruby Object that Works Like Javascript's Objects. The idea is to make creating/validating non-model based forms easier.
class AssociativeObject
def eigenclass; class << self; self; end; end
#form_for requires these methods
attr_accessor :id
attr_accessor :errors
def new_record?; return true; end
def to_param; return nil; end #for AR object to_param returns nil for new objects
def to_key; id ? [id] : nil end #borrowed from rails source for dummy object
def self.model_name; ActiveModel::Name.new(self); end #how AR determines the name for the params hash. TODO: allow dynamic assignment
@markjlorenz
markjlorenz / RecursiveAsyncFileRead.coffee
Created October 12, 2012 18:53
Uses Node.js's asynchronous file functions to recrusivly read a directory structure.
app.get "/ls", (req, res)->
path = "."
directoryCount = 0
edges = {} #key only for internal purpose {key:[], key2:[]}
nodes = {} #stores data for nodes
recursiveCalls = 0
nodeId = (path)->
"#{path}"
recursionComplete = ()->
console.log "-- Directory Count: ", directoryCount
@markjlorenz
markjlorenz / TattleTale.js
Created December 17, 2012 21:36
Report client side JS errors back to the application
// If you pash an object of the same format as `testCases` it will be merged into test cases
// requires jQuery
var objectSupport = function(additionalObjects){
additionalObjects = typeof additionalObjects !== 'undefined' ? additionalObjects : {};
if(!jQuery){throw new Error("clientJSError requires jQuery");}
//takes an object path, returns true of it's available. For Example:
// >objectSupported("Array.prototype.forEach")
// >false //false in IE7
//
@markjlorenz
markjlorenz / vimrc
Last active December 15, 2015 11:39
Let's cargo cult a .vimrc
syntax on
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set indentexpr=
set number
set ai
"for snippets plugin
@markjlorenz
markjlorenz / 10-April-2013_PhoneCall.markdown
Created April 11, 2013 13:10
10-April-2013 Meeting Notes
  • On landing page both the email and text should do the same action.

  • Contest page, maybe replace landing page.

  • Focus webpage on contest

    • Author first name, last name
    • Previously publish in including issue
  • Try to implement a story upload on the contest site.

  • Send a story based on some ones' mood "I'm pissed"

  • Themed contest by season, so content is pre-sorted.

@markjlorenz
markjlorenz / widget.coffee
Created June 14, 2013 18:01
jQuery widget template
jQuery ($)->
$.widget 'yourNamespace.yourPluginName',
options:
_create: ->
$ele = $(@element)