tag:blogger.com,1999:blog-879262544140079612024-03-13T01:45:50.078+02:00Coder EyeSoftware development and photography related issuesGuy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.comBlogger121125tag:blogger.com,1999:blog-87926254414007961.post-91779522136257288892022-06-19T22:49:00.004+03:002022-06-19T22:49:56.784+03:00<h2 style="text-align: center;">Tel Aviv Pride Parade š³ļøāš 2022, Israel</h2><p style="text-align: left;"><span style="font-size: large;">Tel Aviv Pride has become one of the biggest events of the year in Tel Aviv. Visitors from all over Israel and the world come out in full force to celebrate. The city lights up in color and energy, proving its reputation as the Gay Capital of the Middle East, and perhaps even one of the Gay Capitals of the World. Tel Aviv Gay Pride Week takes place every June, with a surge of gay-friendly events taking place across the city, culminating on the Friday with the famed pride parade.</span></p><p style="text-align: left;"><span style="font-size: large;"><br /></span></p><div><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" class="BLOG_video_class" height="549" src="https://www.youtube.com/embed/aXJz60xbvj4" width="661" youtube-src-id="aXJz60xbvj4"></iframe></div><br /><span style="font-size: large;"><br /></span></div>Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-70119140637730594532022-06-17T00:41:00.002+03:002022-06-17T00:41:13.961+03:00<h2 style="text-align: left;">Kikar Dizengoff, Israel</h2><p style="text-align: left;"><span style="font-size: large;">The square, named after Tzina, the wife of Meir Dizengoff, has been one of the hotspots in Tel Aviv since 1934. In the 1970s, the square was redesigned in a two-level format, with a pedestrian bridge and a colorful fountain designed by renowned Israeli artist Yaakov Agam. Standing in the center. On Tuesdays and Fridays, there is a bustling flea market in Dizengoff Square.</span></p><p style="text-align: left;"><span style="font-size: large;"><br /></span></p><p style="text-align: left;"><span style="font-size: large;">A YouTube video showing a Virtual Tour on Kikar Dizengoff:</span></p><p style="text-align: left;"></p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" class="BLOG_video_class" height="520" src="https://www.youtube.com/embed/CVIaHzUi_tc" width="625" youtube-src-id="CVIaHzUi_tc"></iframe></div><br /><span style="font-size: large;"><br /></span><p></p>Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-23582514141425791312018-03-25T23:19:00.003+03:002018-03-25T23:19:55.559+03:00Install Tomcat 8 on RasberryPiI wanted to play a little with my old RaspberryPi (2 Model B) and install Tomcat 8 on it. I went over several tedious blogs showing a pretty long process from checking Java version through creating tomcat user and downloading Tomcat from all sort of strange web sites.<br />
If you are not picky on a specific Tomcat 8 version, then it is actually quite a simple task:<br />
<br />
First make sure using the command line that your RaspberryPi is running at least Java 8:<br />
<br />
java -version<br />
<br />
<br />
The install Tomcat 8 using apt:<br />
<br />
sudo apt-get install tomcat8<br />
<br />
<br />
It will make sure to create tomcat8 user for you.<br />
<br />
In order to make sure if Tomcat 8 is running properly, simply open your browser (probably Chromium) and type:<br />
<br />
localhost:8080Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-71468767841372107872014-12-27T20:47:00.001+02:002014-12-27T23:12:15.111+02:00Nikon 1 VR 70-300 f/4.5-5.6 Sample PhotosThe Nikon 1 VR 70-300 f/4.5-5.6 is quite an expensive lens, but considering it gives you equivalent focal length of 189-810mm that you can very easily hold with one hand, it makes it quite an attractive lens.<br />
<br />
I think Nikon made great job with this lens. It is relatively quite small and light, it has very good optical quality and a fast focus even on my old Nikon V1 camera.<br />
<br />
If you consider buying this lens I brought you some field sample images so you can evaluate it. All photos are completely untouched and uploaded directly from the camera.<br />
<br />
LEAF | <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4eDZJNzNkWmZRVlU" target="_blank">download full image</a><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBr79mXFyVRk7z0GtT4dAw1_54HInsCIlDY9Ndah_ie86C5_k74EcKzqFxbqWWWKG37X7u5tTmWFKVW537u0ve0p3ZCKGwrz4lSyLXE-RvlQ1ZKCj6Wf5roOtPmc7O3WhT3Hh6suWOcrzM/s1600/nikon_1_vr_70_300_leaf.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBr79mXFyVRk7z0GtT4dAw1_54HInsCIlDY9Ndah_ie86C5_k74EcKzqFxbqWWWKG37X7u5tTmWFKVW537u0ve0p3ZCKGwrz4lSyLXE-RvlQ1ZKCj6Wf5roOtPmc7O3WhT3Hh6suWOcrzM/s1600/nikon_1_vr_70_300_leaf.JPG" height="428" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Nikon 1 VR 70-300<br />
Aprture: f/5.6<br />
Focal Length: 300mm (810mm equivavlent)<br />
ISO: 200<br />
Exposure: 1/200 sec</td></tr>
</tbody></table>
<br />
SAVION | <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4Nld6Tm5zb2cwZVk" target="_blank">download full image</a><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4Nld6Tm5zb2cwZVk" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4Nld6Tm5zb2cwZVk" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="font-size: 12.8000001907349px;">
Nikon 1 VR 70-300</div>
<div style="font-size: 12.8000001907349px;">
Aprture: f/5.6</div>
<div style="font-size: 12.8000001907349px;">
Focal Length: 270mm (728mm equivavlent)</div>
<div style="font-size: 12.8000001907349px;">
ISO: 100</div>
<div style="font-size: 12.8000001907349px;">
Exposure: 1/800 sec</div>
</td></tr>
</tbody></table>
SNAIL | <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4dDlVbTJFeTJobFk" target="_blank">download full image</a><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4dDlVbTJFeTJobFk" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4dDlVbTJFeTJobFk" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="font-size: 12.8000001907349px;">
Nikon 1 VR 70-300</div>
<div style="font-size: 12.8000001907349px;">
Aprture: f/5.6</div>
<div style="font-size: 12.8000001907349px;">
Focal Length: 300mm (810mm equivavlent)</div>
<div style="font-size: 12.8000001907349px;">
ISO: 400</div>
<div style="font-size: 12.8000001907349px;">
Exposure: 1/400 sec</div>
</td></tr>
</tbody></table>
MIKA | <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4UGlHR0l1d2E4aGs" target="_blank">download full image</a><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4UGlHR0l1d2E4aGs" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="428" src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4UGlHR0l1d2E4aGs" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div style="font-size: 12.8000001907349px;">
Nikon 1 VR 70-300</div>
<div style="font-size: 12.8000001907349px;">
Aprture: f/5.6</div>
<div style="font-size: 12.8000001907349px;">
Focal Length: 114mm (307mm equivavlent)</div>
<div style="font-size: 12.8000001907349px;">
ISO: 560</div>
<div style="font-size: 12.8000001907349px;">
Exposure: 1/400 sec</div>
</td></tr>
</tbody></table>
<br />Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-86845902363191571662014-12-16T22:00:00.000+02:002014-12-27T19:15:47.249+02:00List of mobile user-agentsSometimes it is useful to have a list of different kinds of mobile <a href="http://en.wikipedia.org/wiki/User_agent" target="_blank">user agents</a>. It can be used in many ways for development purposes in wide areas.<br />
<div>
<br />
<div>
For this reason I created quite a big list of <a href="http://en.wikipedia.org/wiki/User_agent" target="_blank">user-agents</a>. Each line in the list is a JSON object containing data of:</div>
<div>
<ul>
<li>User agent</li>
<li>Device Brand</li>
<li>Device Model</li>
</ul>
<div>
Here are some examples from the file:</div>
<div>
<br /></div>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>{"device":"SC-04E","brand":"DoCoMo","user_agent":"Mozilla\/5.0 (Linux; Android 4.4.2; en-us; SC-04E Build\/KOT49H) AppleWebKit\/537.36 (KHTML, like Gecko) Version\/1.5 Chrome\/28.0.1500.94 Mobile Safari\/537.36"}
</code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>{"device":"U3","brand":"Housin","user_agent":"Mozilla\/5.0 (Linux; U; Android 4.0.2; en-in; HONPhone V7 Build\/ITL41D) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30"}
</code></pre>
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>{"device":"XT926","brand":"Motorola","user_agent":"Mozilla\/5.0 (Linux; U; Android 4.0.1; th-th; DROID RAZR HD Build\/IMM76D) AppleWebKit\/534.30 (KHTML, like Gecko) Version\/4.0 Mobile Safari\/534.30"}
</code></pre>
<div>
The list is compressed as RAR. It contains almost 1.5M different user agents.</div>
<div>
I hope you will find this list useful.</div>
</div>
</div>
<div>
<b>Download:</b> <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4dGFnQ1VHOFEwN1E" target="_blank">You can download mobile user-agents list here</a>.</div>
Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-69550831558506724522014-12-14T21:20:00.001+02:002014-12-14T21:20:04.318+02:00Nikon V1 Viewfinder/Display problemI own a <a href="http://www.dpreview.com/reviews/nikonv1j1" target="_blank">Nikon V1</a> camera. It is considered to be quite old and outdated these days, but still I find it useful from time to time.<br />
<br />
Few days ago I had this strange problem: when I turned on the camera, things were shown properly on the display, but when I put my eye on the viewfinder and then removed it again the image stayed on the viewfinder and refused to go back to the display.<br />
<br />
Took me quite some time to understand that the sensor on the left side of the viewfinder was simply covered with too much dust. It tricked the sensor to think that my eye is all the time on the viewfinder and therefore showed the image on the viewfinder instead of the display.<br />
<br />
I though it might be useful to share this information in case one of you out there is still using <a href="http://www.dpreview.com/reviews/nikonv1j1" target="_blank">Nikon V1</a> and experience the same problem. Of course that cleaning the sensor solved the problem.<br />
<br />
Here is where the sensor is located:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj79nv_nJcIYsNbI8e216brEaSfl6eKKcW6J1bF31-GVXvsG4ijKrrOVvWJOI8wPy87qUmfnNNEHr0rxXAefePNAgJ6cTc69VEYGSNhMsBheN1fTSDT6qavwLQYuR-FdJ87Mb-vXVJUufwS/s1600/nikon_v1_viewfinder.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj79nv_nJcIYsNbI8e216brEaSfl6eKKcW6J1bF31-GVXvsG4ijKrrOVvWJOI8wPy87qUmfnNNEHr0rxXAefePNAgJ6cTc69VEYGSNhMsBheN1fTSDT6qavwLQYuR-FdJ87Mb-vXVJUufwS/s1600/nikon_v1_viewfinder.jpg" /></a></div>
<br />
<br />
<br />
<br />Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-78374025027258663342014-12-11T18:57:00.001+02:002014-12-11T18:57:35.046+02:00List of cities as SQL insertsThere are times you might need a list of cities as SQL inserts.<br />
For this reason I extracted quite a large list of cities from MaxMind database.<br />
The list is composed of 2 columns:<br />
<ul>
<li>Country code as ISO-3166 alpha2<span id="sorttable_sortfwdind"> (2 letters for each country)</span></li>
<li><span id="sorttable_sortfwdind">City name</span><span id="sorttable_sortfwdind"></span> </li>
</ul>
There is also a script that creates the cities table (SQL Server syntax):<br />
<br />
<pre style="background-image: URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhElC6bU2Y33yj7Muu8njz58zmeW0-jQWqbBLcTT9Br-2opbQg8X06WBW8VAz2sKf3ge5g6ssbzTmN-8p367kKEqKQxwGUL5LVc75GYbEGbjBr1OnDD6SamXpKI0MdUgNsDloDZGVA7qBdh/s320/codebg.gif); background: #f0f0f0; border: 1px dashed #CCCCCC; color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;"><code style="color: black; word-wrap: normal;"> CREATE TABLE [dbo].[city](
[country_code] [char](2) NOT NULL,
[city] [varchar](100) NOT NULL,
CONSTRAINT [PK_city] PRIMARY KEY CLUSTERED
(
[country_code] ASC,
[city] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
</code></pre>
<br />
<b>DOWNLOAD:</b> You can <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4MUtfR3YwOWJ2ZHc" target="_blank">download the list of cities HERE</a> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-23158390522680079752014-12-03T19:09:00.002+02:002014-12-11T18:41:18.220+02:00Show Resultset as HTML table
There are times you simply want to show some result set as a table on the screen.<br />
You do not need anything fancy, just show some tabular data on the screen.<br />
<br />
In order to solve this issue I wrote a very small and lightweight Java class named: ResultSetToHtmlTable.
Even through this class is doing a quite simple task it still have some nice qualities:
<br />
<br />
<ul>
<li>It is very fast. It doesn't construct any string. It simply writes the table directly to a writer.</li>
<li>It doesn't use any external libraries. All plain and simple Java.</li>
<li>It is only a single class.</li>
<li>It knows to format the data in each column. It supports the following formats:</li>
<ul>
<li>Integer - Show <b>1000 </b>as <b>1,000</b></li>
<li>Float - Show <b>0.5145235 </b>as <b>0.51</b></li>
<li>Currency - Show <b>5.2 </b>as <b>$5.2</b></li>
<li>Percentage - Show <b>0.5</b> as <b>50%</b></li>
<li>Date - Show <b>12/5/2014</b> as <b>5 Dec 2014</b></li>
<li>Date and time - Show <b>12/5/2014 12:00:00</b> as <b>5 Dec 2014 12:00:00</b></li>
<li>Time - Show only the time part of a date. For example: <b>13:22:15</b></li>
</ul>
<li>It allows to align the data to the left or right and add titles to columns.</li>
<li>If no strict column information is supplied is knows to auto detect:</li>
<ul>
<li>Column types.</li>
<li>Column titles - titles are named as column names returned in query.</li>
<li>Column alignment - Numbers are aligned to the right.</li>
</ul>
</ul>
The code of this class is quite simple and straightforward. Here is how it looks like:
<!-- code formatted by http://manoli.net/csharpformat/ -->
<br />
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"><code>package com.todacell.util.sql;
import java.io.IOException;
import java.io.Writer;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Types;
import java.text.DateFormat;
import java.text.Format;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
/**
* @author Bashan
* Date: 18/11/2014 15:07
*/
public class ResultSetToHtmlTable {
public void writeTable(ResultSet rs, Writer writer, Column[] columns) throws IOException, SQLException {
writer.write("<table>");
// Write titles
writer.write("\t<tr>\n");
for (Column column : columns) {
writer.write("\t\t<th>" + column.title + "</th>");
}
writer.write("\t</tr>\n");
// Write data
int cols = columns.length;
while (rs.next()) {
writer.write("\t<tr>\n");
for (int i = 0; i < cols; i++) {
ColumnType columnType = columns[i].columnType;
String columnAlign = columnAlignToColumnCss.get(columns[i].columnAlign);
writer.write("\t\t<td" + columnAlign + ">" + format(columnType, rs.getObject(i + 1)) + "</td>");
}
writer.write("\t</tr>");
}
writer.write("</table>");
}
private static Map<Integer, ColumnType> sqlTypeToColumnType = new HashMap<Integer, ColumnType>();
private static Map<ColumnType, ColumnAlign> columnTypeTpColumnAlign = new HashMap<ColumnType, ColumnAlign>();
private static Map<ColumnAlign, String> columnAlignToColumnCss = new HashMap<ColumnAlign, String>();
static {
// Map SQL types to column types
// integer
sqlTypeToColumnType.put(Types.INTEGER, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.BIGINT, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.SMALLINT, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.TINYINT, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.NUMERIC, ColumnType.INTEGER);
// float
sqlTypeToColumnType.put(Types.FLOAT, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.DOUBLE, ColumnType.INTEGER);
sqlTypeToColumnType.put(Types.DECIMAL, ColumnType.INTEGER);
// date
sqlTypeToColumnType.put(Types.TIME, ColumnType.DATE);
sqlTypeToColumnType.put(Types.TIMESTAMP, ColumnType.DATE);
// Map column type to column alignment
columnTypeTpColumnAlign.put(ColumnType.INTEGER, ColumnAlign.RIGHT);
columnTypeTpColumnAlign.put(ColumnType.FLOAT, ColumnAlign.RIGHT);
columnTypeTpColumnAlign.put(ColumnType.CURRENCY, ColumnAlign.RIGHT);
columnTypeTpColumnAlign.put(ColumnType.DATE, ColumnAlign.LEFT);
columnTypeTpColumnAlign.put(ColumnType.STRING, ColumnAlign.LEFT);
// Map column alignment to css style
columnAlignToColumnCss.put(ColumnAlign.LEFT, "");
columnAlignToColumnCss.put(ColumnAlign.RIGHT, " style=\"text-align:right\"");
columnAlignToColumnCss.put(ColumnAlign.CENTER, " style=\"text-align:center\"");
}
public void writeTable(ResultSet rs, Writer writer) throws IOException, SQLException {
ResultSetMetaData meta = rs.getMetaData();
int cols = meta.getColumnCount();
Column[] columns = new Column[meta.getColumnCount()];
for (int i = 0; i < cols; i++) {
ColumnType columnType = sqlTypeToColumnType.get(meta.getColumnType(i + 1));
ColumnAlign columnAlign = columnTypeTpColumnAlign.get(columnType);
columns[i] = new Column(
columnType != null ? columnType : ColumnType.STRING,
meta.getColumnName(i + 1),
columnAlign != null ? columnAlign : ColumnAlign.LEFT);
}
writeTable(rs, writer, columns);
}
public enum ColumnType {
STRING, INTEGER, FLOAT, DATE, DATE_TIME, TIME, CURRENCY, PERCENTAGE
}
public enum ColumnAlign {
LEFT, RIGHT, CENTER
}
private static NumberFormat integerFormat = NumberFormat.getInstance();
private static NumberFormat floatFormat = NumberFormat.getInstance();
private static final NumberFormat percentFormat = NumberFormat.getPercentInstance();
private static final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
private static final DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
private static final DateFormat dateTimeFormat = new SimpleDateFormat("dd MMM yyyy hh:mm:ss");
private static final DateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");
static {
floatFormat.setMaximumFractionDigits(2);
integerFormat.setMaximumFractionDigits(0);
}
public String format(ColumnType columnType, Object value) {
String result;
if (value != null) {
if (columnType == ColumnType.STRING) {
result = value.toString();
} else {
Format format;
if (columnType == ColumnType.FLOAT) {
format = floatFormat;
} else if (columnType == ColumnType.CURRENCY) {
format = currencyFormat;
} else if (columnType == ColumnType.PERCENTAGE) {
format = percentFormat;
} else if (columnType == ColumnType.DATE) {
format = dateFormat;
} else if (columnType == ColumnType.DATE_TIME) {
format = dateTimeFormat;
} else if (columnType == ColumnType.TIME) {
format = timeFormat;
}else {
format = integerFormat;
}
result = format.format(value);
}
} else {
result = "N/A";
}
return result;
}
public static class Column {
ColumnType columnType;
String title;
ColumnAlign columnAlign;
public Column(ColumnType columnType, String title, ColumnAlign columnAlign) {
this.columnType = columnType;
this.title = title;
this.columnAlign = columnAlign;
}
}
}
</code></pre>
And here is a simple example of how to use this code in a JSP file:
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhElC6bU2Y33yj7Muu8njz58zmeW0-jQWqbBLcTT9Br-2opbQg8X06WBW8VAz2sKf3ge5g6ssbzTmN-8p367kKEqKQxwGUL5LVc75GYbEGbjBr1OnDD6SamXpKI0MdUgNsDloDZGVA7qBdh/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <%@ page import="com.todacell.management.SessionSingleton" %>
<%@ page import="com.todacell.util.sql.ResultSetToHtmlTable" %>
<%@ page import="org.hibernate.Session" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Daily Deposits</title>
<style type="text/css">
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
td, th {
padding: 5px;
}
</style>
</head>
<body>
<jsp:include page="k2_menu.jsp" />
<h1>Daily Deposits</h1>
<%
Session hSession = SessionSingleton.instance();
Connection conn = hSession.connection();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from k2_deposits(60)");
ResultSetToHtmlTable resultSetToHtmlTable = new com.todacell.util.sql.ResultSetToHtmlTable();
resultSetToHtmlTable.writeTable(rs, out,
new com.todacell.util.sql.ResultSetToHtmlTable.Column[] {
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.DATE, "Date", ResultSetToHtmlTable.ColumnAlign.LEFT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.CURRENCY, "Deposits", ResultSetToHtmlTable.ColumnAlign.RIGHT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.CURRENCY, "Allocated", ResultSetToHtmlTable.ColumnAlign.RIGHT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.CURRENCY, "Deallocated", ResultSetToHtmlTable.ColumnAlign.RIGHT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.CURRENCY, "Ad Spend", ResultSetToHtmlTable.ColumnAlign.RIGHT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.CURRENCY, "Potential Spend", ResultSetToHtmlTable.ColumnAlign.RIGHT),
new ResultSetToHtmlTable.Column(ResultSetToHtmlTable.ColumnType.INTEGER, "New Users", ResultSetToHtmlTable.ColumnAlign.RIGHT)
});
} finally {
if (hSession != null) {
hSession.close();
}
}
%>
</body>
</html>
</code></pre>
And here is how it looks on the browser:
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYj6YpbA_Rqna9iGneuzc4va_7W8b5HnoQvnouOXvLjfS5UECbTTVpNDgg8VdT39o6Ul5xvh8-zZf0msZXfQZfOt-3vtAVKanryaeWhTwrimd8Onnb6azytgyvZvlrZtDe1Iny_1sBpnFA/s1600/jsp_table_screen_shot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYj6YpbA_Rqna9iGneuzc4va_7W8b5HnoQvnouOXvLjfS5UECbTTVpNDgg8VdT39o6Ul5xvh8-zZf0msZXfQZfOt-3vtAVKanryaeWhTwrimd8Onnb6azytgyvZvlrZtDe1Iny_1sBpnFA/s1600/jsp_table_screen_shot.png" /></a></div>
<b>DOWNLOAD:</b> You can <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4UkRYYS1PcDUtNms">download the ResultSetToHtmlTable here</a>Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-79874442187169953842014-11-25T20:51:00.000+02:002014-11-25T21:12:08.779+02:00Instagram Photo Cycler JavaSscript widget<br />
A while ago I built for the <a href="http://todacell.com/" target="_blank">company I work for</a> a nice Dashboard presenting business and operational data on a TV.<br />
<br />
I wanted to add to the Dashboard something cool that will drive people to be more creative.<br />
<br />
I had an idea of showing on the dashboard <a href="http://instagram.com">Instagram</a> photos of the company by posting photos to a predefined hashtag. For example: #mycompany.<br />
<br />
There was one problem: the real-estate on a dashboard TV screen is very expensive and you can not show more then a single photo.<br />
<br />
I remembered that I once encountered a cool JavaScript widget that simply cycles photos with nice transition effects. I thought that it will be nice to connect this widget with <a href="http://instagram.com">Instagram</a> and put it on the dashboard.<br />
<br />
Back then I didn't know that I can also get the assistance of <a href="http://instafeedjs.com/">Instafeed.js</a> in order to get <a href="http://instagram.com">Instagram</a> data easily, so I had to write this part my self.<br />
<br />
The result was pretty cool, so I decided to make a <a href="http://jquery.com/">jQuery </a>widget from it to allow others to use it as well. You can <a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4VWZRb1RTV2Y2aWc">download the widget</a> and use it for your own photos or for showing photos of some hashtag.<br />
<br />
Here is how the widget looks like for the hashtag <b>#love:</b><br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>
<br />
<div id="instagramCyclerCoderEyeLove" style="width:320px; height:320px;">
</div>
<script language="JavaScript">
<!--
$(document).ready(function() {
$('#instagramCyclerCoderEyeLove').cycleInstagram({
'get': 'tagged',
'tagName': 'love',
'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0'
});
});
</script>
</code></pre>
<br />
And here is the result:
<br />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>
<br />
<div id="instagramCyclerCoderEyeLove" style="height: 320px; width: 320px;">
</div>
<script language="JavaScript">
$(document).ready(function() {
$('#instagramCyclerCoderEyeLove').cycleInstagram({
'get': 'tagged',
'tagName': 'love',
'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0'
});
});
</script>
In order to show your own photos you can use the property "get" with the "user" value. Please note that in order to show you own photos, you can simply use for "userId" the word "self". In addition you can see how you can show more than just a photo and even control look of the widget very easily with the "template" property and simple usage of CSS:
<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>
<style>
#instagramCyclerCodeEyerUser {
background-image: url("https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4a1JVbTNoY0N0T0U");
background-size: cover;
width:326px;
height:380px;
}
#instagramCyclerCodeEyerUser img {
padding-top:28px;
padding-left:36px;
}
#instagramCaption {
margin-top:25px;
padding-left:36px;
font-size:18px;
font-family: āLucida Sans Unicodeā, āLucida Grandeā, sans-serif;
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<div id="instagramCyclerCodeEyerUser"></div>
<script language="JavaScript">
$(document).ready(function() {
$('#instagramCyclerCodeEyerUser').cycleInstagram({
'get': 'user',
'userId': 'self',
'tagName': 'todacellmon',
'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0',
'template': '<div><a href="{{link}}"><img src="{{image}}" width="250" height="250" /></a><div id="instagramCaption">{{caption}}</div></div>'
});
});
</script>
</code></pre>
<br />
Here is the result:
<br />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://cdn.rawgit.com/malsup/cycle/master/jquery.cycle.lite.js" type="text/javascript"></script>
<script src="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4anFQam9reXhyNWc" type="text/javascript"></script>
<style>
#instagramCyclerCodeEyerUser {
background-image: url("https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4a1JVbTNoY0N0T0U");
background-size: cover;
width:326px;
height:380px;
}
#instagramCyclerCodeEyerUser img {
padding-top:28px;
padding-left:36px;
}
#instagramCaption {
margin-top:25px;
padding-left:36px;
font-size:18px;
font-family: āLucida Sans Unicodeā, āLucida Grandeā, sans-serif;
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<br />
<div id="instagramCyclerCodeEyerUser">
</div>
<script language="JavaScript">
$(document).ready(function() {
$('#instagramCyclerCodeEyerUser').cycleInstagram({
'get': 'user',
'userId': 'self',
'tagName': 'todacellmon',
'accessToken': '161840.f92bbd9.e0a09d9b00f746c8b2662a4e784e55b0',
'template': '<div><a href="{{link}}"><img src="{{image}}" width="250" height="250" /></a><div id="instagramCaption">{{caption}}</div></div>'
});
});
</script>
<b>PLEASE NOTE:</b> In order to use <a href="http://instagram.com">Instagram</a> API, you should create an access token. You have nothing to worry that others can see your access token as long as you create an access token only for READING. Frankly, creating the access token on <a href="http://instagram.com">Instagram</a>, at least at the time that I did it, was not a simple task. You can find more help on how to do it on <a target="new" href="http://instagram.com/developer/authentication/">Instagram developers section</a> or <a target="new" href="http://jelled.com/instagram/access-token">on this url</a><br /><br />
<b>DOWNLOAD: </b><a href="https://docs.google.com/uc?export=download&id=0B8vXkKUFKJw4VWZRb1RTV2Y2aWc">Here you can download the widget</a>Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-27033251917734028322014-11-13T18:08:00.001+02:002014-11-13T18:14:09.489+02:00Working with SHA1 on SQL Server<br />
There are times you might need to convert some information to MD5 on your SQL Server in HEX format. As it is for now there is no out of the box function to do it on SQL Server. But you can easily accomplish this task by using the following function:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>create FUNCTION [dbo].[sha1]
(
@value varchar(4000)
)
RETURNS varchar(40)
AS
BEGIN
return
case when @value is not null then
SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('SHA1', @value)), 3, 40)
else null end
END
GO</code></pre>
<br />
Testing it is quite straight forward. For example:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>select dbo.sha1('123') </code></pre>
<br />
And here is the output:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>40bd001563085fc35165329ea1ff5c5ecbdbbeef</code></pre>
<br />
<br />
Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-42102978805683900082014-11-12T19:03:00.000+02:002014-11-13T18:13:55.953+02:00Working with MD5 on SQL Server<br />
There are times you might need to convert some information to MD5 on your SQL Server in HEX format. As it is for now there is no out of the box function to do it on SQL Server. But you can easily accomplish this task by using the following function:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>create FUNCTION [dbo].[md5]
(
@value varchar(4000)
)
RETURNS varchar(40)
AS
BEGIN
return
case when @value is not null then
(SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', @value)), 3, 32))
else null end
END
GO</code></pre>
<br />
Testing it is quite straight forward. For example:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>select dbo.md5('123') </code></pre>
<br />
And here is the output:<br />
<pre style="background-color: #eeeeee; border: 1px dashed #999999; color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>202cb962ac59075b964b07152d234b70 </code></pre>
<br />
<br />
Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-63993175478784496052013-04-09T15:12:00.003+03:002014-11-13T18:43:44.011+02:00PC speaker beeps with no apparent reasonI had this problem for about few months: from time to time with no warning, my PC started beeping from its speakers for no apparent reason.<br />
Sometimes it started with several beeps, sometimes it started with a single long beep. When I restarted my computer the problem seemed to pass till the next time.<br />
First, I suspected I had a virus. I made sure I updated my <a href="http://www.kaspersky.com/" rel="nofollow" target="_blank">Kaspersky</a> to the latest version and scanned for viruses with no luck.<br />
<br />
I then went to Windows device drivers manager and stopped the speakers service - but still, the beep used to come whenever it wanted. Eventually, I came with the theory that my machine is getting too hot and therefore I get a warning beep. So I opened the case of the PC to make sure my ventilation is working properly - all seemed right.<br />
<br />
So, I decided to download this small app named <a href="http://www.alcpu.com/CoreTemp/" rel="nofollow" target="_blank">Core Temp</a>. It can give detailed about the temperature of each core of your CPU. It uses information from the CPU itself and not sensors that measure temperature outside the CPU.<br />
<br />
After loading the app I noticed the temperature was around 70 degrees. It seems to me a bit high, but nothing unreasonable. So I decided to wait for the next beep to come. <br />
After few days the beep came again. I loaded the <a href="http://www.alcpu.com/CoreTemp/" rel="nofollow" target="_blank">Core Temp</a> and was amazed to see that the CPU temperature was on 95 degrees!<br />
I quickly opened my PC case and noticed both ventilation are working properly. So I decided to give a closer look at the hit sink below the CPU ventilation. I noticed a huge amount of dust that filled the hit sink.<br />
<br />
I started cleaning all the dust that accumulated there along the time. Then started my computer again and loaded the <a href="http://www.alcpu.com/CoreTemp/" rel="nofollow" target="_blank">Core Temp</a>. Then I noticed the temperature was around 35 degrees!<br />
Eventually the mystery was solved: my PC was beeping like crazy, since the CPU was hitting too much and I couldn't tell there was a problem, because ventilation seemed to work properly.<br />
So if your PC starts to beep with no apparent reason, do yourself a favor and give it attention. It might say that something is seriously wrong. Probably your CPU is over hitting and the blame might be more then a low performing ventilation: DUST.<br />
I assume that the dust may have caused 2 major things:<br />
<ul>
<li>Less effective hit dispensation.</li>
<li>Increases the drag of the ventilation and therefore cause it to rotate slower.</li>
</ul>
When my computer was not working too hard: temperature was around 70 degrees, which was not so good, but not so bad.<br />
<br />
When my computer was working hard, CPU temperature started climbing higher and higher till it reached around 95 degrees and the computer started beeping to warn about the hit.<br />
The small difference of removing the excessive dust made the difference for more than 50 degrees! Worth the effort!Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-55402222810966331622013-02-04T12:19:00.000+02:002013-02-04T12:19:29.467+02:00Change address bar back to Google on FireFoxNowadays, when you install new software on your machine, you can never know if it comes with some other bundled packages that during installation simply change the behavior of your browser/system. During the installation process you get a small check box selected by default, usually on the bottom of the window so you do not notice that you are going to install some additional software.<br />
<br />
Lately this thing happened to me, even tough I always pay attention to these kind of things. I even do not remember what I installed. But as a result of the installation I was not longer able to directly do search on my FireFox address bar.<br />
Companies that usually change the address bar for you without you wanting it are:<br />
<ul>
<li><a href="http://ask.com/">ask.com</a> </li>
<li><a href="http://conduit.com/">conduit.com</a></li>
</ul>
I was able to repair this issue very easily by doing the following steps:<br />
<ol>
<li>Write on FireFox address bar: "about:config". It will take you to advanced settings of FireFox.</li>
<li>Use the "search" text field on the top to filter: "keyword.URL".</li>
<li>Right click on the resulted row and select: "Reset".</li>
</ol>
That's it. As simply as that.<br />
<br />
It is also a good thing if you will try to filter the list by the strings: "ask" and "conduit" in order to reset other things they might have changed in you browser.<br />
Please make sure that you do not do mistakes in the process. Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-36585208592379531092012-07-12T15:41:00.000+03:002014-11-13T11:58:17.146+02:00Use Google photos screen saver without installing Picasa<br />
<br />
Google photo screen saver used to be part of Google Pack. Then Google decided to move it under <a href="http://picasa.google.com/">Picasa</a>. That means, that if you want to use Google photo screen saver you have to install <a href="http://picasa.google.com/">Picasa</a>.<br />
<br />
<br />
I use <a href="http://www.adobe.com/products/photoshop-lightroom.html">Adobe Light Room</a> to edit my photos and I love it. I love Google's photo screen saver. It shows photos much more nicely then Microsoft's built-in photos screen saver and also ads more sources to get photos (like RSS feeds from the internet).<br />
<br />
<br />
I wanted to install Google's photo screen saver without needing to install <a href="http://picasa.google.com/">Picasa</a>. I managed to do it easily by installing <a href="http://picasa.google.com/">Picasa</a>, grabbing it's screen saver file: GPhoto.scr and then uninstalling Picasa.<br />
<br />
<br />
If you would like to use Google photo screen saver without needing to install Picasa, you can simply <a href="https://www.box.com/s/46b747ca2f7b7fce5bc8">download it here</a>, then place this file under Windows folder: c:\windows (or you own windows installation folder).<br />
<br />
<br />
When going to screen savers selection on Windows (the location of this option depends on your Windows version, but can be easily found) you should see Google's photos screen saver on the screen savers list.<br />
<br />
<br />
Enjoy it!Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com5tag:blogger.com,1999:blog-87926254414007961.post-1143094665514581602011-06-06T17:03:00.001+03:002011-06-07T23:19:45.425+03:00Configure Timeout for Apache HttpClient 4.0Adding HTTP request timeout support to <a href="http://hc.apache.org/httpcomponents-client-ga/">HttpClient</a> 4.0  of <a href="http://www.blogger.com/">Appache</a> is quite an easy task. But not as straight forward as one might think. I needed to add such timeout for one of my HTTP requests. I expected to have a method named: "setTimout" or "setConnectionTimeout". But couldn't find any method regarding timeout. After a little digging I found how it can be done. Hope it will save you some time. <br />In general, all you have to do is create an instance of HttpParams and use it in order to define the connection timeout. <br />Let's see how the code looks: <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">package</span> com.bashan.blog.http;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.HttpResponse;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.client.HttpClient;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.client.methods.HttpGet;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.impl.client.DefaultHttpClient;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.params.BasicHttpParams;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.params.HttpConnectionParams;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.params.HttpParams;<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.http.util.EntityUtils;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">/**<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> * @author Bashan<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> */</span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> HttpRequest {<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> main(String[] args) <span style="color: #0000ff">throws</span> Exception {<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #008000">// Set connection timeout</span><br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> HttpParams params = <span style="color: #0000ff">new</span> BasicHttpParams();<br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> HttpConnectionParams.setConnectionTimeout(params, 5000);<br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> HttpConnectionParams.setSoTimeout(params, 5000);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> HttpClient httpClient = <span style="color: #0000ff">new</span> DefaultHttpClient(params);<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> HttpResponse response = httpClient.execute(<span style="color: #0000ff">new</span> HttpGet("<span style="color: #8b0000">http://google.com</span>"));<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> System.out.print(EntityUtils.toString(response.getEntity()));<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> }<br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre></pre><br /><p>You can see in the 3 lines marked in yellow, how the <strong>HttpParams</strong> class is used in order to define the connection timeout. Later an <strong>HttpClient</strong> instance is created with params that is passed to it.</p><br /><p>You can <a href="http://www.box.net/shared/3c8xjps29j">download this class here</a>.</p> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com5tag:blogger.com,1999:blog-87926254414007961.post-18406345901998878172011-05-27T18:29:00.004+03:002011-05-27T23:00:22.438+03:00Show timer with seconds using NSTimer on iPhone and Objective CI am currently developing an iPhone App using X-Code and Objective-C. I had to show a simple timer showing the elapsed number of seconds and minutes. I donāt know much about Objective-C, but from my past experience I knew this task can be easily accomplished using a Timer. The timer should be called every second, and a simple int variable will hold the seconds. The variable is incremented on every call of the timer. <br />This is how I the timer is defined: <br /> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">NSTimer *mainTimer = [NSTimer scheduledTimerWithTimeInterval:1 <br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> target:self <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> selector:@selector(timerController) <br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> userInfo:nil <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> repeats:YES];</pre></pre><br />Note that the timer is set to be activated every one second and the function that will be called every one second is named ātimerControllerā.<br /><br />In the ātimerControllerā function I wrote the code that will increment the seconds variable as well as update a label on the screen. In order to update the label with the minutes and seconds I wrote a small function. The function gets seconds and returns a string of the format: āmm:ssā (for example, for input of 90 the function will return: ā01:30ā. Letās see the function that returns the time:<br /><br /><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">- (NSString*)getTimeStr : (<span style="color: blue">int</span>) secondsElapsed {<br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: blue"> int</span> seconds = secondsElapsed % 60;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: blue"> int</span> minutes = secondsElapsed / 60;<br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: blue"> return</span> [NSString stringWithFormat:@"<span style="color: darkred">%02d:%02d</span>", minutes, seconds];<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}</pre></pre><br />And letās have a look at the ātimeControllerā function that use it:<br /><br /><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">- (<span style="color: blue">void</span>)timerController {<br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> seconds++;<br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> [[self timeLabel] setText:[self getTimeStr]];<br /></pre><pre style="background-color: white; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">}</pre></pre><br />The ātimeLableā is a UILabel control that is connected with a label that is show on the iPhone screen.<br /><br /><br /> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com1tag:blogger.com,1999:blog-87926254414007961.post-81270253203276948742011-05-26T19:05:00.000+03:002011-05-26T19:05:13.713+03:00Add Facebook Like Button to your Blogger.com (BlogSpot)<a href="http://www.facebook.com/">Facebook</a> Like button is a great and easy way of sharing things that you like with your friends. If you have a blog on <a href="http://blogger.com/">Blogger.com</a> (BlogSpot) you can easily add a <a href="http://www.facebook.com/">Facebook</a> like button to any of your posts. Each post will have it's own Like button. This can help increasing the traffic of your blog. <br />
<br />
Let's see how we can easily add <a href="http://facebook.com/">Facebook</a> like button: <br />
<br />
<b>Step 1: Editing out blog template as HTML: <br />
</b> <br />
<ul><li>press on: "Design" on your blog main menu. </li>
<li>Then press on "Edit HTML" on the upper sub menu. </li>
<li>Check "Expand Widget Templates" checkbox. </li>
</ul><b>Step 2:</b> <b>Find the place in which <a href="http://facebook.com/">Facebook</a> Like button code should be entered: <br />
</b>Search for the String: <br />
<pre style="background-color: #fbfbfb; border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; border-right: #cecece 1px solid; border-top: #cecece 1px solid; min-height: 40px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: mediumvioletred;">data</span>:<span style="color: maroon;">post.body</span><span style="color: blue;">/></span></pre></pre><a href="http://facebook.com/">Facebook</a> Like button should be placed before this code. <br />
<br />
<b>Step 3: Put the following code in your blog template:</b><br />
<pre style="background-color: #fbfbfb; border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; border-right: #cecece 1px solid; border-top: #cecece 1px solid; min-height: 40px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: mediumvioletred;">b</span>:<span style="color: maroon;">if</span> <span style="color: red;">cond</span>=<span style="color: blue;">'data:blog.pageType == &quot;item&quot;'</span><span style="color: blue;">></span>
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">iframe</span> <span style="color: red;">allowTransparency</span>=<span style="color: blue;">'true'</span> <span style="color: red;">expr</span>:<span style="color: red;">src</span>=<span style="color: blue;">'&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.url + &quot;&amp;layout=standard&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=arial&amp;colorscheme=light&quot;'</span> <span style="color: red;">frameborder</span>=<span style="color: blue;">'0'</span> <span style="color: red;">scrolling</span>=<span style="color: blue;">'no'</span> <span style="color: red;">style</span>=<span style="color: blue;">'border:none; overflow:hidden; width:450px; height:40px;'</span><span style="color: blue;">/></span>
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"></</span><span style="color: mediumvioletred;">b</span>:<span style="color: maroon;">if</span><span style="color: blue;">></span></pre></pre><br />
After you save your template, go to one of your posts. You could see that a <a href="http://facebook.com/">Facebook</a> Like button was added right under the name of your post.Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-57612751650051865772011-05-16T14:15:00.018+03:002011-05-16T22:49:50.161+03:00Log4j SMTPAppender and deadlocks - Adding Timeout support<p>On the post: <a href="http://www.bashanblog.com/2009/02/sending-email-alerts-with-log4j.html">Sending Email alerts with Log4j</a> we saw how we can easily send mails whenever our system has an exception. But we have to remember that using Apache Log4j <b>SMTPAppender</b>, can be very risky if not used cautiously. In general, the Log4j <b>SMTPAppender </b>has 2 main problems: </p> <ol> <li>The part that send the mail, is synchronous. In fact, it is synchronous between all Log4j appenders. It means that when you log an error and a mail is being sent, all log commands are locked. This is quite risky. Especially when your system has many errors (for whatever reason). This may cause your whole system to get stuck. This issue can be easily handled by using: <strong>AsyncAppender</strong>. I may write about <strong>AsyncAppender</strong> in more detail in the future. </li> <li>The code responsible for sending the mail, which is written by Apache developers, doesn't has a <b>Timeout</b>. That mean, a mail being sent can be stuck forever and simply cause your entire system to go into a deadlock. <br />In this post, we will improve the Apache SMTPAppender to include a <b>Timeout </b>property. The <b>Timout</b> property will make sure, that if a mail is being sent using SMTP connection for too long, it will be dropped. We may loose a report about an exception, but we will make sure our system won't be stuck indefinitely. </li> </ol> <p> <br />We will create a new class name: <b>SMTPAppenderTimeout</b>, that extends <b>SMTPAppender</b>. This new class will override the <b>SMTPAppender </b>method: <b>createSession</b>. <br />The new <b>createSession</b> method will make sure to add the following 2 properties to the mail session:  <br /></p> <ul> <li>mail.smtp.connectiontimeout </li> <li>mail.smtp.timeout </li> </ul> <p> <br />These 2 properties instruct the Java mail framework to set a timeout on the SMTP connection. <br />Let's have a look on the <strong>SMTPAppenderTimeout</strong> class: <br /> <br /></p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">package</span> com.bashan.blog; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> org.apache.log4j.net.SMTPAppender; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> javax.mail.Authenticator; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> javax.mail.PasswordAuthentication; <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> javax.mail.Session; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">import</span> java.util.Properties; <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #008000">/** <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">* @author Bashan <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">*/</span> <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SMTPAppenderTimeout <span style="color: #0000ff">extends</span> SMTPAppender { <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span> timeout; <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> getTimeout() { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">return</span> timeout; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> setTimeout(<span style="color: #0000ff">int</span> timeout) { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">this</span>.timeout = timeout; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> @Override <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">protected</span> Session createSession() { <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> Properties props; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">try</span> { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props = <span style="color: #0000ff">new</span> Properties(System.getProperties()); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <span style="color: #0000ff">catch</span> (SecurityException ex) { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props = <span style="color: #0000ff">new</span> Properties(); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">if</span> (timeout > 0) { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> String timeoutStr = Integer.toString(timeout); <br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props.setProperty("<span style="color: #8b0000">mail.smtp.connectiontimeout</span>", timeoutStr); <br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props.setProperty("<span style="color: #8b0000">mail.smtp.timeout</span>", timeoutStr); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">if</span> (getSMTPHost() != <span style="color: #0000ff">null</span>) { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props.put("<span style="color: #8b0000">mail.smtp.host</span>", getSMTPHost()); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> Authenticator auth = <span style="color: #0000ff">null</span>; <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">if</span> (getSMTPPassword() != <span style="color: #0000ff">null</span> && getSMTPUsername() != <span style="color: #0000ff">null</span>) { <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> props.put("<span style="color: #8b0000">mail.smtp.auth</span>", "<span style="color: #8b0000">true</span>"); <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> auth = <span style="color: #0000ff">new</span> Authenticator() { <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">protected</span> PasswordAuthentication getPasswordAuthentication() { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">return</span> <span style="color: #0000ff">new</span> PasswordAuthentication(getSMTPUsername(), getSMTPPassword()); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> }; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> Session session = Session.getInstance(props, auth); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">if</span> (getSMTPDebug()) { <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> session.setDebug(getSMTPDebug()); <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff">return</span> session; <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> } <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px">} <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre></pre><br /><p>You can also <a href="http://www.box.net/shared/e36xf18222">download</a> the <a href="http://www.box.net/shared/e36xf18222">SMTPAppenderTimeout</a>. <br /> <br /><br /> <br />Let's see an example of a log4j.xml file which use SMTPAppenderTimeout to allow timeout of 5 seconds (5000ms):        </p><br /><pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><?</span>xml version="1.0" encoding="UTF-8" <span style="color: #0000ff">?></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><</span>!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"<span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><</span><span style="color: #800000">log4j</span>:<span style="color: #ff0000">configuration</span> <span style="color: #ff0000">xmlns</span>:<span style="color: #ff0000">log4j</span>=<span style="color: #0000ff">"http://jakarta.apache.org/log4j/"</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">appender</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"RollFile"</span> <span style="color: #ff0000">class</span>=<span style="color: #0000ff">"org.apache.log4j.RollingFileAppender"</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"File"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"C:\\testlog.txt"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MaxFileSize"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"10MB"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"MaxBackupIndex"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"1"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">layout</span> <span style="color: #ff0000">class</span>=<span style="color: #0000ff">"org.apache.log4j.PatternLayout"</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"ConversionPattern"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"%d{HH:mm:ss} %-5p [%c{1}]: %m%n"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"></</span><span style="color: #800000">layout</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"></</span><span style="color: #800000">appender</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">appender</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Email"</span> <span style="color: #ff0000">class</span>=<span style="color: #0000ff">"com.bashan.blog.SMTPAppenderTimeout"</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"BufferSize"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"10"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"SMTPHost"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"smtpout.secureserver.net"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"SMTPUsername"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"test_user"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"SMTPPassword"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"test_password"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffff00; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Timeout"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"5000"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"From"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"someone@mail.com"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"To"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"bashan@mail.com"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"Subject"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"System Error Notification"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">layout</span> <span style="color: #ff0000">class</span>=<span style="color: #0000ff">"org.apache.log4j.PatternLayout"</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">param</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"ConversionPattern"</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"%d [%t] %-5p %c %x - %m%n"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"></</span><span style="color: #800000">layout</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"></</span><span style="color: #800000">appender</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">root</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">priority</span> <span style="color: #ff0000">value</span>=<span style="color: #0000ff">"info"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">appender</span>-<span style="color: #ff0000">ref</span> <span style="color: #ff0000">ref</span>=<span style="color: #0000ff">"RollFile"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">appender</span>-<span style="color: #ff0000">ref</span> <span style="color: #ff0000">ref</span>=<span style="color: #0000ff">"Email"</span> <span style="color: #0000ff">/></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"></</span><span style="color: #800000">root</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"></</span><span style="color: #800000">log4j</span>:configuration<span style="color: #0000ff">></span></pre></pre><br /></layout></appender-ref></appender-ref></priority></root></log4j:configuration>You can also <a href="http://www.box.net/shared/fc9r22k6sn">download</a> the <a href="http://www.box.net/shared/fc9r22k6sn">log4j.xml</a>.<br /><br /><br /><br /><br /> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-14334445381616298362011-04-24T01:09:00.002+03:002011-05-26T19:10:18.588+03:00Nikon D7000 vs Nikon D300 or should I wait for the Nikon D400?<p>I was waiting for the Nikon D400 to come out for too long. It has been more than 4 years since I bought my Nikon D300. I love this camera. But it has gotten too old. I wanted something new and the Nikon D400 doesnāt seem to show any signs of coming out. So I got tired of waiting, and just bought the Nikon D7000. I wanted to share some of my feelings of my new Nikon D7000 and do a small comparison with my good and old Nikon D300, so those of you who own the Nikon D300 could have an easier decision regarding purchasing the Nikon D7000. So, before comparing the Nikon D7000 and Nikon D300, I can spare you from reading and tell you that I simply love my new Nikon D7000 and I do recommend you go and buy one. If you own a Nikon D300, you wonāt regret it. Although the Nikon D7000 is less pro, itās newer technology definitely puts it in a better place than Nikon D300 and even Nikon D300s and all for that for less price. OK, so letās start to see what is so good on the <b>Nikon D7000</b>:</p> <p><b>Focus System:</b></p> <p>Nikon D300 has 51 focus points from which 15 are cross-type. 51 focus points are a lot, and the Nikon D300 has great focus system. It is fast, accurate and allows you to do continuous and even tracking focus. But, although the Nikon D7000 has less focus points: 39 from which 9 are cross-type, it has very fast and accurate focus system. I think even faster and better than the one of the Nikon D300. You donāt have anything to worry about, all the focus options from the Nikon D300 exist in the Nikon D7000. <b></b></p> <p><b>Controls:</b></p> <p>Thatās one of the things I worried about when I wanted to buy the Nikon D7000. After so much time that I got used to all the fast and easy on-camera controls of the Nikon D300, I worried that I will really miss them on the Nikon D7000. Well, now that I got the Nikon D7000, I can tell you that I donāt miss those buttons much. I mean, it was nice to have these buttons there, but you can easily manage without them on the Nikon D7000. Switching the ISO (I usually choose the ISO manually), White Balance (I almost never change it from Automatic), and metering mode are all all done same as the Nikon D90/D80. But, there is a new button, placed on the focus AF/M selection switch. This new button along with the two front and back wheels allows you to quickly and easily select your desired focus mode. This new cool button, makes it easier to forget those loveable focus switches on the Nikon D300. <b></b></p> <p><b>Viewfinder:</b></p> <p>The Nikon D7000 has 100% viewfinder coverage. comparing to the 95% viewfinder coverage of the Nikon D300, you can see entirely what you are going to shoot. Itās the first time I am using a 100% coverage viewfinder and I like it. <b>Better image </b></p> <p><b>Quality:</b></p> <p>The Nikon D7000 has better image quality. You have to look at the results and decide for yourself. In my opinion the results are better. Although the Nikon D7000 has 16.2 MP sensor (comparing to the Nikon D300), the image quality is better at all ISO ranges. A sensor containing more pixels, means smaller pixels. Smaller pixels mean more noise at higher ISOs. But the D7000 seems to be dealing better with noise than the D300. The Nikon D7000 has better color depth: 24bit comparing to 22bit. Thatās about x2.5 more colors. In addition, the Nikon D7000 has better dynamic range: 14EV comparing to 12EV of the Nikon D300. Thatās more 2 f-stops on the D7000.</p> <p><b>Continuous Shooting:</b></p> <p>The Nikon D300 shoots 7 frames per second. The Nikon D7000 shoots 6 frames per second. That makes the Nikon D300 a bit better when it comes to continuous shooting. There are times when continuous shooting can be a great help, but the difference between 6 to 7 frames per second is not that big. In addition, when you set the Nikon D300 D-Lightning feature, or you set your ISO to be 800 or higher (when high ISO cleaning option is turned on), the processing is too slow, so after about 8 photos, the shooting rate goes down dramatically. The D7000 doesnāt seem to suffer from this issue.</p> <p><b>Shutter Noise:</b></p> <p>One of the most annoying things of the Nikon D300 is itās shutter noise. This is really an extreme noise. I donāt know how Nikon released a camera with such a strong shutter noise. Well, on the Nikon D7000 you donāt have to worry about noise. The shutter makes much less noise, even when shooting continuously. If you want even less noise you have a special āquiteā mode that will reduce the noise even further.</p> <p><b>Memory Slots:</b></p> <p>The Nikon D7000 has 2 memory slots. Additional memory slot means more memory. More memory means you can store more photos. This is good when you shoot on RAW mode which takes considerably more space for each photo, or you shoot 1080p video which takes a lot of space. You can also use the 2 slots to function as backup (each photo is stored on 2 cards). <b>Video:</b> Well, I donāt shoot video. But with the Nikon D7000 you can easily shoot 1080p Video with 24 fps. You shoot the video using your good Nikon lenses, so you can get great results with shallow depth of field. The video is shown on the back screen and there is an automatic focusing system that can identify faces. It is working very nice. You can also edit the video on the camera.</p> <p><b>Size and Weight:</b></p> <p>The Nikon D7000 is smaller in size and lighter in weight than the Nikon D300, but it still has a strong grip and it feels good in your hands. It is not well built as the Nikon D300, but it still has a very satisfying built quality <b>Price:</b> Event today, after more than 4 years that the Nikon D300 exists in the market (I believe Nikon has already stopped producing it), it is sold for about more than $200 than the Nikon D7000.</p> <p><b>Summary:</b></p> <p>I own the Nikon D7000 for only 2 days. I have taken with it only 200 photos. It may be a short period for solid opinion, but so far I am very satisfied with it. If you own a Nikon D300 or Nikon D300s I think the Nikon D7000 is a good upgrade choice for a decent price. Since the Nikon D400 is still not on the horizon (with the recent earthquake on Japan, it will probably event take longer), and it seems like it is going to be with the same sensor of the Nikon D7000 but with more focus points and stronger body, I think it is not worth the time and money waiting for the Nikon D400.</p> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com2tag:blogger.com,1999:blog-87926254414007961.post-9800479312550318922011-04-10T23:17:00.003+03:002011-04-10T23:44:50.863+03:00Check if Virtual Box / VMWare can run 64bit Operating Systems<p><a href="http://www.virtualbox.org/">VirtualBox</a> and <a href="http://www.vmware.com/">VMWare</a> are great virtualization software allowing you to easily run virtual operating systems on your machine.</p> <p>Creating a new virtual machine is an easy task. You create a new virtual machine, set some parameters and you are ready to go. You get a new place to install any operating system of your choice.</p> <p>Sometime we would like to install 64bit operating system. 64bit operating system, can take advantage of 64bit machine and do some of the operations almost twice faster than 32bit. Todays modern computers are mostly support 64bits. If your machine support 64bit, it means you can install 64bit operating system on it. Buy, it doesnāt mean you can install 64bit operating in a virtual environment. In order to be able to run 64bit operating system on <a href="http://www.virtualbox.org/">VirtualBox</a> and <a href="http://www.vmware.com/">VMWare</a> you should have a machine that support it. Running a 64bit operating system in a virtual environment requires hardware level support.</p> <p><a href="http://www.vmware.com/">VMWare</a> made a small utility that helps you to check if your machine supports installing 64bit operating systems.</p> <p>The tool is called: <a href="http://downloads.vmware.com/d/details/processor_check_5_5_dt/dCpiQGhkYmRAZQ==">Processor Check for 64-Bit Compatibility</a> and you can find on <a href="http://downloads.vmware.com/d/details/processor_check_5_5_dt/dCpiQGhkYmRAZQ==">this link</a>.</p> <p>If your machine allows you to run 64bit operating systems on virtual machines you will get this message:</p> <p><a href="http://lh3.ggpht.com/_0G45OzGsIro/TaIWIHRgQnI/AAAAAAAAD8Q/8nAD09-yfUk/s1600-h/vmware-1%5B3%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="vmware-1" border="0" alt="vmware-1" src="http://lh3.ggpht.com/_0G45OzGsIro/TaIWI3CVEnI/AAAAAAAAD8U/I-GcUk-e2HY/vmware-1_thumb%5B1%5D.png?imgmax=800" width="491" height="188" /></a></p> <p>And if your if your machine doesnāt allow you to run 64bit operating systems on virtual machines you will get this message:</p> <p><a href="http://lh6.ggpht.com/_0G45OzGsIro/TaIWJgfVtyI/AAAAAAAAD8Y/KqnkyaIfzXI/s1600-h/vmware-2%5B3%5D.png"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="vmware-2" border="0" alt="vmware-2" src="http://lh3.ggpht.com/_0G45OzGsIro/TaIWKcMbHUI/AAAAAAAAD8c/gTmc82-oiLY/vmware-2_thumb%5B1%5D.png?imgmax=800" width="474" height="206" /></a></p> <p>Note that I run this utility on 2 different machines, both are 64bit capable, both have Windows 7 64bit installed. One machine allows running 64bit operating systems on virtual machines and one doesnāt allow.</p> Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-26431718060806074532011-04-05T00:17:00.003+03:002011-04-09T00:48:04.655+03:00Convert image file .img to .isoBoth <a href="http://en.wikipedia.org/wiki/IMG_%28file_format%29">ā.imgā</a> and <a href="http://en.wikipedia.org/wiki/ISO_image">ā.isoā</a> are file formats contains data packed together and ready to be burned.<br />
I recently had to convert ā.imgā file to ā.isoā file. after a little search I got to <a href="http://www.magiciso.com/">this small piece of software</a> called <a href="http://www.magiciso.com/">Magic ISO</a>.<br />
After a small installation process and loading the application go to āToolsā and select āConvertā¦ā from the menu:<br />
<br />
<a href="http://lh4.ggpht.com/_0G45OzGsIro/TZo1XtRLT8I/AAAAAAAAD7g/20hVm71wvAY/s1600-h/magiciso1%5B4%5D.png"><img alt="magiciso1" border="0" height="548" src="http://lh4.ggpht.com/_0G45OzGsIro/TZo1ZqGjJ8I/AAAAAAAAD7k/VDM3-srNxpA/magiciso1_thumb%5B2%5D.png?imgmax=800" style="background-image: none; border: 0px none; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="magiciso1" width="701" /></a><br />
<br />
<br />
The dialog is open, simply select the ā.imgā file you would like to convert and set a new directory to locate the outputed ā.isoā file (only if you would like a different directory than the one of the ā.imgā file:<br />
<br />
<a href="http://lh4.ggpht.com/_0G45OzGsIro/TZo1akxroCI/AAAAAAAAD7o/SJBz4TlOuMk/s1600-h/magiciso2%5B6%5D.png"><img alt="magiciso2" border="0" height="549" src="http://lh5.ggpht.com/_0G45OzGsIro/TZo1b2drfdI/AAAAAAAAD7s/_Oel60giaDc/magiciso2_thumb%5B4%5D.png?imgmax=800" style="background-image: none; border: 0px none; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="magiciso2" width="702" /></a>Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-8148199457613819212011-03-30T22:26:00.000+02:002011-03-30T22:26:24.698+02:00Automatically delete Tomcat access log old filesOn the post <a href="http://www.bashanblog.com/2011/01/enable-tomcat-access-log.html" title="http://www.bashanblog.com/2011/01/enable-tomcat-access-log.html">Enable Tomcat acess log</a> we saw how Tomcat can be easily configured to log all HTTP requests coming to our server.<br />
For some reason, Tomcat doesn't have a mechanism that also makes sure to delete old access log files. This is a bit weird, because I assume that Tomcat is using <a href="http://logging.apache.org/log4j/1.2/">Log4j</a> in order to log the requests, and <a href="http://logging.apache.org/log4j/1.2/">Log4j</a> has a built in mechanism for rotating and deleting old log files.<br />
Anyway, since Tomcat doesnāt take care of all these access log files that are being added, and since a typical production server may produce access log files of several giga per day, your disk might get out of space pretty quick.<br />
we will build a small class that will handle old access log files deletion.<br />
First, we need to get the following information:<br />
<ul><li>Tomcat access log files directory.</li>
<li>Access log file structure. The default structure is: localhost_access_log.yyyy-MM-dd.txt</li>
<li>Access log date format: The default structure is: yyyy-MM-dd</li>
<li>Number of access log files we would like to keep as backup. For example, if we choose: 10 it means that we would like to keep the last 10 access log files.</li>
</ul>The idea is very simply:<br />
<ul><li>We get all access log files on the directory.</li>
<li>We extract the date of each log file.</li>
<li>We sort all the files on ascending order.</li>
<li>We delete the oldest files making sure to keep the requested number of backups.</li>
</ul>Letās have a look at our access log files deletion class. Itās code is quite simple:<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">package</span> com.bashan.blog.log;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> org.apache.commons.logging.Log;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> org.apache.commons.logging.LogFactory;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.io.File;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.io.FilenameFilter;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.text.ParseException;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.text.SimpleDateFormat;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.util.*;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.util.regex.Matcher;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.util.regex.Pattern;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: green;">/**
</span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">* @author Bashan
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">*/
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> TomcatAccessLogCleaner <span style="color: blue;">extends</span> TimerTask {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> <span style="color: blue;">static</span> <span style="color: blue;">final</span> Log log = LogFactory.getLog(TomcatAccessLogCleaner.<span style="color: blue;">class</span>);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> <span style="color: blue;">static</span> <span style="color: blue;">final</span> String DEFAULT_LOG_FILE_PATTERN = "<span style="color: darkred;">localhost_access_log\\.yyyy-MM-dd\\.txt</span>";
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> <span style="color: blue;">static</span> <span style="color: blue;">final</span> String DEFAULT_DATE_FORMAT = "<span style="color: darkred;">yyyy-MM-dd</span>";
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> String dateFormat;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> Pattern logFilePat;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> File logFileDir;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> <span style="color: blue;">int</span> numBackups;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> TomcatAccessLogCleaner(File logFileDir, <span style="color: blue;">int</span> numBackups) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>(logFileDir, DEFAULT_LOG_FILE_PATTERN, DEFAULT_DATE_FORMAT, numBackups);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> TomcatAccessLogCleaner(File logFileDir, String logFilePattern, String dateFormat, <span style="color: blue;">int</span> numBackups) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.dateFormat = dateFormat;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.logFileDir = logFileDir;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">String pat = logFilePattern.replace(dateFormat, "<span style="color: darkred;">(.+?)</span>");
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">logFilePat = Pattern.compile(pat);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.numBackups = numBackups;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">void</span> clean() {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">log.info("<span style="color: darkred;">Starting to clean old Tomcat access logs. Number of backups to keep: </span>" + numBackups);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">File[] files = logFileDir.listFiles(<span style="color: blue;">new</span> FilenameFilter() {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">boolean</span> accept(File dir, String file) {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> return</span> logFilePat.matcher(file).matches();
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">});
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">List<LogFile> logFiles = <span style="color: blue;">new</span> ArrayList<LogFile>(files.length);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> for</span> (File file : files) {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> try</span> {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">LogFile logFile = <span style="color: blue;">new</span> LogFile(file, logFilePat, dateFormat);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">logFiles.add(logFile);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">} <span style="color: blue;"> </span></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> catch</span> (ParseException pe) {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">} </pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> </pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">Collections.sort(logFiles, <span style="color: blue;">new</span> Comparator<LogFile>() { </pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">@Override
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">int</span> compare(LogFile o1, LogFile o2) {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> return</span> o1.getLogDate().compareTo(o2.getLogDate());
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">});
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> int</span> numFilesToClean = logFiles.size() - numBackups;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> int</span> removed = 0;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> for</span> (<span style="color: blue;">int</span> i = 0; i < numFilesToClean; i++) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">LogFile logFile = logFiles.get(i);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">log.debug("<span style="color: darkred;">Deleting access log file: </span>" + logFile);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> if</span> (!logFile.getFile().delete()) {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">log.warn("<span style="color: darkred;">Failed deleting log file</span>");
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">log.info("<span style="color: darkred;">Finished cleaning old Tomcat access logs. Total log files: </span>" +
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">logFiles.size() + "<span style="color: darkred;">. Deleted: </span>" + removed + "<span style="color: darkred;"> of </span>" + Math.max(0, numFilesToClean));
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> LogFile {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> File file;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> private</span> Date logDate;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> LogFile(File file, Pattern pattern, String dateFormat) <span style="color: blue;">throws</span> ParseException {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">Matcher matcher = pattern.matcher(file.getName());
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> if</span> (matcher.find()) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">String dateStr = matcher.group(1);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">SimpleDateFormat sdf = <span style="color: blue;">new</span> SimpleDateFormat(dateFormat);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">logDate = sdf.parse(dateStr);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.file = file;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> File getFile() {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> return</span> file;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">void</span> setFile(File file) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.file = file;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">} </pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> </pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> Date getLogDate() {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> return</span> logDate;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> </span></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">void</span> setLogDate(Date logDate) {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> this</span>.logDate = logDate;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">} </pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"> </pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">void</span> run() {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">clean();
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}</pre></pre>Note that <b>TomcatAccessLogCleaner</b> extends <b>TimeTask</b>. This enables easily using this class with a timer, allowing it to run every fix interval, and clean Tomcat access log files.<br />
You can <a href="http://www.box.net/shared/absvt9afsn">download this class here</a>.<br />
Letās have a look of an example, showing how this class can be used in a servlet. The class will be scheduled to run automatically every 24 hours and clean old access log files. The class will be scheduled once when servlet loads. Donāt forget that you have to map servlets on your <b>web.xml</b>:<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">package</span> com.bashan.blog.log;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> javax.servlet.ServletConfig;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> javax.servlet.ServletException;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> javax.servlet.http.HttpServlet;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.io.File;
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">import</span> java.util.Timer;
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: green;">/**
</span></pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">* @author Bashan
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">*/
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> TomcatAccessLogCleanerServlet <span style="color: blue;">extends</span> HttpServlet {
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> public</span> <span style="color: blue;">void</span> init(ServletConfig config) <span style="color: blue;">throws</span> ServletException {
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"> super</span>.init(config);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">Timer time = <span style="color: blue;">new</span> Timer();
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">TomcatAccessLogCleaner tomcatAccessLogCleaner = <span style="color: blue;">new</span> TomcatAccessLogCleaner(<span style="color: blue;">new</span> File("<span style="color: darkred;">c:\\tomcat access log dir</span>"), 10);
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">time.scheduleAtFixedRate(tomcatAccessLogCleaner, 0, 1000 * 60 * 60 * 24);
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">}</pre></pre>You can <a href="http://www.box.net/shared/6ex4fts7h7">download the servlet here</a>.Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com6tag:blogger.com,1999:blog-87926254414007961.post-49725834796233040272011-03-28T16:45:00.001+02:002011-03-30T00:04:05.105+02:00List of Mobile Devices and Brands as SQL insertsI compiled a list of all mobile vendor (brands like Apple, Nokia) and models (mobile devices like iPhone, Galaxy S) as SQL inserts. <br />
This list is a good place to start, but mobile devices are being added all the time. If you have a web application that needs to show list of mobile devices this list can help you. Note that the table contains both vendor and model, so it is best to show data in two drop downs: one for vendors and one for models. The drop down of the vendors is used as a filter to the drop down of the models.<br />
This is the structure of the devices table (mySQL style):<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=CREATE&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">CREATE</a> <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=TABLE&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">TABLE</a> `device` (
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">`vendor` <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=varchar&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">varchar</a>(100) <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=NOT&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">NOT</a> <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=NULL&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">NULL</a>,
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">`model` <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=varchar&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">varchar</a>(100) <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=NOT&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">NOT</a> <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=NULL&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">NULL</a>,
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=PRIMARY&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">PRIMARY</a> <a href="http://search.microsoft.com/default.asp?so=RECCNT&siteid=us%2Fdev&p=1&nq=NEW&qu=KEY&IntlSearch=&boolean=PHRASE&ig=01&i=09&i=99" style="color: blue;">KEY</a> (`vendor`,`model`)
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">) ENGINE=InnoDB</pre></pre>The list of the inserts if very long. You can download it by <a href="http://www.box.net/shared/mtoi7es0uq">using this link</a>.Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com2tag:blogger.com,1999:blog-87926254414007961.post-33430802752766133012011-03-22T00:03:00.004+02:002011-03-22T00:16:48.877+02:00How to Jump to an Anchor using JavaScriptJust like links/urls are a great way of moving between pages, anchors are great way of moving between locations on the same page.<br />
Suppose we would like to move to a specific location on a page above some <b><div></b> tag. All we have to do is simply put an <b><a></b> tag above that div and give it some name. For example:<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="background-color: yellow;"><span style="color: blue;"><</span><span style="color: maroon;">a</span> <span style="color: red;">name</span>=<span style="color: blue;">"example"</span><span style="color: blue;">></span><span style="color: blue;"></</span><span style="color: maroon;">a</span><span style="color: blue;">></span></span>
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">...
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">...
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;">...
</pre><pre style="background-color: white; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"></</span><span style="color: maroon;">div</span><span style="color: blue;">></span>
</pre><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"></pre></pre><br />
How do we jump to this specific location (named: <b>example</b>)? By putting an <b><a></b> on the place from which we would like to jump to this location. For example, somewhere else on the page we put:<br />
<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">a</span> <span style="color: red;">href</span>=<span style="color: blue;">"#example"</span><span style="color: blue;">></span>Press here to show example<span style="color: blue;"></</span><span style="color: maroon;">a</span><span style="color: blue;">></span></pre></pre><br />
Note, that the name of the anchor for which we would like to jump contains the hash sign (#) as a prefix.<br />
<br />
Now, suppose we would like to jump to some location by clicking something other than <b><a></b> (anchor) tag. For example by clicking a simple button. How can we jump to that location? Since we are not using anchor tag, we can no longer be directed to that location automatically.<br />
<br />
We can use JavaScript in order to accomplish exactly the same behavior. Letās see how it can be easily done with our button and by setting the āwindow.location.hashā property :<br />
<br />
<pre style="background-color: #fbfbfb; border: 1px solid rgb(206, 206, 206); min-height: 40px; overflow: auto; padding: 5px; width: 650px;"><pre style="background-color: #fbfbfb; font-family: consolas,'Courier New',courier,monospace; font-size: 12px; margin: 0em; width: 100%;"><span style="color: blue;"><</span><span style="color: maroon;">input</span> <span style="color: red;">type</span>=<span style="color: blue;">"button"</span> <span style="color: red;">value</span>=<span style="color: blue;">"Press here to show example"</span> <span style="color: red;">onclick</span>=<span style="color: blue;">"window.location.hash = 'example';"</span><span style="color: blue;">/></span></pre></pre><br />
Note that on the JavaScript code we no longer need to use the hash (#) prefix.Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com0tag:blogger.com,1999:blog-87926254414007961.post-70301768324534350082011-03-21T00:21:00.003+02:002011-03-21T00:25:16.816+02:00Automatically Add āwwwā to your site on Tomcat or: Canonical Hostnames<p>Sometimes we would like that our website domain will always contain āwwwā.</p> <p>I can this of two good reasons (beside of making all your siteās urls neat and unified) for adding āwwwā to your site urls: </p> <ul> <li><strong>To avoid cookie issues:</strong> Cookies are being stored for domains. <strong>www.example.com</strong> and <strong>example.com</strong> are 2 different domains when it comes to cookies. So if you would like to store some data in a cookie without wondering where did it disappear. Unify all the urls of your site to contain āwwwā and you are always working on the same domain.</li> <li><strong>To avoid security issues:</strong> Sometimes we would like to do some JavaScript coding on our site that may require us to be on the same domain (for example: running some JavaScript code from an iFrame on the parent window). Since url with āwwwā and url without āwwwā is considered to be a different domain, by making sure all of our urls contain the āwwwā prefix, we make sure we will not fall in all kind of cross domain security traps.</li> </ul> <p>So, how do we make sure all our urls will always contain the āwwwā prefix" on Tomcat?</p> <p>Luckily for us there is a great Java open source project named <a href="http://www.tuckey.org/">tuckey</a> that can easily help us to accomplish that task. <a href="http://www.tuckey.org/">Tuckey</a> is Url rewrite filter. It rewrites our urls according to set of predefined rules. As you noticed <a href="http://www.tuckey.org/">tuckey</a> is doing much more than just adding āwwwā to our urls, but this is not for the scope of this post. You can learn more about <a href="http://www.tuckey.org/">tuckey</a> and download it from this web site: <a href="http://www.tuckey.org/">http://www.tuckey.org/</a>.</p> <p>After you download and install <a href="http://www.tuckey.org/">tuckey</a> on your web application (it is well details on the <a href="http://www.tuckey.org/">tuckey</a> web site how this thing can be done), you simply have to add this rule to you <strong>urlrewrite.xml</strong> file:</p> <pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"><</span><span style="color: #800000">rule</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">name</span><span style="color: #0000ff">></span>Canonical Hostnames<span style="color: #0000ff"></</span><span style="color: #800000">name</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">condition</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"host"</span> <span style="color: #ff0000">operator</span>=<span style="color: #0000ff">"notequal"</span><span style="color: #0000ff">></span>^www.mydomain.com<span style="color: #0000ff"></</span><span style="color: #800000">condition</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">condition</span> <span style="color: #ff0000">name</span>=<span style="color: #0000ff">"host"</span> <span style="color: #ff0000">operator</span>=<span style="color: #0000ff">"notequal"</span><span style="color: #0000ff">></span>^$<span style="color: #0000ff"></</span><span style="color: #800000">condition</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">from</span><span style="color: #0000ff">></span>^/(.*)<span style="color: #0000ff"></</span><span style="color: #800000">from</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #ffffff; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"> <span style="color: #0000ff"><</span><span style="color: #800000">to</span> <span style="color: #ff0000">type</span>=<span style="color: #0000ff">"redirect"</span> <span style="color: #ff0000">last</span>=<span style="color: #0000ff">"true"</span><span style="color: #0000ff">></span>http://www.mydomain.com/$1<span style="color: #0000ff"></</span><span style="color: #800000">to</span><span style="color: #0000ff">></span><br /></pre><pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"><span style="color: #0000ff"></</span><span style="color: #800000">rule</span><span style="color: #0000ff">></span></pre></pre><br />Make sure that this rule is the first rule on your <strong>urlrewrite.xml</strong> file. Guy Bashanhttp://www.blogger.com/profile/13987595961461293379noreply@blogger.com3