Hulihan Applications
about projects portfolio services contact_us
Running PHP Inside a Rails App

    

Have you ever wanted to run a PHP application inside of a Rails application? Here's a scenario: your website is written in ruby on rails. You want to run a php application, like Magento inside it, under a directory called shop. Since all web-accessible files in Rails are located in the public directory, your shop directory will be located in public/shop. However, whenever you try to access this directory by going to http://www.yourwebsite.com/shop, You get a 500 error from your Rails application saying: Application error Rails application failed to start properly, or something along those lines. 

Uh Oh.

This is because rails thinks that this subdirectory is a controller or an action within your rails application that isn't acting properly, when in reality, it's a real subdirectory with PHP files inside! We need to convince it otherwise. The easiest way to do this is by creating an .htaccess file inside the shop directory. Then paste this code into the .htaccess file:

RewriteEngine On
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule ^(.*)$ -%2/$1 [QSA,L]

That's it! Try it again, and your PHP code should run without a problem! 

 


Comment_add  (0) Comments




WishlistFactory.com

    We recently started a new website called WishlistFactory.com, that lets families, friends, and other groups of people to create private wishlists for any event or holiday! It's a free service, and it's extremely useful for birthdays and for christmas, and it helps prevent people from getting the same gift twice(or three times, if you're very unlucky). Check it out!

 

 


Comment_add  (0) Comments




Ruby, Arduino, and Serial Communication

    Lately, We've been using the Programmable Arduino Microcontroller with some fun projects. We usually program the Arduino to send data to other devices using Serial Communication. Since we also love ruby, we decided to use Ruby to handle all the communications that the Arduino sends to a computer. With this in mind, I thought I'd share a little tutorial of how you can do this.

In this example, we're going to program the Arduino to send random data(between 0 and 100) over a serial port to a host computer. On the Host computer, we're going to be running a ruby program that will monitor the serial port and print out any data sent to it on the command line. Here's the code(also known as a sketch in arduino lingo) we're going to upload into the Arduino, using the Arduino Software:
/* 
  Feed Simulated data via serial(COM) port to computer.
  This simulated data will be used by a program on the computer to handle serial data from a device.  
*/

void setup() 
{ 
  Serial.begin(9600); 
  Serial.println("Begin Simulated Serial Data Generation!"); 
} 



int interval_time = 500; // Interval between data being sent. (in ms)
int min_num = 1; // min value to generate data, must be above 1
int max_num = 100; // max value to generate
int sim_data = 0; // initialize data var

void loop() 
{ 
  sim_data = random(min_num, max_num);
  Serial.println(sim_data);
  delay(interval_time); // wait
} 
Then, create a new ruby file with following code(we're going to name our ruby file serial_test.rb).
 require 'rubygems'
 require 'serialport' # use Kernel::require on windows, works better.

  #params for serial port
  port_str = "COM3"  #may be different for you
  baud_rate = 9600
  data_bits = 8
  stop_bits = 1
  parity = SerialPort::NONE
  
  sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
  
  #just read forever
  while true do
    sp_char = sp.getc
    if sp_char
      printf("%c", sp_char)
    end
  end
Then execute the script, and you'll see all the data being sent by the Arduino! Here's what you should be seeing:
Begin Simulated Serial Data Generation!
77
35
78
84
86
81
...
You can do anything with the data, depending on your what your goal is. In my case, I'm getting sensor data from the Arduino that I display in a pretty fxruby windows application, then I save the data in a MySQL database for statistical analysis. Fun stuff!

Comment_add  (0) Comments






Hulihan Applications © 2007-2009
No portion of this site may be copied, altered, duplicated or otherwise used without the express written approval of Hulihan Applications.