Skip to content

Instantly share code, notes, and snippets.

View jpcody's full-sized avatar

Joshua Cody jpcody

View GitHub Profile
var _generateGroupId = function randGen(){
// 2. newid is reset
var newId = Math.floor(Math.random() * 10);
if( _(myArray).include(newId) ){
// 1. you're sent back to the top of the function
randGen.apply( this );
} else {
myArray.push( newId );
// 3. a new id is explicitly returned. if you log here, you will get the new value
// self-executing function that will leak _ and its method/props into the global scope
(function() {
// access to global scope throughout function
var root = this;
var previousUnderscore = root._;
var breaker = {};
$openDocument.click(function(e){
e.preventDefault();
this.showDocument( $(this) );
}.bind(this));
## Semantic
<div class="childhood-story">
<label for="story-of-youth">A Story From Your Childhood</label>
<textarea name="story-of-youth" id="story-of-youth" cols="30" rows="10"></textarea>
</div>
<style>
div.childhood-story label {
vertical-align: top;
def top_align_label(form_field)
return "top-align" if form_field.is_a?( TextareaFormField )
return "top-align" if form_field.is_a?( FileFormField ) && form_field.reference
end
scenario "A user should be able to save an opportunity" do
all('input[type="text"]').each{ |input| fill_in( input[:id], :with => "Test Data" ) }
all('select').each do |select|
option = first("##{select[:id]} option")
select( option[:value], :from => select[:id] )
end
click_on( "Save" )
end
scenario "A user should be able to save an opportunity" do
all('input[type="text"]').each{ |input| fill_in( input[:id], :with => "Test Data" ) }
all('select').each do |select|
option = first("##{select[:id]} option")
select( option[:value], :from => select[:id] )
end
click_on( "Save" )
end
# Copyright 2008 Chris Wanstrath
# Taken from defunkt's gist repository: http://github.com/defunkt/gist/tree/master
require 'open-uri'
require 'net/http'
require 'net/https'
module Gist
extend self
@jpcody
jpcody / gist:649745
Created October 27, 2010 19:18
Pubsub Middle Ground
var search = {
getResults : function(){
$.getJSON(
'http://query.yahooapis.com/v1/public/yql?format=json&callback=',
{ q : getQuery(term) },
function(resp) {
if (!resp.query.results.result.length) { return; }
search.updateDOM(resp.query.results.result);
}
$which_document = (array(
"_id" => $email_address,
'$elemMatch' => array('word_id' => $word)
));
$which_fields = array('$set' => array("status" => "complete"));
$collection->update($which_document, $which_fields);