Eric Guo's blog.cloud-mes.com

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

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.
*/

Enable Genymotion Android Emulator Network in Intranet

Permalink

Genymotion is very fast compare to original android simulator, but make it work in Intranet takes me quite a lot of time.

In fact, it’s simple: Open the Oracle VM VirtualBox manager, Settings->Network, Select the Adapter 2 (Adapter 1 is used primary by Genymotion and cannot change), using Bridged Adapter and select the working network card in Intranet (not wireless usually).

Rails With SQL Server Gem Install

Permalink

Ubuntu 12.04 LTS already have the freetds package, so just running below command will install SQL Server support for Rails.

install tiny_tds
apt-get install freetds-dev
gem install tiny_tds
gem install activerecord-sqlserver-adapter
add below line to odbcinst.ini
#/etc/odbcinst.ini
[FreeTDS]
Description = ODBC for Microsoft SQL
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
UsageCount = 1
Threading = 2

About the driver location, you may need to find the libtdsodbc first at via find /usr/lib -name libtdsodbc.so.

add below line to odbc.ini
#/etc/odbc.ini
[FreeTDS-TECN]
Description = MS SQL connection to 'SDSS' database
Driver = FreeTDS
Database = TECN
ServerName = CVPALPIP01
Trace = No
add below line to freetds.conf
#/etc/freetds/freetds.conf
[CVPALPIP01]
host = 10.70.2.77
port = 1433
tds version = 7.0 # or 8.0
add below line to database.yml
tecn:
adapter: sqlserver
dataserver: '10.70.2.77\SDSS'
database: TECN
username: only_read
password: only_read
and using it in model
# app/models/tecn.rb
class Tecn < ActiveRecord::Base
# No corresponding table in the DB.
self.abstract_class = true
establish_connection("tecn")
def readonly?
true
end
end

AutoCAD 2014 Training Notes

Permalink

Just attend company training and below is quick notes/tips coming from trainer.

  • Always using mm as basic unit in drawing, no matteer your are drawing archtecture/mechanical.
  • Workspace setting is to classic, Options->User Preferences for Right-click Customization is set to ½/1 (repeat last cmd/shortcut menu/ENTER) mode is recommand.
  • Notice the Trim is only trim and can not delete whole object.
  • Menu undo is based on action, but Ctrl+Z can undo step in an action.
  • Polar Array can product beautiful result if set very high repeat rate.
  • Layer must be use in practical drawing, if output to A4, line weight should be larger than 0.53mm to see a noticable result.
  • Multiline must explode before trim
  • Overkill can be used to clean duplicate line and it’s original express tools can be load by MENULOAD and select acetmain.cuix.
  • The Block should draw in layer 0.
  • The Block insert allow add negative value to get a mirror effect.
  • Delete Block should use PURGE command
  • Multi Text Text Height is based on the draw dimenstion
  • Multi Text upper side text and down side text should using stack
  • x/400 x is longest line in demension, 14000/400=40
  • Change line type, show detail to adjust the line Global scale factor if the dash style is too small to display completely.
  • You can turn off InfoCenter by change Windows Registry:
[HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R19.1\ACAD-D005:409\InfoCenter]
"InfoCenterOn"=dword:00000000

Enable Directory Listing in Nginx

Permalink

Step 1, setting the autoindex on in conf

server {
listen 80;
server_name cvpforms; #replace your DNS name
server_name cvpforms.sandisk.com;
rails_env development; #development/production
root /var/rails_apps/pl-form/public;
passenger_enabled on;
client_max_body_size 5m;
location /rf_image {
autoindex on;
autoindex_exact_size off;
}
}

Step 2, resolve the 403 forbidden error using below command if you meet such error.

chmod 755 * -R # in /home/pl-form/pl-form/public/rf_image