Skip to content

Instantly share code, notes, and snippets.

View Jimgerneer's full-sized avatar

Jim Denton Jimgerneer

  • Blinker
  • Denver
View GitHub Profile
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 / 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"
@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")
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 / 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
@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 / 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)