Skip to content

Instantly share code, notes, and snippets.

@arturaz
arturaz / gist:1214959
Created September 13, 2011 20:03
Ruby side
lambda do
jar_path = File.join(ROOT_DIR, 'vendor', 'SpaceMule', 'dist', 'SpaceMule.jar')
# Win32 requires us to manually require all the jars before requiring
# main jar.
Dir[File.dirname(jar_path) + "/lib/*.jar"].each { |jar| require jar }
require jar_path
# Scala <-> Ruby interoperability.
class Object
@arturaz
arturaz / gist:1214962
Created September 13, 2011 20:04
Scala side
object Finder {
def find(
source: Locatable,
sourceJumpgates: Set[SolarSystemPoint],
sourceSs: Option[SolarSystem],
sourceSsGalaxyCoords: Option[Coords],
target: Locatable,
targetJumpgates: Set[SolarSystemPoint],
targetSs: Option[SolarSystem],
targetSsGalaxyCoords: Option[Coords],
@arturaz
arturaz / gist:1214967
Created September 13, 2011 20:05
Call args
[#<Java::SpacemuleModulesPathfinderObjects::GalaxyPoint:0x46c34>, #<Java::ScalaCollectionImmutable::HashSet:0x838d2a>, Java::Scala::None, Java::Scala::None, #<Java::SpacemuleModulesPathfinderObjects::GalaxyPoint:0x1af2cc0>, #<Java::ScalaCollectionImmutable::HashSet:0x166d133>, Java::Scala::None, Java::Scala::None, Java::Scala::None]
object Finder {
def test(t: Option[Int]) { println(t.get) }
}
>> SpaceMule::PfO.Finder.test(Some(3))
3
=> nil
>> SpaceMule::PfO.Finder.test(None)
NameError: no method 'test' for arguments (org.jruby.RubyClass) on Java::SpacemuleModulesPathfinderObjects::Finder
object Finder {
def none = None
def test(t: Option[Int]) { println(t.get) }
}
>> f = SpaceMule::PfO.Finder
=> Java::SpacemuleModulesPathfinderObjects::Finder
>>
?> f.test(f.none)
NativeException: java.util.NoSuchElementException: None.get
@arturaz
arturaz / gist:1231932
Created September 21, 2011 12:43
SpaceMule
lambda do
jar_path = File.join(ROOT_DIR, 'vendor', 'SpaceMule', 'dist', 'SpaceMule.jar')
# Win32 requires us to manually require all the jars before requiring
# main jar.
Dir[File.dirname(jar_path) + "/lib/*.jar"].each { |jar| require jar }
require jar_path
# Scala <-> Ruby interoperability.
class Object
@arturaz
arturaz / gist:1231939
Created September 21, 2011 12:46
SpaceMule::Pathfinder
# Invokes SpaceMule pathfinder.
module SpaceMule::Pathfinder
# Scala constants
Coords = SpaceMule::Pmg.classes.geom.Coords
Pf = SpaceMule::SmModules.pathfinder
PfO = Pf.objects
def self.invoke(source, target, avoid_npc)
avoidable_points = []
Server has encountered an error!
UNEXPECTED EXCEPTION: java.lang.RuntimeException: could not shut down process: java.lang.UNIXProcess@fde438
Message:
{"params":{"version":"2011-1104-1211","web_player_id":2567,"server_player_id":909},"id":"1320523371429","action":"players|login"}
Backtrace:
org.jruby.RubyIO.obliterateProcess(RubyIO.java:4049)
org.jruby.util.ShellLauncher$POpenProcess.destroy(ShellLauncher.java:886)
org.jruby.RubyIO.obliterateProcess(RubyIO.java:4053)
org.jruby.RubyIO.close2(RubyIO.java:1998)
RSpec::Matchers.define :be_created_from_static_ss_configuration do
|configuration|
def check_planet(position_str, ss_conditions, data)
exp_to = "Expected planet @ #{position_str} to"
if SsObject::Planet.where(ss_conditions).exists?
planet = SsObject::Planet.where(ss_conditions).first
owned_by_player = ! planet.player_id.nil?
@errors << "#{exp_to} have owned_by_player: #{data["owned_by_player"]
jruby-1.6.5 :018 > c = ActiveRecord::Base.connection.raw_connection.with_connection_retry_guard { |c| c }
=> #<Java::ComMysqlJdbc::JDBC4Connection:0x1200320>
jruby-1.6.5 :019 > c.create_statement
=> #<Java::ComMysqlJdbc::StatementImpl:0x16f974f>