Skip to content

Instantly share code, notes, and snippets.

View jorgenpt's full-sized avatar

Jørgen Tjernø jorgenpt

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jorgenpt on github.
  • I am jorgenpt (https://keybase.io/jorgenpt) on keybase.
  • I have a public key whose fingerprint is C54B EFD5 C4CF 4AEE D568 9A3C CEE2 5916 07D6 4BF0

To claim this, I am signing this object:

@jorgenpt
jorgenpt / wrapper.sh
Last active August 29, 2015 14:01
steam-runtime launcher script for use outside of Steam
#!/bin/bash
# Path relative to the directory where the executable lives.
JPT_STEAM_RUNTIME_LOCATION='steam-runtime'
# Figure out where this script lives.
exedir="$(cd "$(dirname "$0")" && pwd)"
# If this script is named `foo.sh' or `foo', we execute `foo.bin'
exename="$(basename "$0" ".sh").bin"
@jorgenpt
jorgenpt / extract_runtime.sh
Created May 26, 2014 01:33
Helper scripts to update & extract the steam-runtime for direct distribution.
#!/bin/bash -e
# Helper script for extracting the steam-runtime that:
# - Strips unused parts of the runtime (documentation)
# - Allows you to extract a single architecture
# - Extracts it to a directory that doesn't contain the runtime date.
function fatal() { echo "$@" >&2; exit 1; }
if [ $# -lt 3 ]; then
fatal "Usage: $0 <steam-runtime path> <amd64|i386|all> <output directory>" >&2
// To be run on https://store.steampowered.com/account/history/
function parseTotals()
{
var transactions = document.getElementsByClassName('wallet_table_row');
var totals = { usd: 0, eur: 0 };
for (var i = 0; i < transactions.length; ++i)
{
var transaction = transactions[i];
var items = transaction.getElementsByClassName('wht_items')[0];
if (items && items.innerText.indexOf('Wallet Credit') >= 0)
@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)