Skip to content

Instantly share code, notes, and snippets.

View daviddavis's full-sized avatar

David Davis daviddavis

View GitHub Profile
@daviddavis
daviddavis / prime_factorization.rb
Created February 15, 2012 14:52 — forked from masassiez/prime_factorization.rb
#42@Rubeque - Prime Factorization
def prime_factorization(num)
prime = Enumerator.new do |y|
mem = []
is_prime = lambda { |e| mem.find { |_| e.gcd(_) != 1 } }
2.upto(num) do |n|
unless is_prime[n]
mem << n
y << n
end
code = "__ == __ == Date.parse(date.sub(/(\d+)[-\/](\d\d).(\d{4})/,'\\3-\\1-\\2')).strftime('%b %d, %Y')"
sub = "Date.parse(date.sub(/(\d+)[-\/](\d\d).(\d{4})/,'\\3-\\1-\\2')).strftime('%b %d, %Y')"
code.gsub("__", sub) # Date.parse(date.sub(/(d+)[-/](dd).(d{4})/,'--'))...
code["__"] = sub # only fill in one at a time. fails when sub = "__method__"
code.split("__").join(sub) # ugly but seems to work
@daviddavis
daviddavis / html.vim
Created July 5, 2012 23:15
Fix to the annoying way vim handles indentation in p and li tags
" this goes in ~/.vim/after/indent/html.vim
let g:html_indent_tags = g:html_indent_tags . '\|li\|p'
@daviddavis
daviddavis / .vimrc
Created August 30, 2012 17:06
vimrc for Ruby
" set up tabs for all files (recommended)
set ts=2
set et
set softtabstop=2
set sw=2
" OR
@daviddavis
daviddavis / readinglist.md
Created August 30, 2012 23:24
Summer reading list
Do Androids Dream of Electric Sheep?
Of Mice and Men
The Stranger
A Clockwork Orange
Breakfast at Tiffany's
The Willows
The Old Man and the Sea
Frankenstein
dadavis@dhcp-230-216 ~ % katello -u admin -p admin ping
Service unavailable or restarting, try later
@daviddavis
daviddavis / user_test.rb
Created October 10, 2012 19:35
User test
#
# Copyright 2012 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
@daviddavis
daviddavis / user_factory.rb
Created October 11, 2012 20:56
User factory
factory :user do
username "ehelms"
email "ehelms@redhat.com"
password "Secret1234"
disabled false
trait :with_admin_role do
after_build do |user|
admin_role = Role.find_by_name("ADMINISTRATOR") || FactoryGirl.build(:admin_role)
user.roles = [admin_role]
# set environment variable BUNDLER_ENABLE_RPM_PREFERRING to 'true' to enable bundler patch
# if enabled bundler prefers rpm-gems even if they are older version then gems in gem-repo
if ENV['BUNDLER_ENABLE_RPM_PREFERRING'] == 'true'
require File.join(File.dirname(__FILE__), 'lib', 'bundler_patch_rpm-gems_preferred')
end
# load Katello configuration
path = File.expand_path('../lib', __FILE__)
$LOAD_PATH << path unless $LOAD_PATH.include? path
require 'katello_config'
λ f16p2 ~ks → λ git pulpv2_merge* → rake minitest:glue mode=all
/home/dadavis/Projects/katello/src/app/models/foreman/architecture.rb:14: warning: toplevel constant IndexedModel referenced by Resources::AbstractModel::IndexedModel
/home/dadavis/Projects/katello/src/app/models/foreman/domain.rb:14: warning: toplevel constant IndexedModel referenced by Resources::AbstractModel::IndexedModel
/home/dadavis/Projects/katello/src/app/models/foreman/subnet.rb:14: warning: toplevel constant IndexedModel referenced by Resources::AbstractModel::IndexedModel
/usr/lib/ruby/gems/1.8/gems/activesupport-3.0.10/lib/active_support/test_case.rb:14: warning: already initialized constant Mocha
Run options: --seed 34704
# Running tests:
undefined method `destroy_repo' for nil:NilClass