Skip to content

Instantly share code, notes, and snippets.

View joshrendek's full-sized avatar

Josh Rendek joshrendek

View GitHub Profile
belongs_to :plan
before_create :set_trial_end
def set_trial_end
plan = Plan.find(4)
end_of_trial = self.created_at + plan.trial_duration.days
self.trial_end_date = end_of_trial
end
def bandwidth_usage(days)
beginning = Time.now.advance(:days => -days)
x = self.server_logs.where("created_at > ?", beginning)
netin = 0
netout = 0
for i in (0..(x.size-2)) # avoid last record
time_in_distance = (x[i+1].created_at - x[i].created_at)
netin += x[i].net_in * time_in_distance
netout += x[i].net_out * time_in_distance
end
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<host>
<name>ota-db1</name>
<dell_service_tag>ASDVB</dell_service_tag>
<make_model>Dell PowerEdge R610</make_model>
<os>
<os_name>CentOS x86_64</os_name>
<os_version>5.2</os_version>
</os>
<?xml version="1.0" encoding="UTF-8"?>
<hosts>
<title>PT Smart Complete Configuration V1.1</title>
<url>http://url.com/complete_configuration/11</url>
<description>Customer OTAF Configuration Description</description>
<host>
<name>ota-db1</name>
<dell_service_tag>ASDVB</dell_service_tag>
<make_model>Dell PowerEdge R610</make_model>
<os>
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'pg'
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'pg'
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
gem 'pg'
module DatatablesRails
class Structify
attr_accessor :struct
def initialize(data)
@struct = {}
@struct = data.collect{|d| d.attributes }
end
def formatter(&block)
#block.call(@struct)
desc 'Ping pubsubhubbub server.'
task :ping do
require 'cgi'
require 'net/http'
http = Net::HTTP.new('pubsubhubbub.appspot.com', 80)
path = '/publish'
headers = {'Content-Type' => "application/x-www-form-urlencoded"}
data = 'hub.mode=publish&hub.url=http://bluescripts.net/atom.xml'
2011-11-27T04:27:27+00:00 heroku[router]: GET app.classopoly.com/ dyno=web.1 queue=0 wait=0ms service=16ms status=200 bytes=1247
2011-11-27T04:27:27+00:00 app[web.1]:
2011-11-27T04:27:27+00:00 app[web.1]:
2011-11-27T04:27:27+00:00 app[web.1]: Started GET "/" for 98.230.1.143 at 2011-11-26 20:27:27 -0800
2011-11-27T04:27:27+00:00 app[web.1]: Completed 200 OK in 9ms (Views: 3.3ms | ActiveRecord: 4.5ms)
2011-11-27T04:27:29+00:00 app[web.1]: cache: [GET /user_courses] miss
2011-11-27T04:27:31+00:00 heroku[router]: GET app.classopoly.com/ dyno=web.1 que
2011-11-27T04:27:32+00:00 app[web.1]:
2011-11-27T04:27:32+00:00 app[web.1]: