Skip to content

Instantly share code, notes, and snippets.

View Jimgerneer's full-sized avatar

Jim Denton Jimgerneer

  • Blinker
  • Denver
View GitHub Profile
@Jimgerneer
Jimgerneer / buzz.rb
Created December 3, 2013 04:17
FizzBuzz
class FizzBuzz
def self.play(array)
array.collect do | num |
self.fizzbuzz(num) || self.buzz(num) || self.fizz(num) || num
end
end
def self.fizz(n)
@Jimgerneer
Jimgerneer / gist:6105276
Created July 29, 2013 15:42
Ruby Warrior
class Player
def play_turn(warrior)
@warrior = warrior
@direction ||= :backward
@health ||= warrior.health
@hurt ||= false
@step ||= true
explore(@direction)
@Jimgerneer
Jimgerneer / ruby
Last active December 15, 2015 13:19
Fail sauce
class Canoe
class CommitValue < Struct.new(:email, :committed_date); end
def self.weight(commit_values)
sorted_by_email_list = commit_values.group_by(&:email)
scored_by = sorted_by_email_list.each_with_object({}) do |(email, commit), hsh|
hsh[email] = sorted_by_email_list[email].count
hsh
class Bill < ActiveRecord::Base
attr_accessible :invoice, :amount, :initiated_by_id, :payer_id, :origin_id, :destination_id ,:accepted, :paid, :auto, :frequency, :payments_left
belongs_to :initiated_by, class_name: 'Member', foreign_key: :initiated_by_id
belongs_to :payer, class_name: 'Member', foreign_key: :payer_id
belongs_to :origin, class_name: 'Account', foreign_key: 'origin_id'
belongs_to :destination, class_name: 'Account', foreign_key: 'destination_id'
validates_numericality_of :amount, greater_than_or_equal_to: 0.01
validates :amount, :presence => {message: "cannot be blank"}
@Jimgerneer
Jimgerneer / perpetrator.rb
Created January 23, 2013 21:02
perp model
class Perpetrator < ActiveRecord::Base
attr_accessible :name
has_many :reports
scope :sort_by_highest_bounty, order("max_bounty DESC")
scope :sort_by_most_reported, order("record_count DESC")
scope :sort_by_most_evidence, order("evidence_count DESC")
scope :filter_by_civ, lambda {|civ| where(["reports.civilization_id = ?", civ])}
scope :sort_by_most_wanted, order(" ( (SUM(CASE when reports.active = 't' THEN reports.bounty ELSE 0 END) - MAX(reports.bounty))*(COUNT(DISTINCT reports.id) + (SUM(COALESCE(evidence_links.evidence_count,0)) * 3 ) ) ) / (MIN(extract(epoch FROM now() - reports.created_at)) / 86400 + 1.3) DESC")
@Jimgerneer
Jimgerneer / schema.rb
Created January 19, 2013 19:30
current schema
ActiveRecord::Schema.define(:version => 20130117202104) do
create_table "civilizations", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "claims", :force => true do |t|
t.integer "hunter_id"
class RedditService
def self.post_report(report, token)
client = OAuth2::AccessToken.new(oauth_client, token)
url = "http://www.civbounty.com"
perp = Perpetrator.find(report.perpetrator_id)
user = User.find(report.user_id)
title = "Bounty of #{report.bounty}d placed on #{perp.name} CivBounty"
opts = { kind: 'link', url: url, title: title, sr: 'Rook'}
reddit_response = client.post("/api/submit", opts)
@Jimgerneer
Jimgerneer / Report.rb
Created December 24, 2012 19:56
Attempts at scope
1 class Report < ActiveRecord::Base¬
2 attr_accessible :user_id, :evidence, :location, :time, :perpetrator_id, :new_perpetrator, :bounty, :active¬
3 attr_accessor :new_perpetrator¬
4 ¬
5 before_validation :create_new_perpetrator¬
6 ¬
7 belongs_to :perpetrator¬
8 belongs_to :user¬
9 ¬
10 scope :active, where(active: true)¬
@Jimgerneer
Jimgerneer / gist:3814837
Created October 1, 2012 22:26
Rook Beta Draft 1

Welcome to Rook.

What is Rook?

This is my Apprenticeship Thesis project. It is a Sinatra open source project I have been doing on the side to hone my skills as a Ruby apprentice. The idea is for those with knowledge to create learning opportunities. Whether it be pairing on a kata in Ruby or a whole course in Common Lisp I want to make it easier for people to offer their time/skills and easier for people to find those opportunities.

Potential Mentees:

Where do you start? Everyone has a different learning style. Rook is shaped on my preferred style, learning by doing. I started to learn Ruby at the beginning of this year. After a month buried in books and tutorials, I didn't know what to do, I needed direction, a harness for my newly found love of programming. I made a post on Reddit and asked the question, "How did you get your first job developing Ruby?". They first directed me to find local user groups which is rock solid advice I pass on to everyone I know starting out. Then they did something I was n

class Booking
include DataMapper::Resource
property :id, Serial
belongs_to :booked_user, :model => 'User', :child_key => [:user_id]
belongs_to :booked_opportunities, :model => 'Opportunity', :child_key => [:opportunity_id]
end