Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Saturday, August 24, 2013

Solving SciTE indentation problem for Python

I had this annoying problem while coding python using SciTE.
SciTE uses TAB indentation instead of the regular 4 spaces. Moreover, it doesn't stick with the existing indentation of the current file.

To solve this problem:
  1. Go to Options -> Open Global Options File.
  2. Scroll down to #Indentation
  3. Modify the following variables
 indent.size=8
use.tabs=1
#indent.auto=1

to

indent.size=4
use.tabs=0
indent.auto=1

PS: Unfortunately, it does affect all other languages as well. Also, doing the same modifications only in python.properties file doesn't restrict the changes to python files.

Friday, September 28, 2012

How to remove duplicate rows in MySQL

Sometimes your table contains duplicate keys due to the fact that you forgot to add a primary key to the initial design. Something like that
CREATE TABLE employee (
ssn INT NOT NULL,
name VARCHAR(20) NOT NULL 
);
Yeah, Bad database design!!

Here are different ways to fix it
1- You realize that a primary(unique) key is missing, so you add it
ALTER IGNORE TABLE employee ADD PRIMARY KEY (ssn);  
or
ALTER IGNORE TABLE employee ADD UNIQUE KEY (ssn); 
notice the IGNORE keyword.
You could later reverse that constraint by
ALTER TABLE employee DROP index ssn;  
or 
ALTER TABLE employee DROP index ssn; 
2- Delete all but one using LIMIT keyword

DELETE FROM employee WHERE ssn=x LIMIT n; 
where x is the value of the duplicated attribute and n is the number of required deleted rows, i.e. less than the total duplicated rows by 1.
example:
if you have a duplicated ssn = 123456789 repeated 10 times and you want to delete 9 of them

DELETE FROM employee WHERE ssn=123456789 LIMIT 9; 
You can do a COUNT on that ssn before you apply the previous command.

3- Using a temporary table
CREATE TEMPORARY TABLE employee_temp AS SELECT DISTINCT * FROM employee;
DELETE * FROM employee;
INSERT INTO employee SELECT * FROM employee_temp; 

 

Wednesday, August 15, 2012

Struts 2 - The requested resource () is not available

You are here probably because you have just created your first Struts 2 application and after deploying it on a server, you got the following message:

“HTTP Status 404 -
type Status report
message
descriptionThe requested resource () is not available.

This problem is a result of having more or less than the required jar files added to the build path.
Here is the solution, make sure to include exactly these jar files in the build path.
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.4.jar
xwork-core-2.3.4.jar

It should work.

Note: The numbers at the end of the file names may be different for the Struts release you work with.