Skip to main content

Posts

Showing posts from 2007

Session problems with Mongrel and Jruby on rails

If you get a "wrong number of arguments(2 for 1)" in the stale_session_check method when running your jruby ruby on rails application, the problem may be your sessions. Clear the sessions and delete all rows from the sessions database table if you are using one. Then add to environment.rb: config.action_controller.session = { :session_key => "_myapp_session", :secret => "some secret phrase of at least 30 characters" } The code has to be inside the Rails::Initializer.run do |config| block.

Rubyscript2Exe is not deleting the temp files once it is done: SOLVED!

Is your Ruby on rails application packed in a exe created by Rubyscript2Exe? Is Ruby2Exe not deleting the temp files once it is done? I came out with the solution of deleting the files of previous run: 1. Replace the contents of init.rb with this: require "rubyscript2exe" require "fileutils" at_exit do require "irb" require "drb/acl" require "dbi" require "dbd/ODBC/ODBC" #Add the libraries you need end if RUBYSCRIPT2EXE.is_compiled? ee_base_folder = File.expand_path(RUBYSCRIPT2EXE.appdir + "/../..") ee_folder = File.expand_path(RUBYSCRIPT2EXE.appdir + "/..") name_parts = ee_folder.split(".") curr_ee_folder_number = name_parts[3].to_i last_ee_folder_number = curr_ee_folder_number - 1 Dir.entries(ee_base_folder).each do |folder| if (folder != ".") and (folder != "..") and (folder.split(".")[3].to_i != curr_ee_folder_number)

Database configuration sample for accessing MS SQL in Jruby's rails

Use NetBeans to create the rails project using Jruby. Make sure you select "use JDBC". The database yml for connecting to MS SQL through ODBC: development: adapter: jdbc username: MYUSERNAME password: "14 if your password starts with a number enclose the password in double quotes" driver: sun.jdbc.odbc.JdbcOdbcDriver url: jdbc:odbc:MYDNSNAME

The easiest way to install Samba 3 with ldap as a domain controller

Acting like a wizard, the Samba/Ldap Installer found in http://www.majen.net/smbldap/ can install and configure Samba as a PDC with openLDAP backend. After finding useless most of the tutorials out there (including the official samba PDC howto) I found this little piece of magic that installed the Samba PDC in the edubuntu server at work. After running the script you need to install BIND9 (a dns server) and webmin (a linux administration web console) to set up a dns to point to your domain server. I still can only log in from windows as root tho; but I will work on solving that problem next week. Another thing I will take a look at is the NTX-grp out-of-the-box solution for open-exchange, which also includes Samba as a PDC with ldap and the dns server.
Want to migrate your rails database to a specific version? Use: rake db:migrate VERSION=# where # is 1 or 2 or 3 .... Want to migrate your production database? Use export RAILS_ENV=production Change production to any other environment you want.

Finish the new Tarpri.com

I decided to help some people by re-designing the Tarpri.com website because the joomla's ez-store component stopped working. Thanks to the ruby-powered, website generator Webgen and websites with open web designs, the process of creating the website went somewhat smooth. If you want to use Webgen to generate your website, you should download the example personal website to learn how to use Webgen. I had a small problem with generating php files; when following the example in the website for outputNameStyle which is the custom page name output format, I got an "invalid URI" message when running webgen. I solved it by using: outputNameStyle: [:name, [”.”, :lang], .php] in the meta info section of the .page file for the English version of the page. outputNameStyle: [:name, ., :lang, .php] in the meta info section of the .page file for the spanish version of the page.

Semi-Automated Mail Merge in OpenOffice

I released a new version of my MailMerger application ( http://rubyforge.org/projects/mailmergehelper/ ) . The application now uses java and ruby to automate the collection and processing of csv data to be merged. It uses a java class that can transform csv to ods (OpenOffice Calc document) and viceversa and html to ods. The Writer mail merge template must use a datasource that links to an ods spreadsheet. It works with OpenOffice 2.3. The program has helped me alot at work, where we use it to automatically take the html data produced by RenWeb's create-a-report and convert it to ods so that OO Writer can use it for mail merge. The program also allows for custom ruby scripts to process the data before is sent to Writer. I also found that the best way of doing labels in OpenOffice is to download the Microsoft Word templates from the Avery website and then convert them into odt.

Content files not available in Typing Master

I got an error when trying to open Typing Master's User Manager. The error said that the content files were not available. To fix the error, I search for any changes made to the shared Typing Master folder and noticed that the lessons folder was missing. I reinstalled Typing Master to add the folder again. Surprisingly, the re-installation did not delete any of my user data files, all of the student's information was there intact.

How to connect to CSV files using Ruby DBI ODBC and no DSN

I had a hard time finding a way of connecting to csv files using ruby's dbi through the odbc driver without using a DSN. The odbc turned not to work with Microsoft Text driver for odbc because the name of the driver has a semicolon in it. Thus, the ruby code fro the driver was splitting the name of driver, resulting in a keyword syntax error. The following is the (working) code that shows how to connect to csv files using dbi and odbc, note that I had to override require to add the fix to the odbc driver because dbi loads the driver using require : require "dbi" alias :old_require :require def require(library) old_require(library) if library.downcase.include?("odbc") define_odbc_fix() end end def define_odbc_fix DBI.class_eval <<-'THERE' module DBD module ODBC class Driver < DBI::BaseDriver #JPT: fixed to allow the ";" character in the connection string. # Obeys the rule of "If a

Multiline and regular expressions troubles

I had some problems with Ruby on rails while working in the Bullet on rails framework. Regexp.new("(class [^$]+)$", Regexp::MULTILINE) will basically match your whole file until the end. Regexp.new("(class [^\n]+)", Regexp::MULTILINE) will match only the line that starts with "class". Also, if you have problems with JavaScript, try doing rake rails:update:javascript.

Don't drop, remove!

When you want to completely erase an scene node from your irrlicht scene, use renmoveALL and remove instead of drop. It happened to me that I was just dropping and then deleting the object C style, however the scene manager still had a grab on the node because the node was loaded from an irr file and therefore was giving me a runtime exception.

Directional player-controlled character movement

I finally was able to replicate in CalvaryGDK directional player-controlled character movement that you find in 3rd person games and platform games. The trick is to set the linear velocity to zero on all axis. Recommended for human movement behavior. The changes are in the SVN trunk at sourceforge. I will try to make a classic spaceship game with Calvary and released soon (maybe this weekend?). //move the object using forces but stop forcing after a speed is reached // only ONE of the components should be filled. RubyMethod move_forced(VALUE self, VALUE x, VALUE y, VALUE z, VALUE max_speed) { guard(GameObject.move_forced); CWorldObject *obj = internal(self); //std::cout << "\n --> move_forced " << obj; float cx = RubyFloat::internal(x); if (cx != 0.0f) { //std::cout << "\n X velocity " << obj->GetLinearVelocity().X; if (abs(obj->GetLinearVelocity().X) < RubyFloat::internal(max_speed))

No bones

Don't use custom moving bones for animations. Just Take a apart every part of the mesh and export it on its own. Because they all have a 0,0,0 origin, the end result should be the same character being displayed.

Back to rails! (only for a while tho)

Got so excited with focus sis and rails at work that I decided to work on a new personal project. The new project will help new and advance users to use a simple GUI to create web applications based in rails. The project's aim is to have the same easiness to use that MS Access has. However, thanks to the power of ruby on rails, the end result could be a MS Access killer :). Tonight, I worked on the code to generate forms from a GUI wizard.

Angular factor now works

Setting the angular factor on my 3d object was not working. Then I realize that I had left out the RubyFloat::internal method call to convert the VALUE passed into a c++ float. Without the conversion, the RubyGameObject was passing a value of 1 to the set_angular_factor method. Now the 3d object's position is affected by physics but not its rotation, which is good for character control. RubyMethod set_angular_factor(VALUE self, VALUE angular_factor) { guard(GameObject.set_angular_factor); CWorldObject *obj = internal(self); obj->set_angular_factor(RubyFloat::internal(angular_factor)); //line that had the problem return Qnil; unguard }

The Isometric soldier now shoots

I finished the GML code to make the soldier shoot in a isometric environment. The bullet consists of two parts: the graphic bullet and its shadow. The graphic bullet takes care of holding the information about the bullet and how to draw it. The shadow is always at certain distance below the graphic bullet depending on the bullet's height and takes care of collisions (it checks at ground surface for realistic isometric collisions). This is the code to create the bullet in a Game Maker script that runs from the isometric player object's perspective: { the_bullet = instance_create(x,y - height - 5,bullet); the_bullet.direction = point_direction(the_bullet.x,the_bullet.y,user_hud.x,user_hud.y) the_bullet.speed = 5 the_bullet.user_hud = user_hud; the_bullet._height = height - 5; the_bullet._shadow = instance_create(the_bullet.x,the_bullet.y,bullet_shadow); }

Why I prefer GameMaker over Multimedia Fusion

Update (5/1/12): I wrote a new article about Construct2 and why I think is now a better solution than both MMF and GameMaker for making games. Please check that new article. MMF doesn't have enough power for me. Yes, it has all those hundreds of extensions, but you can't just re-use your code in a practical way. Let's face it, GameMaker is ages more object-oriented than MMF and it has as well many extensions (such as physics and 3d) anyways. Also, the GM graphic editor has advance features such as colorize (useful in RTSs), outline, multiple crop, scaling sequence (for your mod 7 games), blur and more. Another advantage is price, GM is free and it's more powerful registered version is only around 20 bucks. Now, GM can be daunting to learn and use, but once you master it you will love it. Furthermore, I am working on a GM big template that will allow the user to have handy pre-made code just like in MMF making the use of GM much simpler. The screen shot is another

Let my memory go!

The function that frees allocated memory when a C++ ruby object is no longer referenced now works. The function is called freeme and is sent to Ruby via Data_Wrap_Struct. The freeme function takes as a parameter a pointer to the actual C++ object. Ruby passes that object when ruby objects no longer reference the Ruby object that encapsulates the C++ object. Unfortunately I could not make the character control work. The md2 models didn't get imported well into Irrlicht either. Also, the physics callback allows the C++ app class to inform Ruby when a collision occurred and who collided. I will try to work more on that feature to make it more powerful.

Solved the problem with bounding boxes

The ball in my test was not being stopped by the box blocks. All the blocks use the same 3ds mesh but modified for each of the 4 using irrEdit. The problem lied on the code trying to get the non-transformed bounding box from the irrlicht scene node and using that wrong sized bounding box to create the shape for the Bullet physics engine. I replaced the getBoundingBox () call in my code for getTransformedBoundingBox(). Now the ball does get stopped.

Another day of hard work

The grades publishing software that we use at the school is not really nice. We will try to change it to something better and easier to use. I have not switched to Dvorak layout yet. CalvaryGDK is the focus of my attention. I am working on making a platform controller that will enable an object to jump, run and more with the user input. For running the plan is to apply force only if the current velocity of the object is less than the maximum velocity. Still don't know what I am going to do for jumping, but could be something similar taking the Y component of velocity into account.

CalvaryGDK is taking shape

CalvaryGDK now has the ability to apply forces relative to another object such as a camera, e.g.: a controller class can direct the player in 4 directions of the view of the camera and not the absolute coordinates. When using this feature, the physics class object will rotate the given force vector by the degrees of rotation of the reference node on the specified axis. I also tried Webgen, a very nice ruby program to generate web sites. I may use it to do the projects websites.

More troops???

Bush wants to put more troops in Iraq. The majority of American people doesn't want him to do it and wants the troops to come back soon. My favorite news magazine, The New America wants the troops to come home too and denounce the war as unconstitutional. I kinda I agree with them. I have seen many TV shows discussing the war but none of them answered my questions: 1. Are more troops the answer for guerrilla warfare? By that I mean: is there any statistical proof from any country that solved its insurgency problems by military strength? 2. Is there any country that has solved its insurgency problems? 3. What it means to win ? Chenney's wife asked an interviewer if he wanted the U.S. to win. But what exactly is winning? Getting rid of Saddam, disabling WMDs threats, force democracy in Iraq, making Iraq a perfect paradise or protecting the U.S. from terrorist's hate? 3. if winning means making Iraq a perfect paradise, there were more than 1000 homicide victims in just Ne

First day of work

I finally got back to work at the school today. Only teaching one class tho. It is a pretty nice computer class. Got lots of work because we are sending report cards this week. I really don't like WinSchool; it is too complicate to use for the average user. I am gonna look for a better alternative, probably open source one. Seems like it is going to be a blessed semester tho, Praise the Lord. Pastor Schettler is here preaching the revival and the people like him a lot, he is very good.

Don't make! just wrap!

I finally got rid of the segmentation fault. rubynative.h had the problem. When initializing the ruby version of the C++ class, the code was using Data_Make_Struct. While looking over the web I found that other people have trouble with it and C++. I decided to try Data_Wrap_Struct instead. To accomplish that I first create a normal instance of my C++ class using new . Then, I pass the created object to the modified construct(VALUE &object, T *obj) function in rubynative.h : static T* construct(VALUE &object, T *obj) { object = Data_Wrap_Struct(rubyClass(), 0, free, obj); return obj; } Now it works, but the C++ class' destructor is never called so I guess I have a memory leak. However, the ruby script works now using the extension and it actually displays a ball affected by gravity falling into a table. I already coded the feature to allow changing of cameras from ruby and passing of physical parameters through the node's name defined in Irre

Searching for the truth in my extension

After having the segmentation fault, I did what any good developer does: put cout to print messages all over my code. Thanks to it I was able to "fix" the line: *instance = CApp2(RubyInt::internal(width), RubyInt::internal(height), RubyString::internal(scene_file)); into: instance = new CApp2(RubyInt::internal(width), RubyInt::internal(height), RubyString::internal(scene_file)); I also found out that somehow some of my pointers that are instance variables of the C++ class are getting set to zero. That is why I now get a segmentation fault again because I try to use them when they are zero. Maybe Ruby is setting them to zero? but why? I could not find anything on the web to help. Look at the output from the ruby program: >ruby Test.rb *** initialized CApp2 module *** *** Done initialized CApp2 module *** *** Creating instance *** In contructor b4 Assigning static m_pPhysicsWorld = 03016000 Assigning static Finished static Irrdevice = 03000EF0 *** Done Crea

Switched to Bullet Physics engine

I completely revamped my CalvaryGDK to use somebody else's example of Bullet + Irrlicht. I am working now on building the Ruby extension. When I tested it I got this nasty message: "[BUG] Segmentation fault"