Skip to content

Instantly share code, notes, and snippets.

View kbrock's full-sized avatar

Keenan Brock kbrock

View GitHub Profile
@kbrock
kbrock / gist:4177712
Created November 30, 2012 18:52
ugly package list
#aptitude (/ search, + install, gg - go)
contents
apt-file list $*
install
apt-get install
upgrade
apt-get upgrade
remove
apt-get --purge remove $*
list installed
# Create a file: config/torquebox_remote.rb
TorqueBox::RemoteDeploy.configure do
torquebox_home "/usr/local/torquebox"
jruby_home "/usr/local/jruby"
hostname "10.0.3.50"
#port "22"
user "deployer"
key "#{ENV['HOME']}/.ssh/deployer_rsa"
#sudo true
end
@kbrock
kbrock / timing.rb
Created December 21, 2012 15:00
timing custom string interpolation
require "benchmark"
require 'erb'
d=Time.now
Benchmark.bm(20) do |x|
# the ultimate, but still can't figure out how to generate something that can be interpolated
x.report("n - str") { 100_000.times {
"abc #{d.hour < 10 ? '0' : ''}#{d.hour} #{d.min < 10 ? '0' : ''}#{d.min} cdef"
} }
@kbrock
kbrock / windowing.sql
Last active December 30, 2015 00:59
Using windowing function to do multiple smaller limits. Give me the first 3 records (for each grouping) If you use limit, this will require 1 query to determine the groupings, and one limit queries per each grouping. N+1
create table windowing_example (id int, counter int);
-- id is the common component of the rows
-- counter is the timestamp / other id where ordering is introduced
insert into windowing_example(id, counter) values
(1, 1),
(1, 2),
(1, 3),
(1, 4),
(1, 5),
@kbrock
kbrock / gitconfig
Last active August 29, 2015 14:02
gitconfig
[alias]
st = status
br = branch
co = checkout
cat = show
#origin = !sh -c 'git remote add -t ${2:-master} -m ${2:-master} ${1:-origin} ${0}'
prune = fetch --prune
#amend keeping the same comment
amend = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
# add file to .gitignore
digraph G {
label = "Enterprise"
rankdir = "TB";
node [ shape="Mrecord" ]
edge [ color="#555555"; dir="back"]
subgraph cluster_1 {
label = "Region: 1"
color = "#000000"
#!/usr/bin/env ruby
require 'nokogiri'
src =<<EOD
<wrapper xmlns="ns" xmlns:extra="extra">
<record xml:id="r1">
<field>aaa</field>
<field extra:type="second">bbb</field>
</record>
@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) }

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 / 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