Showing posts with label Work. Show all posts
Showing posts with label Work. Show all posts

Tuesday, August 16, 2011

VMware (Player) Port Forwarding

As I said in one of my previous posts, I _love_ VMWare Player (much more than its Workstation brother). There is no surprise, I want to have some neat port forwarding (from HOST machine to VMWare).

I found the following information on http://asunix.tufts.edu/howto/vmware/portforwardingWin7:

Step 0: If using VMware Workstation, continue to Step 1. However, if using VMware Player, you need to extract the `Virtual Network Editor' from the installer via the following command:

$> VMware-player-setup.exe /e .\extract

Go into `extract' -> `network' and copy `vmnetcfg' into the VMware Player directory before you use this tool. Once `vmnetcfg' is in the VMware Player folder, you can launch this tool to configure the NAT port forwarding.

Step 1: Open the Virtual Network Editor ( either from Workstation or launch `vmnetcfg' )

Step 2: Choose `VMnet8' from the interface list, change the Subnet IP at the bottom of the panel to `192.168.192.0' then and choose `NAT Settings...' from the VMnet Information panel.

Step 3: Ensure that the Gateway IP is set to `192.168.192.2' and then choose `Add' under the Port Forwarding panel.

Step 4: Fill in the port map information with the following data:

Host Port: 22

Type: TCP

Virtual machine IP address: 192.168.192.100

Virtual machine port: 22

Description: SSH

Step 5: Apply all settings and close out of the Virtual Network Editor.

Friday, September 18, 2009

Java Read/Write Files in UTF-8

Even after several years of Java experience, there still can be confusion reagarding handling of files with different encodings.

One thing that is unclear most of the times is that encoding only makes sense if you are trying to read/write character data. For this Java created the Readers and Writers. They only handle textual content and they bridge byte streams to character streams by encoding/decoding the bytes using a specified encoding (char set). For binaries (or for textual content not actually represented as text) one can use normal input/output byte streams.

Reading textual content from a file using UTF-8 encoding:
public static String getContents(File aFile) {
StringBuffer result = new StringBuffer();
BufferedReader br = null;

try {
int len = 0;
char[] buffer = new char[8192];
br = new BufferedReader(new InputStreamReader(
new FileInputStream(aFile), "UTF-8"));
while ((len = br.read(buffer)) != -1) {
result.append(buffer, 0, len);
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}

return result.toString();
}

Writing textual content from a file using UTF-8 encoding:
public static void saveContent(String content, String fileName) {
String directoryName = fileName.substring(0,
fileName.lastIndexOf(File.separatorChar));
if (directoryName.length() > 0) {
File outputFile = new File(directoryName);
outputFile.mkdirs();
}

BufferedWriter writer = null;
try {
writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(fileName), "UTF-8"));
writer.write(content);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

Thursday, May 7, 2009

Transforming XML with XSLT using JSTL

Example is using JSTL 1.1 and EL:

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>

<c:import var="xml" url="/sample.xhtml"/>
<c:import var="xsl" url="/stlyesheet.xsl"/>

<x:transform xml="${xml}" xslt="${xsl}">
<x:param name="request" value="${pageContext.request}" />
<x:param name="response" value="${pageContext.response}" />
</x:transform>

Check also the other JSTL related blogs:
- The JSTL Fine Print
- JSTL request attribute

Wednesday, April 8, 2009

How to construct a JSP PageContext outside a JSP

I think it's the third time I was asked how to get a JSP servlet PageContext when you are not on a JSP. The solution is the following:

JspFactory jspxFactory = JspFactory.getDefaultFactory();
PageContext pageContext = jspxFactory.getPageContext(this, request, response, null, true, 8192, true);


Tip: I got this from the decompiled servlet that is always generated from a JSP. Just look in the belly of Tomcat (work folder) and you'll find the actual Java/class file.

Friday, March 20, 2009

Charlotte, NC

This week I was at a client in Charlotte, North Carolina. The project is going fine. I am working on an interesting piece of code -- exposing Tridion functionality as a Web Service / Java servlet, so that other web applications can read content from it using SOAP or plain HTTP requests.

Anyway, some remarkable things are the beer which is very cheap compared to California or NY and that I almost punched a partner. He was too much of a wise arse, claiming sarcastically that Tridion is rocket science. I luckily refrained from explaining Tridion functionality with my fists. However, funny enough, they bailed out of the project just 2 days later. Hmmm... maybe it was too much of rocket science after all. Ha ha :D

I also met up with Andi and Alina, old friends from back home. It is rare to see familiar faces where my job takes me, so meeting up with Andi and Alina was definitely a big plus. They showed me Charlotte, went to dinner, went to an Irish pub and just spent lots of time catching up. Here are some pictures from this lovely meeting:

Wednesday, February 25, 2009

So easy to work with smart people

This week I was in Boston to have an architecture workshop with a partner. I admit, it was probably the best sessions I ever had. I would always recommend these guys. For somebody who didn't know Tridion, they were so quick to pick up knowledge and to take it to the next level, even before I had the chance to introduce it.

It makes my job so easy and fulfilled when working with smart people. In 3 days, we accomplished what in other projects would probably take 2 weeks.
The partner is called Thoughtworks (from India).

Logisticly, it was quite funny that I almost missed my plane on the way to Boston. It was Sunday evening, after the Oscars, when I arranged for a 'fancy taxi' to take me from San Jose to San Francisco airport. The guy was supposed to pick me up at 9 p.m., and after calling them at 9:15, he told me he misunderstood my request and that he would have picked me up on Monday morning at 9 a.m. Luckilly, my brother in law gave me a ride to SFO.

Friday, February 13, 2009

KD New York

On February 12 & 13 there were the Knowledge Days for PS US. Held in New York, I arrived on the 12th in the morning (after a 8 hour overnight flight, direct from San Jose with JetBlue). Very nice airline, with plenty of leg space (extra leg space seats available for only 10$ extra). Anyway, trying to sleep in an airplace chair sucks big time!

In the evening, Chris cooked a great dinner for everybody. Thanks, Chris! It was paella and lots of wine on the side. Again a great night with PS colleagues.

On Friday, I had to leave a bit early to catch the plane from JFK at 6 p.m. At 9 p.m. I was back in San Jose, after a 6 hour flight. I love air travel.

Thursday, January 29, 2009

Viva San Diego

Nici nu am apucat să îmi trag sufletul după marea mutare... că firma m-a şi trimis la client. Aşa că, începând de luni seară sunt in San Diego. Oraş foarte plăcut, liniştit... îmi aminteşte de New Orleans într-un fel - străzile din centru, numit Gas Lamp, sunt pline de restaurante, cluburi de jazz, terase, chiar şi baruri pe stradă... adică un fel de terasă care nu are decât un blat pe post de bar, ca să poţi sta şi savura un pahar. Totuşi nu se poate bea pe stradă... New Orleansul era şi mai pitoresc de altfel.

Lucrul la client merge tare încet... mă plicti destul de tare. În schimb mai am timp să vizitez câte un pic seara. În prima seară, Marţi, am făcut greşală mare, tovarăşa profesoară... am mers, la recomandarea colegilor de la firmă totuşi, la un restaurant brazilian de jenul all-you-can-eat. Şi Doamne-ţi mulţam, io pot mânca. Erau vreo 10 de feluri de carne, cu care umblau vreo 10 chelneri pe proţap. Tot cam la 2 minute apărea unul pe la mese şi îţi tăia o felioară. Pe masă avea un fel de solniţă cu un cap roşu şi unul verde. Atâta timp cât capul verde era deasupra ei îţi aduceau carne. Mai era şi un bar de salată de toate gusturile, formele şi apetitele. Mi-am dat însă seama că ăla e pentru neştiutori, care se lăcomesc pe salată şi nu mai am loc de cărnuri... aşa că nu am cazut în capcana lor şi am fost tare cumpătat la salate... he he he. Localul se numeşte Rei Do Gado pe 4th street.

În seara asta am fost la altă minunăţie culinară... Un local de genul Coco's Outback din Amsterdam, adică un fel de bar în care se serveşte mâncare multă, într-un mod tare rustic... adică din găleţi. Se numeşte Rockin' Baja şi e specializat pe creveţi. Aşa că am păpat o găleată de creveţi cu nişte pui şi o bucată de vită. Iam Iam! :)

De mâine începem dieta... iarăşi! He he...