Skip to content

Instantly share code, notes, and snippets.

View jorgenpt's full-sized avatar

Jørgen Tjernø jorgenpt

View GitHub Profile
@jorgenpt
jorgenpt / lazyobject.rb
Created February 27, 2011 06:19
Create on use
# Class to easily instantiate an object when needed.
# Similar to using (object ||= Foo.new).bar, but stores the initialization code to make
# the code cleaner.
class LazyObject
@object = nil
def initialize(&code)
@init = code
end
def was_initialized?
Oct 25, 2011 6:54:42 PM hudson.ExpressionFactory2$JexlExpression evaluate
WARNING: Caught exception evaluating: descriptor.getPropertyType(instance,field).itemTypeDescriptorOrDie. Reason: java.lang.reflect.InvocationTargetException
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.commons.jexl.util.PropertyExecutor.execute(PropertyExecutor.java:125)
at org.apache.commons.jexl.util.introspection.UberspectImpl$VelGetterImpl.invoke(UberspectImpl.java:314)
at org.apache.commons.jexl.parser.ASTArrayAccess.evaluateExpr(ASTArrayAccess.java:185)
public FormValidation doCheckOsVersion(@QueryParameter String value) {
return doCheckOsVersion(value, true).getFormValidation();
}
private ValidationResult doCheckOsVersion(String osVersion, boolean allowVariables) {
if (osVersion == null || osVersion.equals("")) {
return ValidationResult.error(Messages.OS_VERSION_REQUIRED());
}
if (!allowVariables && osVersion.matches(Constants.REGEX_VARIABLE)) {
return ValidationResult.error(Messages.INVALID_OS_VERSION());
@jorgenpt
jorgenpt / objc_calling.rb
Created November 3, 2011 08:15
Objective-C-esque calling convention in Ruby (or: Why I shouldn't be let near method_missing)
# See the bottom of the file for how this actually works.
module ObjC
def method_missing(method, *args)
ObjCCall.new(self, [], []).send(method, *args)
end
end
class ObjCCall
def initialize(obj, selector, args)
@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?
# 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)
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"
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"
@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);
}
-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