Extensive use of post request are evil

So one guy say: “I want a website and the domain and url should never change.”
The webdeveloper say: “Sure ? Okey – no problem”.

Now what the webdeveloper has some options. First option is to make the site normal and put the in to an iframe, second option is to make a ajax app (for example with Google Webtoolkit) and the third option and maybe the worst idea ever is to make for every link javascript event that execute a hidden form to the main site.

So why this is this evil.


  1. The backbutton doesn’t work and refreshing the sites sucks.

  2. Development sucked because of cached data in every browser

  3. You break the HTTP Protokoll: Get for getting Data, Post for send data, Put for …

  4. Users can’t share links.

  5. Google’s pagerank might not work

Maybe you think different about this. My opinion is Extensive use of post request are evil

Posted on 19 May 2010.

Optimize your html/css development

When you develope a website, you are the most of the time with refreshing the browser. But instante of every time refresh your browser, you can simply add an http redirect while you design your webpage.

For example your website you are designing is called “index.html”. You simply add this


<meta http-equiv=“Refresh” content=“2; URL=index.html” \>

in your header section. And voila – no more refresh the browser. The browser is refreshing automaticly.

Posted on 17 April 2010.

Use Java to insert large amount of data

Sometimes you need a fast way to insert large amount of data in a mysql database. One way to do that is to use a PreparedStatement and addBatch. But there can be a pittfall if you don’t controll your database commits. Here’s a example :

Class.forName("com.mysql.jdbc.Driver");
  
Connection con = DriverManager.getConnection("jdbc:mysql://" +  host + ":" + port + "/" + db, user, password);
String insertSQL = "INSERT INTO users (login, email, passwort_reset) VALUES (?,?,?)";
	
PreparedStatement insertStatement = con. prepareStatement(insertSQL);

for (User user : users)
{
  insertStatement.setString(1, user.name);
  insertStatement.setString(2, user.mail);
  insertStatement.setBoolean(3, true);
  insertStatement.addBatch();
}

con.setAutoCommit(false);
insertStatement.executeBatch();
con.commit();
con.setAutoCommit(true);

The reason why I disable in line 16 the autocommit is that I call in Line 17 executeBatch and hope that all my Data will insertet in the table. But mysql commits every inserts. And in that case the imports would be extremly slow. I have made some benchmark test by myself and saw an performance by 20000 inserts normally it would take 10 – 12 secs. and with disabled autocommit 3-5 secs. That’s huge performance improvement. After you inserts don’t forget to commit (line 18) so that you can unlock the users table.

Posted on 10 April 2010.

Create multiple objects in Java.

Let’s create some objects. We have three classes.

	public class Human 
	{
		private String name;
		
		public Human(){
			name="";
		}
		
		public Human(String name)
		{
			
		}
		
		public String getName()
		{
			return this.name;
		}
		
		public void setName(String name)
		{
			this.name=name;
		}
	}
	public class Man extends Human
	{
		
	}
	public class Woman extends Human
	{
		
	}
	List<Woman> women = new ArrayList<Woman>();
	List<Man> men = new ArrayList<Man>();
	
	
	for(int i = 0; i < 100; i++)
	{
		womans.add(new Woman());
		men.add(new Man());
	}

Now if you do much thing like this you write much for-loops. I found a solution for this kind of problem without writing a new for loop. Lets add a Method in the Human class.

	public static List<Human> getInstances(Class<? extends Human> clazz, int counter)
	{
		List humans = new ArrayList<Human>();
		
		for(int i=0;i< counter; i++)
		{
			
			humans.add(clazz.newInstance());
		
		}
		
		return humans;
	}

Now you can use this for creating humans.

	List<Men> men = Human.getInstances(Men.class,10);
	List<Women> men = Human.getInstances(Women.class,10)

If you have a specific constructor you can use this

	public static List<Human> getInstances(Class<? extends Human> clazz,String name, int counter)
	{
		List humans = new ArrayList<Human>();
		
		for(int i=0;i< counter; i++)
		{
			
			humans.add(clazz.getDeclaredConstructor(String.class)
				.newInstance(name));
		
		}
		return humans;
	}
Posted on 27 January 2010.

Reset Blog

After long time, i decided to reset my website. Why ? Because Wordpress is for this site to much. I want a simple site management tool. And finaly I found one Jekyll. I put the code for this site on Github. If you like you can check it out and fork it :-)

Posted on 25 January 2010.