Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@jupiterjs
jupiterjs / JavaScriptMVC.md
Created May 24, 2011 16:58 — forked from moschel/JavaScriptMVC.md
JavaScriptMVC Overview

The following is a VERY rough draft of an article I am working on for Alex MacCaw's @maccman's Book. It is very rough, but even now a worthwhile read. Suggestions / comments are very welcome! Please help me :-)

Introduction

JavaScriptMVC (JMVC) is an open-source jQuery-based JavaScript framework. It is nearly a comprehensive (holistic) front-end development framework, packaging utilities for testing, dependency management, documentation, and a host of useful jQuery plugins.

Yet every part of JavaScriptMVC can be used without every other part, making the library lightweight. Its Class, Model, View, and Controller combined are only 7k minified and compressed, yet even they can be used independently. JavaScriptMVC's independence lets you start small and scale to meet the challenges of the most complex applications on the web.

This chapter covers only JavaScriptMVC's $.Class, $.Model, $.View, and $.Controller. The following describes each component:

@michaelt
michaelt / latex.template
Created June 9, 2011 21:23
Simple Pandoc default.latex with comments
%!TEX TS-program = xelatex
\documentclass[12pt]{scrartcl}
% The declaration of the document class:
% The second line here, i.e.
% \documentclass[12pt]{scrartcl}
% is a standard LaTeX document class declaration:
% we say what kind of document we are making in curly brackets,
% and specify any options in square brackets.
@mxriverlynn
mxriverlynn / 1-model.rb
Created June 17, 2011 01:37
serialize mongoid documents to json with an id attribute
class Foo
include Mongoid::Document
field :bar
end
foo = Foo.new(:bar => "baz")
foo.to_json # => { _id: "(some uuid)", bar: "baz" }
/**
Code copyright Dustin Diaz and Ross Harmes, Pro JavaScript Design Patterns.
**/
// Constructor.
var Interface = function (name, methods) {
if (arguments.length != 2) {
throw new Error("Interface constructor called with " + arguments.length + "arguments, but expected exactly 2.");
}
this.name = name;
@caike
caike / vending_machine.coffee
Created July 4, 2011 21:36
Vending Machine
class VendingMachine
constructor: ->
@products = {
'coke': 5,
'iced tea': 5
}
@balance = 0
getCount: (productName)->
@jcasimir
jcasimir / Rakefile
Created July 20, 2011 17:34
Using Rake to keep track of my pending/to-do items while writing
FILE_SEARCH_PATTERN = "tutorials/**/*.{markdown, textile}"
MARKERS = {"todo" => :red, "pending" => :green}
COLORIZE = true
MARKERS.keys.each do |marker|
desc "Pull out #{marker.upcase} lines"
task marker do
print_lines_containing(marker)
end
end

Polymorphism

Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:

  • A Person
  • A Company
  • A PhoneNumber that can connect to a Person or a Company

At the Database Level

@elliotttf
elliotttf / gist:1102105
Created July 24, 2011 02:02
git branch on terminal prompt
# Add current git branch (if applicale) to the terminal prompt.
function pgb {
ref=$(/usr/bin/git symbolic-ref HEAD 2> /dev/null) || return
dirty=""
untracked=""
# Disallow unstaged changes in the working tree
if ! /usr/bin/git diff-files --quiet --ignore-submodules --
then
dirty="*"
@shaunoconnell
shaunoconnell / gist:1154345
Created August 18, 2011 15:38
rails rake task to override things. . .for legacy db where user does not have perms
# since we are using a "legacy" schema, we don't want to drop db or tables.'
Rake::TaskManager.class_eval do
def alias_task(fq_name)
new_name = "#{fq_name}:original"
@tasks[new_name] = @tasks.delete(fq_name)
end
end
def alias_task(fq_name)
Rake.application.alias_task(fq_name)
@IndianGuru
IndianGuru / jruby08.rb
Created September 2, 2011 11:21
JRuby programs
# 1
class Rubyist
def self.who
"Geek"
end
end
puts Rubyist.who
# 2
class Rubyist