Eric Guo's blog.cloud-mes.com

in HTML5, JavaScript, Ruby & Rails, Python, and Cloud MES!

Compile Eventmachine 1.0.3 in Ruby 2.1.3 on Windows

Permalink

eventmachine didn’t release a new gems for a long time, so we have to manually compile if you decide using Ruby 2.1.3, it’s probably the most complex gems which can still successfully install on windows as far as I known, here is the steps for your interesting:

git clone https://github.com/eventmachine/eventmachine
cd eventmachine && bundle install

Now you will meet the bluecloth can not install problem first, which you can following stackoverflow steps including patch ext/bluecloth.h and 6 steps.

Now you need using updated version of rake-compiler (v0.9.3) to continue, so change eventmachine.gemspec to that version and do the bundle install again.

Now we can running rake package and it should generate the updated 1.0.3 gem file you need, but before that you need another depend lzma package mentioned in Ruby Installer Google Group, I only tested x86 but the x64 should be same.

  1. Put the download openssl-1.0.0m-x86-windows.tar.lzma to c:\temp
  2. run C:\DevKit\devkitvars.bat
  3. c:\Temp> bsdtar --lzma -xf sqlite-3.7.15.2-x86-windows.tar.lzma
  4. c:\git\eventmachine\pkg> gem install ./eventmachine-1.0.3.gem --platform=ruby -- --with-opt-dir=C:/Temp

Now enjoy eventmachine on ruby 2.1.3 windows!

Checking Gem Reverse Dependencies

Permalink

gem dependency parser --reverse-dependencies or -R in short only works in local, so if you want to get all gems from rubygems, can using:

ruby -ropen-uri -rpp -ryaml -e 'pp YAML.load(open("https://rubygems.org/api/v1/gems/parser/reverse_dependencies.yaml"))'

The tip is coming from Faria DevTips.

Installation Ruby 2.1.3 on Windows Log

Permalink

Except simply install the ruby 2.1.3 from rubyinstaller and it’s DevKit, here is my log when I meet the problem during ruby 2.1.3 on a Windows 7 32bits machine.

  1. Comments out the warn “DL is deprecated, please use Fiddle” at C:\Ruby21\lib\ruby\2.1.0\dl.rb
  2. Install yajl-ruby via gem install yajl-ruby -v 1.1.0 --platform ruby
  3. Install RedCloth via gem install RedCloth --platform ruby and move the file C:\Ruby21\lib\ruby\gems\2.1.0\gems\RedCloth-4.2.9\lib\redcloth_scan.so to new created folder C:\Ruby21\lib\ruby\gems\2.1.0\gems\RedCloth-4.2.9\lib\2.1.
  4. Install sqlite3 via:

    1. run C:\DevKit\devkitvars.bat
    2. mkdir c:\temp
    3. download http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma to c:\temp
    4. c:\Temp>bsdtar --lzma -xf sqlite-3.7.15.2-x86-windows.tar.lzma
    5. c:\Temp>gem install sqlite3 --platform=ruby -- --with-opt-dir=C:/Temp
  5. Install bcrypt via gem install bcrypt --platform ruby

  6. Install win32console via gem install win32console --platform ruby

  7. Install ffi via gem install ffi --platform ruby

  8. Install pg via gem install pg --platform ruby

  9. Install mysql following stackoverflow

Setting global environment setting:

CURL_CA_BUNDLE=C:\Ruby21\share\ca-bundle.crt
SSL_CERT_FILE=C:\Ruby21\share\cacert.pem
NLS_LANG=AMERICAN_AMERICA.UTF8

Also do not using ansicon in ruby 2.1.3 any more, seems not compatible.

How to Install Gem Curb in Windows

Permalink

After read the post in Ruby-China say how to use mechanize and curl to login Ruby-China, I decide to install curb, seems still a little tricky.

First download last available libcurl in windows, which currently is 7.34.0.

Extract to C:\ and install the curb via below command.

gem install curb --platform=ruby -- --with-curl-lib=C:/curl-7.34.0-devel-mingw32/bin --with-curl-include=C:/curl-7.34.0-devel-mingw32/include

Some relative issues in github about curb, #37, #183

To make SSL certification work, you need to set your windows environment variable, the file can be download here

CURL_CA_BUNDLE=C:\Ruby200\bin\ca-bundle.crt
SSL_CERT_FILE=C:\Ruby200\bin\cacert.pem

Finally, need copy all DLL and EXE file in C:\curl-7.34.0-devel-mingw32\bin to C:\Ruby200\bin.

Unlock the Locked Table by Kill Session

Permalink

Seems I frequently need to kill some session due to the network issue or other client issue to submit data to oracle, but each time I google the answner, it takes me at least 5 minutes, so I decide to write done SQL and command here:

Find the locked session
SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal,
b.object_id,substr(b.object_name,1,40) object_name
from v$session a, dba_objects b, v$locked_object c
where a.sid = c.session_id
and b.object_id = c.object_id
Kill session
alter system kill session '14,397';

Postback Other Input Controls Value in Rails Jquery-ujs Data-remote Request

Permalink

The Unobtrusive JavaScript feature introduce from Rails 3.1 and the Rails Guide have a whole chapter to say about how to use, but the jquery-ujs much more feature not talked in official Rails Guide.

Except the AJAX forms and some link_to feature, one of my favorite features is AJAX HTTP request back to server when one of the forms input control content changed by user and lost focus. Such feature is very similar to ASP.NET AutoPostBack, which is very handy when you need user fill some content first before you can help them auto fill the rest.

Some Trick to Install Native Gems in Win32 Ruby 2.0.0-p451

Permalink

I used to write post about install ruby 2.0.0-p195 in windows one years ago, the ruby language improved a lot this year and it’s gems. But windows platform is still not active compare with Mac OS X or Linux in rubyist.

There are two thick I believe worth to write down for the windows rubyist:

Install debugger

  1. clone the debugger-ruby_core_source to local folder, e.g. C:\git\debugger-ruby_core_source
  2. copy C:\git\debugger-ruby_core_source\lib to C:\Ruby200\lib\ruby\gems\2.0.0\gems\debugger-ruby_core_source-1.3.2
  3. gem install debugger.

Install bson

Modify the win32.h file (@C:\Ruby200\include\ruby-2.0.0\ruby) before install gems bson

insert _PC_64 and _MCW_PC define
static inline double
rb_w32_pow(double x, double y)
{
return powl(x, y);
}
#elif defined(__MINGW64_VERSION_MAJOR)
#ifndef _PC_64
#define _PC_64 0x00000000
#endif
#ifndef _MCW_PC
#define _MCW_PC 0x00030000
#endif
/*
* Set floating point precision for pow() of mingw-w64 x86.
* With default precision the result is not proper on WinXP.
*/