Skip to content

Instantly share code, notes, and snippets.

View sebglazebrook's full-sized avatar

Seb Glazebrook sebglazebrook

View GitHub Profile
@sebglazebrook
sebglazebrook / gist:9ac4aac479db58ac9d5e
Last active May 11, 2018 05:15
Call jruby from groovy/java
#test_ruby_class.rb
class TestRubyClass
attr_accessor :name, :birth_year
def initialize
@name = 'Yukihiro Matsumoto'
@birth_year = 1965
end
def average(array)
array.inject(0) { |memo, element| memo += element } / array.size
end
def calculate_deviation(value, average)
value >= 0 ? value - average : average - value
end
def solution(a)
def average(array)
array.inject(0) { |memo, element| memo += element } / array.size
end
def calculate_deviation(value, average)
value >= 0 ? value - average : average - value
end
def solution(a)
extreme_element_index = -1
@sebglazebrook
sebglazebrook / Groovy read file from package
Last active August 29, 2015 13:56
Read text file from a package
// Quite different to ruby. Took me a little longer to find out how to do it than it should.
def template(filename) {
def input = getClass().getResourceAsStream("/path/to/package/${filename}.template")
new InputStreamReader(input, 'utf-8')
}
// If file is in your 'resources' folder then use the below
def templateFromResources(filename){
def input = getClass().getResourceAsStream("templates/${filename}.template")
new InputStreamReader(input, 'utf-8')
@sebglazebrook
sebglazebrook / ruby-2-centos
Created September 24, 2013 23:21
Install Ruby 2 on Centos
# be root :-)
sudo su -
cd /tmp
# remove existing
yum -y remove ruby
# install dependencies
yum -y groupinstall 'Development Tools'