MySQL
CREATE TABLE hello (
idHello int NOT NULL AUTO_INCREMENT
) AUTO_INCREMENT=5;
PostgreSQL
CREATE SEQUENCE hello_idHello_sequence START 5;
CREATE TABLE hello (
idHello integer NOT NULL DEFAULT nextval('hello_idHello_sequence')
);
ALTER SEQUENCE hello_idHello_sequence OWNED BY hello.idHello;
Thursday, August 29, 2013
Schema conversion - AUTO_INCREMENT (MySQL) and SEQUENCE (PostgreSQL)
Auto increment is achieved in MySQL using the keyword AUTO_INCREMENT. It is achieved in PostgreSQL using a SEQUENCE statement. Consider the following problem: Create a table with a field, to auto increment starting with the value 5.
Friday, August 16, 2013
Threat Modeling - STRIDE
While performing threat modeling on software, verify that every data item, end point crossing a boundary, open port etc are subject to the categorization defined by STRIDE. Each item under consideration may fall under more than one category.
STRIDE Definition
STRIDE Definition
Spoofing User: Accessing and using a resource by masquerading as another user
Tampering Data: Modifying data maliciously, so that the original data is unavailable and/or malicious data is introduced
Repudiation: Denying by a user or system, that an action has been performed by them
Information Disclosure: Disclosure of information to an unauthorized user or system
Denial of Service: Denying the Service to legitimate users or system
Elevation of Privilege: Unauthorized elevation of privileges by an unprivileged user
For more information, refer to Security Design by Threat Modeling
Sunday, August 11, 2013
Tomcat - Application System Error - Access is Denied
Application: Tomcat
OS: Windows
Error: Unable to open the service 'Tomcat7'
When you install Tomcat on a Windows machine, the following error is seen on rebooting the machine.
OS: Windows
Error: Unable to open the service 'Tomcat7'
When you install Tomcat on a Windows machine, the following error is seen on rebooting the machine.
Reason: Tomcat7w.exe accesses resources that require administrator privileges.
Solutions: Configure Tomcat7w.exe to run as administrator. To configure Tomcat7w.exe run as administrator
- Right-click on Tomcat7w.exe
- Click on Properties
- Click on Compatibility
- Under Privilege Level, check the box 'Run this program as an administrator'
- Click OK
- Reboot the machine
Saturday, August 10, 2013
Programs for Windows Administration
This is a list of programs, that you can use for Windows administration.
- Computer Management: compmgmt.msc
- Component Services: comexp.msc
- Event Viewer: eventvwr.exe
- Local Security Policy: secpol.msc
- ODBC Data Sources: odbcad32.exe
- Performance Monitor: perfmon.msc
- Print Management: printmanagement.msc
- Services: services.msc
- System Configuration: msconfig.exe
- Task Scheduler:taskschd.msc
- Windows Firewall with Advanced Security: WF.msc
Linux Commands
Here are some common Unix/Linux commands
- OS bitness 32 or 64: getconf KERNEL_BITS
- architecture of processor: file /usr/bin/w
- disk space usage: du
- enable backspace: stty erase hit_the_backspace_key
- split a vim screen vertically: Ctrl+wv
- list of open ports: netstat
- list of processes: ps
- rename a file: mv original_filename renamed_filename
- move a file: mv filepath/filename target_filepath/filename
- change permissions: chmod
- change owner: chown
Windows Batch Files - Common Tips
Lessons learnt while writing Windows Batch Scripts
- @echo off -> used as the first line in a batch script, to suppress the output of current command to console
- REM this is how a comment is made
- echo "this is how to print something to console"
Common Tools for Regular Use
I use a variety of tools during development. Here is a list of some of them. This list keeps growing as I use additional software.
- Beyond Compare: for file, folder comparison and file merge
- gVim: for file editing, comparison and merge
- WinMerge: file comparison and merge
- Application Verifier: runtime verification of c, c++ code on Windows
- Driver Verifier: Windows kernel mode driver runtime verifier
- WinDbg: debugging C and C++ code on Windows
- WireShark: network packet analysis and sniffing
- Maven: build, package
- Gradle: build, package, deploy
- Selenium: web site testing
- JUnit: framework for unit testing of Java code
- Fortify SCA: source code analysis
- Clover: code coverage for Java and Groovy code
- SonarQube: for trend analysis of various aspects in a project
- BlackDuck: open source software management
- VMWare Player: free virtual machine software
- psftp: sftp client
- putty: telnet client
- pscp: scp client
- tomcat: web server
- process explorer: Windows processes, open files, handles etc
- dependency finder: for finding dependencies in java code
- lattix: for finding dependencies in java/c/c++/.net/database code
Disclaimer: This is just a list of software that I used. I do not make any recommendations regarding the software that I listed here.
Java - Overriding hashCode() and equals()
Java provides a convenient way to calculate 'deep comparison' of objects via hashCode() and equals() methods. Every object has the default implementation for these methods. Deep comparison of objects can be implemented by overriding hashCode() and equals() methods. Several rules are defined by Java creators which we go through in the following sections. You can access these rules from Javadocs of Object.
Rules for equals():
Rules to override hashCode()
- Invocations of hashCode() should return the same value when fields of object do not change
- If two objects are equal based on equals() method, both the objects should return the same hashCode()
- It is not required that the hashCode() be dissimilar when two objects are not equal based on equals()
Rules to override equals()
- Reflexive: An object should be equal to itself: a.equals(a) is true
- Symmetric: If an object is equal to another object based on equals(), then these objects should be equal irrespective of which object's equal method is called: => if a.equals(b) is true then b.equals(a) is also true
- Transitive: if two objects are equal based on equals(), then these objects are equal to any other objects that are equal to any of these objects: if a.equals(b) is true and b.equals(c) is true, then a.equals(c) is true
- Consistent: multiple invocations of equals() on objects should return the same value, if the underlying values used to check equality are not modified
- Equality check with null is false
Example: Consider the following class that contains an int and the way hashCode() and equals() are overridden.
class A
{
int x;
public int setX(int x);
{
this.x = x;
}
public int getX()
{
return this.x;
}
public int hashCode()
{
return x;
}
public int equals(Object object)
{
boolean isEqual = true;
if(object == null)
{
isEqual = false;
}
else if(Class.forName(object) != this.class))
{
isEqual = false;
}
else
{
A compareObject = (A) object;
if(this.x != compareObject.x)
{
isEqual = false;
}
}
return isEqual;
}
}
Verify that the rules for hashCode() and equals() are satisfied:
Example:
A a,b,c,d;
a.setX(5);
b.setX(5);
c.setX(5);
d.setX(6);
Rules for hashCode():
- a.hashCode() will always return 5
- a.equals(b) is true. also, a.hashCode() and b.hashCode() return 5
- a.equals(d) is false (5 != 6). though a.hashCode() can be same as d.hashCode(), in our implementation they are different
Rules for equals():
- a.equals(a) will always return true
- a.equals(b) is true and b.equals(a) is true
- a.equals(b) is true and b.equals(c) is true and c.equals(a) is also true
- a.equals(b) is true as long as the 'x' value of the objects is not changed
- a.equals(null) is false
Subscribe to:
Posts (Atom)