Archive for July, 2009

Apache: Applying license to code

Friday, July 31st, 2009
Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

See Apache V2 licensing

Hibernate: Config properties, c3p0 and disable the cache level

Thursday, July 30th, 2009
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost/dbname?useUnicode=true&ampcharacterEncoding=UTF8
hibernate.connection.username=username
hibernate.connection.password=pwd

#only if you use the current session
hibernate.current_session_context_class=thread
hibernate.connection.release_mode=on_close

#disable the second level cache
hibernate.cache.use_second_level_cache=false
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect

#do not forget the provider_class to set C3P0. No more auto detect in Hibernate 3.0.0+
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800

MySQL: Load SQL file to MySQL

Saturday, July 25th, 2009
mysql -u database_name -p < /path/to/file.sql

MySql: Drop table, rename table, drop foreign key, drop column

Friday, July 24th, 2009
#switch to the right DB
USE database_name;

#drop a table
DROP TABLE table_name;

#rename a table
RENAME TABLE table_name TO new_table_name;

#drop a foreign key
ALTER TABLE table_name DROP FOREIGN KEY FK_name;

#drop a column
ALTER TABLE table_name DROP COLUMN column_name;

#change a column to varchar(128)
ALTER TABLE table_name CHANGE column_oldName column_newName  varchar(128)

See MySQL Alter Table doc.

# Check the foreign key of a particular database
SELECT * FROM information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA='myDatabaseName';

Source

jQuery: iFrame find elements

Monday, July 20th, 2009
$(‘#iframeID’).contents().find(‘#someID’).html();

Source: http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/

Hibernate: Single table inheritance annotations

Sunday, July 19th, 2009
@Entity
@Table(name = "employee")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "ctype", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("e")
@ForceDiscriminator //optional
public class Employee{
...
}

And the subclass would be like

@Entity
@DiscriminatorValue("m")
public class Manager extends Employee{
....
}

Hibernate: Store Enum as String

Sunday, July 19th, 2009

Just add the @Enumerated(EnumType.STRING)

@Enumerated(EnumType.STRING)
public Type getType() {
    return type;
}

jQuery: Ajax get with callback

Tuesday, July 14th, 2009
$.get("test.cgi", { name: "John", time: "2pm" },
     function(data){
      alert("Data Loaded: " + data);
});

jQuery AJAX Get Doc

Eclipse: Top Shortcuts

Monday, July 13th, 2009
  • File Quick Seeker: Ctrl + Shift + R
  • Type (Class, Interface) Quick Open: Ctrl + Shift + T
  • Methods quick seeker: Ctrl + O (Additional Ctrl + O shows inherited methods)
  • Quick method jump: Ctrl + Shift + (uparrow) or (downarrow)
  • Go to line: Ctrl + L
  • Go to last edit: Ctrl + Q
  • Go to supertype/subtype: Ctrl + T
  • Go to editor: Ctrl + E
  • Go to declaration: F3 (Same as Ctrl Click)

See also:

JQuery: Keypress enter key

Saturday, July 11th, 2009
$("input").keypress(function (e) {
  if (e.which == 13){
     alert("You have pressed Enter");
  }
}

See also: