Skip to content

Instantly share code, notes, and snippets.

View jorgenpt's full-sized avatar

Jørgen Tjernø jorgenpt

View GitHub Profile
module Jenkins::Model
class CLICommand
def self.short_description(short_description = nil)
@short_description = short_description if short_description
@short_description
end
def short_description
@@short_description
end
a = 1
def a; 2; end
puts a # => 1
puts a() # => 2
b = 5
def b(foo); foo * foo; end
puts b # => 5
@jorgenpt
jorgenpt / color_scaling.rb
Created January 19, 2012 19:33
Things you shouldn't use Ruby for, #63
# Returns the framebuffer as an array of floats ranging from 0 to 1, ordered
# like [A, R, G, B, A, R, G, B, ..]
def to_a
red_mask = mask(@header.red_length)
green_mask = mask(@header.green_length)
blue_mask = mask(@header.blue_length)
alpha_mask = mask(@header.alpha_length)
red_max = (1 << @header.red_length) - 1.0
green_max = (1 << @header.green_length) - 1.0
@jorgenpt
jorgenpt / create_magick_image.rb
Created January 18, 2012 01:54
Ruby function to convert 565 & 555 format data into a Magick::Image
require 'rmagick'
def create_magick_image(input, width, height, bpp)
mode = 'RGB'
case bpp
when 15
data = input.unpack('v*').collect do |rgb|
rgb = rgb & 0x7fff
red = (rgb >> 10) / 31.0
green = ((rgb >> 5) & 31) / 31.0
-obfuscate:
[mkdir] Created dir: /Users/jtjerno/Projects/wd@2/Android/App/bin/proguard
[jar] Building jar: /Users/jtjerno/Projects/wd@2/Android/App/bin/proguard/original.jar
BUILD FAILED
/Users/jtjerno/Android/sdk/tools/ant/build.xml:713: /Users/jtjerno/Projects/wd@2/Android/App/2/Android/App/bin/proguard/original.jar (No such file or directory)
Total time: 4 seconds
@jorgenpt
jorgenpt / gist:1488106
Created December 16, 2011 21:35
Fingerprinting code
FingerprintMap map = Hudson.getInstance().getFingerprintMap();
Map<String,String> fingerprints = new HashMap<String, String>();
FilePath[] list = srcDir.list(expandedFilter);
for (FilePath file : list) {
String digest = file.digest();
map.getOrCreate(null, file.getName(), digest).add(build);
fingerprints.put(file.getName(), digest);
}
Log.i(LOG_TAG, "arguments[" + key + "] = (int)" + Integer.toString(arguments.getInt(key)));
// Prints: arguments[stride] = (int)0
Log.i(LOG_TAG, "arguments[" + key + "] = (String)\"" + arguments.getString(key) + "\"");
// Prints: arguments[stride] = (String)"1"
jruby-1.6.5 :001 > require 'rubygems'
=> true
jruby-1.6.5 :002 > require 'virtualbox'
=> true
jruby-1.6.5 :003 > VirtualBox.version
=> "4.1.2"
# Sets the repository URL based on the given repository.
# Valid uses:
# * use_repository(:github => 'me/my-plugin')
# * use_repository(:github => 'my-plugin') -- Implies hosting under the
# jenkinsci organization.
# * use_repository(:git => 'https://code.google.com/p/my-plugin')
# * use_repository(:svn => 'https://svn.jenkins-ci.org/trunk/hudson/plugins/my-plugin')
def use_repository(opts)
@jorgenpt
jorgenpt / jruby_timeout.rb
Created November 11, 2011 00:59
Workaround for JRuby's timeout not working well with IO.popen
# Workaround for IO.popen.readlines being allowed to block indefinitely even if
# wrapped in a Timeout::timeout call.
#
# Test case:
# $ time jruby -rtimeout -e "timeout(1) { IO.popen('sleep 10').readlines }"
require 'jruby'
module Timeout
def self.timeout(sec, klass=nil)
return yield(sec) if sec == nil or sec.zero?