Skip to content

Instantly share code, notes, and snippets.

View bmneely's full-sized avatar

Ben Neely bmneely

  • Kount
  • Boise, ID
View GitHub Profile
class ConvertSharedSecretToSerializable < ActiveRecord::Migration
def change
add_column :accounts, :all_shared_secrets, :text
Account.find_each do |a|
a.all_shared_secrets.push(a[:shared_secret])
a.save!
end
remove_column :accounts, :shared_secret
@bmneely
bmneely / Account.rb
Last active December 17, 2015 16:29
Account.rb
include GAppsProvisioning
class Account < PapertrailDist
before_validation :set_default_values
after_save :redis_account_update
before_destroy :redis_account_delete
has_many :routers
has_many :clients, :through => :users, :uniq => true
$ ->
subscription.hijackMinusBtn()
subscription.hijackPlusBtn()
subscription =
hijackMinusBtn: ->
$('.minus_quantity').click (event) ->
current_quantity = subscription.getQuantity()
$('#quantity').val(if current_quantity < 2 then 1 else current_quantity - 1)
subscription.updateViewElements(event.currentTarget)
@bmneely
bmneely / account.rb
Created July 3, 2013 18:57
twoway_guest_pw
def twoway_guest_pw
return self.gibberish_guest_pw unless self.gibberish_guest_pw.blank?
self.gpg_guest_pw
end
@bmneely
bmneely / net_interface_spec.rb
Created July 18, 2013 21:56
another data set
context 'crunch stupid simple data' do
let(:start_time) { DateTime.now - 5.days }
let(:crunched) { [30, 10, 10, 0, 0] }
before do
FactoryGirl.create(:data_usage, recorded_at: start_time, bytes_in: 5, bytes_out: 5, net_interface: interface)
FactoryGirl.create(:data_usage, recorded_at: start_time + 2.hours, bytes_in: 5, bytes_out: 5, net_interface: interface)
FactoryGirl.create(:data_usage, recorded_at: start_time + 4.hours, bytes_in: 5, bytes_out: 5, net_interface: interface)
FactoryGirl.create(:data_usage, recorded_at: start_time + 2.days, bytes_in: 5, bytes_out: 5, net_interface: interface)
FactoryGirl.create(:data_usage, recorded_at: start_time + 2.days, bytes_in: 5, bytes_out: 5, net_interface: interface)
class MakeNormalizedNetInterfaceDataUsagesPolymorphic < ActiveRecord::Migration
def up
rename_column :normalized_net_interface_data_usages, :net_interface_id, :measurable_data_id
add_column :normalized_net_interface_data_usages, :measurable_data_type, :string
change_table :net_interfaces do |t|
t.references :measurable_data, polymorphic: true
end
change_table :router_configs do |t|
class AbstractNotificationRules < ActiveRecord::Migration
def up
rename_table :notification_rules, :activity_notification_rules
create_table :data_usage_notification_rules do |t|
t.string :email
t.integer :phone
t.integer :data_total
t.integer :account_id
@bmneely
bmneely / bar_fixed.rb
Last active December 22, 2015 08:19
First method of bar.rb
def self.get_data_usage(thing)
bytes_in = thing.get_data_usage(method_name: :bytes_in)
bytes_out = thing.get_data_usage(method_name: :bytes_out)
total_bytes = thing.get_data_usage
return if total_bytes.nil?
zeros = 0
total_bytes.each do |u|
break if u > 0