Friday, September 24, 2010

Rails - RJS ERROR: TypeError element is null

Usually this error is caused by "page.replace_html 'div_1', render()". Do you have "div_1" defined anywhere in the html?

Wednesday, March 31, 2010

Javascript in Rails Partial

Javascript function defined in a partial sometimes doesn't work (I've seen both worked case and non-worked case). I have a partial named _v_1_0_edit.html.erb; its parent page is index.html.erb. The javascript portion is below:

function my_alert() {

If the above is inside a partial, it doesn't work when I call my_alert() from a onclick event of a button on the partial; it is as if the function is not defined. But if the above is inside the parent, it works.

However, if I change the function definition to below:

my_alert = function my_alert() {

It works if it's defined in a partial (But it doesn't work in IE).

If I just throw the below on a view:


It will show the alert message no matter it's on the partial or the parent.

I need to do more research on this. I think as long as the defined function is shown on page source, it should work. Can I have a script
section inside a div?

Wednesday, October 7, 2009

VS2008 Remote Debugging

First you need to create a user on your desktop and the remote machine with the same username and password on both machines.
Make sure msvsmon.exe is installed on the remote computer. It should be in your Visual studio 2008 directory.
on the remote computer do a runas /user:debuguser c:\fullpath\msvsmon.exe
where debuguser is the user you created above
You should see a window popup saying "3/31/2009 12:22:56 PM Msvsmon started a new server named 'debuguser@TSIK2552100'. Waiting for new connections."
now on your desktop do a runas /user:debuguser "c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"
where debuguser is again the user you created above
the load your project and go to attach to process, enter debuguser@remotemachinename in the Qualifier box and you may need to select the show processes from all users check box. select your process and you should be able to debug.

Monday, September 28, 2009

Enable Sql Server Authentication Mode Over Network

Check the followings:
1. Right click the root node on Object Explorer, in Server Properties window->Security->Server authentication: SQL Server and Windows Authentication mode
2. Create a new user for login.
3. Right click the user on Object Explorer, in Login Properties window:
    3.1 User Mapping: Check the desired database to access
    3.2 Status->Permission to connect to database engine: Grant; Login: Enabled
4. Sql Server Configuration Manager -> Enable TCP/IP and Named Pipes

Thursday, September 17, 2009

Object.GetHashCode, Object.Equals, operator==, and related

After some research, I summarize some points below as guidelines.

1. Object.Equals method and operator== are supposed to be used interchangeably. (It applies to all the .net classes) Therefore, when implementing a new class, it's a good idea to always implement both of them.
Equals() is usually used (implemented) for value equality and Operator== is used for reference equality by default. When a type is an immutable type (e.g. String), overloading Operator== to compare value equality makes sense.

Guidelines for Overloading Equals() and Operator==

Override equals on overloading operator equals

When should I use == and when should I use Equals

2. It is important to override GetHashCode when overriding Equals method. Although failure to do so will not always break your code, things can go wrong if the class is used as a key in a dictionary etc. In that situation, if the hash-code for two items does not match, they may never be considered equal (Equals will never be called). To write the GetHashCode, we need to make sure that: if two objects are equal, then they must return the same value for GetHashCode. On the other hand, we do NOT have to make sure two different objects always return different values for GetHashCode.

Why is it important to override GetHashCode when Equals method is overriden in C#

3. A good implementation of GetHashCode that can be used in many situations:
public int GetHashCode()
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + field1.GetHashCode();
hash = hash * 23 + field2.GetHashCode();
hash = hash * 23 + field3.GetHashCode();
return hash;
What is the best algorithm for an overridden System.Object.GetHashCode

4. Implementing IEquatable Properly

Tuesday, August 25, 2009

Sql Server Script to Restore a Database

use master

alter database DBName
set single_user with rollback immediate

restore database DBName
from disk = 'C:\DBBackup.bak'

-- use the following to overwrite log in case the log file was not backed up
with replace

Tuesday, August 18, 2009

SQL Commands - Disable Constraints

The following commands are from this URL

--Disable Constraints & Triggers
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'

--Perform delete operation on all table for cleanup
exec sp_MSforeachtable 'DELETE ?'

--Enable Constraints & Triggers again
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'

--Reset Identity on tables with identity column
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'

I found the commands are very useful. For example, I once got the foreign key constraint error when trying to import data into my database. I executed the first two commands to disable constraints and triggers first, then imported the data, the errors were gone. After importing data, I then executed the last three commands to re-enable and reset stuff.