Style Sheet Query String Parameter
Posted By: Philip on: Tuesday, 21 May 2013 at 22:47

I haven't created any website content recently because I have been too busy working on other projects, so I thought I would quickly make a post about CSS browser caching.

When surfing the internet and casually viewing the source of your favourite sites [as you do :) ] you may notice some CSS links with query strings.

<link rel="stylesheet" href="sources/css/basic.css?pr=452343223" type="text/css" media="all" />

This may seem pretty pointless as the webserver will ignore any parameters and continue to read the CSS file's contents as normal.

So what is the purpose of the query string on a CSS link?

It's actually a pretty simple hack. If you change the query string every time the style sheet is changed it will force the client's browser to reload the CSS file from the server - removing the possibility of the client using an out of date cached version. This then ensures that the webpage is rendered with the most up to date CSS after each release.

Tags: CSS, Browser, Trick, HTML






Java AJAX Example
Posted By: Philip on: Wednesday, 24 April 2013 at 22:52

On Saturday I created this tutorial video on How to use jQuery/Javascript to make AJAX calls from a JSP to a Java Servlet.

The tutorial also provides some examples of CSS, HTML & googles Gson Jar files that convert Java Objects into their JSON representation. Making it easy for Javascript to parse the response data.

Obviously I would not recommend using this word for word in production as I did not include XSS security such as striping tags and escaping output. Here is a great XSS cheat sheet from OWASP.

Tags: Java, JavaScript, AJAX, CSS, HTML, JSON






Java Map to JSON converter
Posted By: Philip on: Wednesday, 24 April 2013 at 23:45

Tonight I decided to program a simple Java Map -> JSON converter. Could be extended in the future to include nested Objects & Arrays. Here's the class anyway. Again - maybe someone will find this code useful!
import java.util.Map;
import java.util.TreeMap;

/**
 * 

Simple first level JavaScript Object Notation Map converter

*

http://www.philipstarritt.com

* @version 1.0 * @author Philip Starritt * @since 2013/04/15 22:25 */ public class JavaSon { /** *

Will convert a Java Map into JSON format that can be easily used in AJAX calls.

*

String, Integer & Boolean will be printed in JSON expected format.

*

Other objects (Arrays/Lists/Objects etc) will .toString() so it's best to override.

*

This method can be further extended to include nested arrays & Objects in the * JavaScript Object Notation.

* @param map * @return String in JSON */ public static String toJson(Map map){ return (map != null && !map.isEmpty()) ? parse(map) : null; } private static String parse(Map map) { int counter = 0; StringBuilder stringBuilder = new StringBuilder("{\n"); for (Map.Entry mapEntry : map.entrySet()) { stringBuilder.append("\t\"" + mapEntry.getKey() + "\":"); String className = mapEntry.getValue().getClass().getSimpleName(); if(className.equals(Boolean.class.getSimpleName()) || className.equals(Integer.class.getSimpleName())){ stringBuilder.append("" + mapEntry.getValue() + ""); } else{ stringBuilder.append("\"" + mapEntry.getValue() + "\""); } if((map.size() - counter) != 1){ stringBuilder.append(",\n"); } counter++; } return stringBuilder.append("\n}").toString(); } /** *

Main

*/ public static void main(String...args){ Map map = new TreeMap(); map.put("1 - first", 2); map.put("2 - second", "dfdf"); map.put("3 - third", true); map.put("last", new Integer(4)); System.out.println(JavaSon.toJson(map)); /* * OUTPUT * * { * "1 - first":2, * "2 - second":"dfdf", * "3 - third":true, * "last":4 * } * */ } }

On Thursday I will add a another code example on how to use jQuery/Javascript AJAX calls on a Java servlet and access the JSON formatted response data.

cya!

Tags: Java, JavaScript, JSON






Java Recursion - Mathematical Examples
Posted By: Philip on: Saturday, 13 April 2013 at 11:55

I have recreated and uploaded my webpage/document on Java maths recursion.

I hope this comes in handy for someone.

Here is an example division recursive method.
public static int divide(int a, int b){  
    	if(b == 0){
            return 0;
    	}
    	else if(a < b){
            return 0;
    	}
        else if(b == 1){
            return a;
        }
    	else{
            return add(1, divide(sub(a,b),b));
    	}
}

Tags: Java, Recursion, Maths






JMapper - Small Project
Posted By: Philip on: Tuesday, 19 March 2013 at 00:55

Tonight I continued programming my JMapper data inserter. (Inserting JMapperBeans to a database).

I will go back and optimise this program sometime in the next week or so and provide a video demo and upload the source.

Anyway.... Here is a brief demo on how to use JMapper.

First we need to create a bean that implements my JMapperBean interface. The bean should match the database column names/data types & have a method that returns the table name. (You can have any number of data columns)



After that we can then use the JMapper Class to set (Bean), build & execute the transaction. I will provide the JMapper Class Source / reference later.

Please note I have not optimised this code... (all them exceptions could be better handled in JMapper...)

Then some metrics... (Yes I know 0.283.. could be faster)

As you can see this removes the need to write / execute any inline SQL in your java. Data inserted...

My JMapper Class was mainly built from reflection, giving it the ability to examine its own structure & types on the fly. (Package java.lang.reflect) Example:



Overall - This small project has been very fun and I plan to add/optimise its features in the future.

Tags: JMapper, Programming, Reflection, Java






Photo Albums
Posted By: Philip on: Friday, 15 March 2013 at 19:58

I have spent the last little bit programming my new photo albums webpage. I have the structure all complete, now I just need to write the final logic to display the images in each album & reupload the webpage. Should be done by 2013-03-14.

Dunluce Castle - Sea View

Tags: Dunluce Castle, Domain, I am a nerd


Nice landscape.

Posted By: Dovydas on Monday, 18 March 2013 at 22:02





New Blog Developed
Posted By: Philip on: Sunday, 10 March 2013 at 03:24

I decided to completely rewrite my website and give it a nice design & improved features.

Today I finished developing my new Blogging CMS. I decided to use lots of JS/AJAX/jQuery as that's the way the web seems to be going. (With server validation of course for you XSS nerds!)

Try out the comment form.

Tags: Blog, AJAX


Yoo

Posted By: Anon k on Monday, 04 March 2013 at 02:30

Nerd

Posted By: Pete on Wednesday, 06 March 2013 at 23:10

...

Posted By: Orange Tango on Wednesday, 06 March 2013 at 23:10

Hello

Posted By: Gord on Saturday, 09 March 2013 at 13:27

Cool

Posted By: Philip on Friday, 26 April 2013 at 18:03

Dfgdf

Posted By: Hghf on Friday, 26 April 2013 at 18:03





CodePlow.com - Still hanging in there
Posted By: Philip on: Monday, 04 March 2013 at 01:56

I still own the domain codeplow.com. It never took off so I may try and sell it on.

Tags: CodePlow.com, Domain






Site Development
Posted By: Philip on: Tuesday, 05 March 2013 at 19:36

Over the next week I will be uploading my old webpages content in the new sites design.

Content includes my projects with descriptions, documents, open source code, pictures, videos etc

Tags: Old webpages


P.A

Posted By: Pa on Sunday, 10 March 2013 at 21:28

Cool

Posted By: Melissa on Saturday, 16 March 2013 at 17:33





IronFist Youtube Video
Posted By: Philip on: Monday, 04 March 2013 at 02:06

Screen recording with narration of my University project 'IronFist'. Watch in 720p for high quality.

Tags: C#, XNA 4.0, Ironfist, QUB Computer Science level 2, Games Programming






Google Indexing
Posted By: Philip on: Monday, 04 March 2013 at 01:34

Google has maintained its index of my old webpages. I'm pretty surprised as its been over 4 weeks since I removed them and had them redirected to a 404.

Tags: Google Indexing, 404






Hit counter
Posted By: Philip on: Monday, 04 March 2013 at 02:28

My last website had 30,000 views in just over 8 months. Hopefully this one starts to pick up the traffic like the old one had.

Tags: Hit Counter






My First Blog Post.
Posted By: Philip on: Monday, 04 March 2013 at 00:00

New Server / CMS =)

Tags: CMS, First Post, V1.0


Hello

Posted By: Heather on Monday, 04 March 2013 at 00:18

Cool

Posted By: Log on Sunday, 10 March 2013 at 01:32

GT

Posted By: Gt on Sunday, 10 March 2013 at 01:43

About time......

Posted By: Blank on Wednesday, 13 March 2013 at 01:40