Skip to content

Instantly share code, notes, and snippets.

View JonKernPA's full-sized avatar

Jon Kern JonKernPA

View GitHub Profile
@JonKernPA
JonKernPA / some_cynical.rb
Created April 29, 2011 02:54
Silliness for SomeSheep
=begin
Without making any comments on the cynical nature...
Instead of ::
1. list = ("brother","father","family","tribe","neighbouring tribe","regional community","fellow citizens","foreigners")
2.
3.def politics.of.dark.ages
4.n=1
5.while n<length[list]
6.PRINT "I hate my $list[n]!"
7.PRINT "But I stand with my $list[n] against my $list[n+1]"
@JonKernPA
JonKernPA / company.rb
Created January 9, 2011 17:42
Company - Job example
class Company
include MongoMapper::Document
key :name, String
many :jobs
def to_s
name
end
@JonKernPA
JonKernPA / date_query_in_mongomapper.rb
Created November 9, 2010 21:06
This shows an odd quirk of the date query
require 'rubygems'
require 'mongo_mapper'
MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => Logger.new(STDOUT))
# MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017)
MongoMapper.database = 'testing'
class Person
include MongoMapper::Document
@JonKernPA
JonKernPA / registration_management.feature
Created November 9, 2010 19:28
Simple Cucumber Example
# under features
Feature: Registration Management
Once an organizer creates a season, they can open it up for registrants to sign up.
Scenario: Add a Registration Setup
Given the "My Season" season for "Malvern YMCA"
When I add a setup for "My Season"
Then I should be able to signup under "My Season"
class Blog
include MongoMapper::Document
# Attributes ::::::::::::::::::::::::::::::::::::::::::::::::::::::
key :title, String
key :category_id, ObjectId
key :archive_after, Time
# Assocations :::::::::::::::::::::::::::::::::::::::::::::::::::::
belongs_to :category
@JonKernPA
JonKernPA / message_log.rb
Created August 5, 2010 03:43
Demonstrating various searches in mongomapper
class MessageLog
include MongoMapper::Document
# Attributes ::::::::::::::::::::::::::::::::::::::::::::::::::::::
key :repeat_count, Integer, :default => 0
key :patient_name, String, :default => 'Unknown', :index => true
key :patient_num, String, :default => 'Unknown', :index => true
key :patient_emr, String, :default => 'Unknown', :index => true
# Doctor info (number, name, group)
key :doctor, String, :default => 'Unknown', :index => true
@JonKernPA
JonKernPA / idea.rb
Created August 4, 2010 18:00
This shows A User/Idea/Rating model using MongoMapper
class Idea
include MongoMapper::Document
key :brilliance, String, :default => "Dark Matter Sucks!"
many :ratings
belongs_to :user
key :user_id, ObjectId
def to_s
text = "#{user.name} had this IDEA: #{brilliance}\n\tRATINGS:\n"
ratings.each do |r|
@JonKernPA
JonKernPA / nested.rb
Created August 2, 2010 13:47
Nested comments on a Blog using MongoMapper
# Be sure to have mongod running
# Below is an attempt to show one way to have nested comments on a blog post
# I did not thoroughly examine whether it is bulletproof or performant.
# But it seems to work :-)
col = Blog.all()
col.each {|c| c.destroy }
col = Comment.all()
col.each {|c| c.destroy }