Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
@kbrock
kbrock / readme.md
Last active February 19, 2016 14:30
current render vms
@ ms ms- sql sqlms sqlrows comments
0.0 16,828.7 164 3,660.4 48075 /vm_infra/explorer
0.0 16,828.7 23.0 GET http://localhost:3000/vm_infra/explorer
20.0 16,805.6 25.7 6 1.9 5 .Executing action: explorer
41.0 15,327.8 0.0 ..VmShowMixin#feature_tree
41.0 15,327.8 0.2 ...VmShowMixin#build_vm_feature_tree
41.0 3.3 3.3 3 0.3 3 ....VmShowMixin#build_allowed_features
44.0 15,310.6 2,265.7 ....VmShowMixin#build_vm_tree
45.0 13,044.9 299.4 5 41.8 854 .....ApplicationController::Explorer#x_build_dynatree
@kbrock
kbrock / numbers.md
Last active February 2, 2016 14:32
name time child offset
Executing action: explorer
|22.1|29741.2|+19.0
 VmInfraController#explorer
|7.2|29719.1|+38.0
   VmInfraController#x_build_dynatree
|312.8|25769.1|+39.0
    Rbac.search
|136.9|141.8|+40.0
    TreeBuilderVmsAndTemplates#tree
|64.0|1565.8|+182.0
    TreeBuilderVmsAndTemplates#tree
|50.4|1423.2|+1748.0
      EmsVmware#subtree_arranged
|656.3|656.3|+1748.0

Rbac.search|301.0|666.4|+2418.0

@kbrock
kbrock / tasks.rb
Created January 27, 2016 21:18
Purging Schedule and associated methods
miq_schedule_worker_runner:
Jobs.metric_purge_all_timer # role: database_operations
VmdbMetric::Purging.purge_all_timer
# model: VmdbDatabaseMetric, table: vmdb_database_metris
VmdbMetric::Purging.purge_by_date(6.months.ago.utc, "hourly", 10_000)
VmdbMetric::Purging.purge_by_date(6.months.ago.utc, "daily", 10_000)
VmdbMetric::Purging.purge_all_timer
# model: VmdbMetric, table: vmdb_metrics
# PurgingMixin (need interval, so duplicated it)
VmdbMetric::Purging.purge_by_date(6.months.ago.utc, "hourly", 10_000)
@kbrock
kbrock / flow.md
Created January 21, 2016 13:47
Our apache proxy creation

environment_manager.rb:

  def prep_apache_proxying
    return unless MiqEnvironment::Command.supports_apache?

    MiqApache::Control.kill_all
    MiqUiWorker.install_apache_proxy_config
    MiqWebServiceWorker.install_apache_proxy_config
 end
@kbrock
kbrock / reasons.rb
Last active January 14, 2016 17:58
Active Record allows you to define relationships in 2 directions. But unfortunately, it is not always smart enough to detect when a relationship on one side is the same as the opposite direction. This aims to help you discover where and why rails is not helping you out.
class Reason
def reason_inverse_name(src, ref)
# def inverse_name; delegate_reflection.send(:inverse_name); end
ref = ref.respond_to?(:delegate_reflection) ? ref.delegate_reflection : ref
if ref.options[:inverse_of]
# will this false positive a :through?
if ref.options[:inverse_of] == ref.send(:automatic_inverse_of)
"UNNEEDED: `options[:inverse_of]`"
else
require "objspace"
ObjectSpace.trace_object_allocations_start
def log_object_space
ObjectSpace.trace_object_allocations_stop
object_hash = {}
ObjectSpace.each_object do |o|
key = "#{ObjectSpace.allocation_sourcefile(o)}" #:#{ObjectSpace.allocation_sourceline(o)}"
object_hash[key] ||= Hash.new { |h, _| h[:count] = 0; h[:memsize] = 0 }
@kbrock
kbrock / complie.sh
Last active September 8, 2015 15:16 — forked from havenwood/hello.cr
"Hello, world!" from MRuby embedded in Crystal
export MRUBY_HOME=/opt/rubies/mruby-20150906
crystal run --link-flags -L${MRUBY_HOME}/lib/ hello.cr
@kbrock
kbrock / evm.log
Created September 4, 2015 15:40
evm.log with pruned timestamp to reduce width
# Logfile created on 2015-09-04 10:56:03 -0400 by logger.rb/47272
[-] I 10:56:03.728893 #13407] : MIQ(Vmdb::Loggers.apply_config) Log level for vim.log has been changed to [WARN]
[-] I 10:56:05.020030 #13407] : MIQ(Vmdb::Initializer.init) - Program Name: /Users/kbrock/.gem/ruby/2.2.2/bin/rake, PID: 13407, ENV['MIQ_GUID']: , ENV['EVMSERVER']:
[-] I 10:56:05.024106 #13407] : MIQ(Vmdb::Initializer.init) - Init complete
[-] I 10:56:05.711462 #13407] : MIQ(EvmApplication.start) EVM Startup initiated
[-] I 10:56:10.646710 #13413] : MIQ(Vmdb::Loggers.apply_config) Log level for vim.log has been changed to [WARN]
** EVM vmdb_development ** 1
[-] I 10:56:11.568937 #13413] : MIQ(Vmdb::Initializer.init) - Program Name: /Users/kbrock/src/manageiq/bin/rails, PID: 13413, ENV['MIQ_GUID']: , ENV['EVMSERVER']:
[-] I 10:56:11.572899 #13413] : MIQ(Vmdb::Initializer.init) - Init complete
[-] I 10:56:12.233358 #13413] : MIQ(MiqServer.validate_database) Database Adapter: [PostgreSQL], version: [PostgreSQL 9.2.8 on x86_64-apple-d

You may find yourself in a situation where you have a modified v2_key.dev, and are missing a v2_key.

that is easy to fix:

mv v2_key.dev v2_key
git checkout v2_key.dev

@kbrock
kbrock / sort_test.rb
Last active August 27, 2015 00:52
Testing different ways to bring back active records by the source ids
#!/usr/bin/env ruby
require 'ostruct'
require 'byebug'
module Enumerable
def index_by
if block_given?
Hash[map { |elem| [yield(elem), elem] }]
else
to_enum(:index_by) { size if respond_to?(:size) }