Skip to content

Instantly share code, notes, and snippets.

View iNecas's full-sized avatar
💭
Happy hacking 👨 ⌨️ 💻

Ivan Necas iNecas

💭
Happy hacking 👨 ⌨️ 💻
View GitHub Profile
SCRATCH_REPO=http://inecas.fedorapeople.org/dynflow-scratch/
# Install Katello as usual + following commands before katello-intaller
yum install -y\
$SCRATCH_REPO/ruby193-rubygem-algebrick-0.4.0-2.el6.noarch.rpm\
$SCRATCH_REPO/ruby193-rubygem-apipie-params-0.0.3-1.el6.noarch.rpm\
$SCRATCH_REPO/ruby193-rubygem-dynflow-0.2.0-1.git.0.03c40d9.el6.noarch.rpm\
$SCRATCH_REPO/ruby193-rubygem-foreman-tasks-0.1.3-1.el6.noarch.rpm
@iNecas
iNecas / custom_plan.rb
Last active August 29, 2015 13:56
Put this files into the foreman dir, run `bundle exec zeus start`, and then `zeus test ../katello/test/actions/` to run all the action tests
require 'zeus/rails'
class CustomPlan < Zeus::Rails
# def my_custom_command
# # see https://github.com/burke/zeus/blob/master/docs/ruby/modifying.md
# end
def test_environment
require 'minitest/unit'
MiniTest::Unit.class_variable_set("@@installed_at_exit", true)
gem 'zeus'
@iNecas
iNecas / freeze.rb
Created October 16, 2014 14:18
freeze
class Hell
attr_accessor :temperature
end
hell = Hell.new
hell.temperature = 100
hell.freeze
hell.temperature = 0
@iNecas
iNecas / gist:4324536a0b1fd81d3c66
Created May 18, 2015 16:34
Vagrantfile-multihost
Vagrant.configure("2") do |config|
config.vm.define "my-db-fedora" do |vm|
vm.box = "chef/fedora-21"
vm.provision "ansible" do
ansible.groups = { 'ha' => 'my-ha-fedora' }
ansible.playbook = "my-db.yml"
end
end
config.vm.define "my-ha-fedora" do |vm|
@iNecas
iNecas / read_documentation.rb
Created December 7, 2010 16:12
What happens, when you don't read documentation
# getting first item of array or empty hash, when empty:
# A) Without documentation:
def get_first_item_from_array(array)
unless array.blank?
array.each do |single|
return single
end
end
return {}
@iNecas
iNecas / versions ordering
Created December 27, 2010 15:39
Ordering major.minor.revision version numbers
# wrong
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort
# => ["10.1.1", "9.13.3", "9.3.2", "9.3.5"]
# right
["9.13.3", "9.3.2", "10.1.1", "9.3.5"].sort_by{|version| version.scan(/\d+/).map(&:to_i)}
# => ["9.3.2", "9.3.5", "9.13.3", "10.1.1"]
@iNecas
iNecas / hash_constructor_differences
Created February 1, 2011 10:29
Difference between Hash.new(arg) and Hash.new(&block)
hash = Hash.new("") # => {}
hash[1] << "Hello" # => "Hello"
hash[2] # => "Hello"
hash = Hash.new{|h,k| h[k] = ""} # => {}
hash[1] << "Hello" # => "Hello"
hash[2] # => ""
@iNecas
iNecas / grouping_block_arguments_example
Created February 1, 2011 11:14
Grouping block arguments example
pscs = {
["Brno", "Hradecká"] => [61200,62100],
["Brno", "Merhautova"] => [61300,61400],
["Brno", "Nezamyslova"] => [61500,63600],
}
pscs.each do |(city, street), street_pscs|
puts "#{street} in #{city} has following PSCs: #{street_pscs.join(", ")}"
end
@iNecas
iNecas / split_with_regexp.rb
Created February 13, 2011 20:54
Advanced string splitting with regexp
string = "<div>ruby</div><div>string</div><div>methods</div>"
# == splitting with regexp
string.split(/<.*?>/)
# => ["", "ruby", "", "string", "", "methods"]
# == and keeping separator in the result
string.split(/(<.*?>)/)