Some hard-to-find research articles

January 24, 2012 Leave a comment
Categories: Uncategorized

Java, automatically change file name if file exists

March 24, 2011 Leave a comment

If you want to save a file to a certain directory, but don’t want to overwrite existing file. You want to append the file name with an index. Say, you want your file as “myFile.txt”. If “myFile.txt” exists already, you want to change your file name to “myFile1.txt”.

Here is the solution.


String fileName = "myFile";
String extension = ".txt";
String fixedPrefix = fileName;
Integer i=1;

boolean oldFileExist = true;
while (oldFileExist)
{
try {
FileInputStream inputStream = new FileInputStream(fileName + extension);
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fileName = fixedPrefix + i.toString();
i++;

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
oldFileExist = false;
}
}

fileName = fileName + extenstion; //fileName now should be like myFile1.txt

//now continue to create a file with fileName as name, then write to it as normal

BufferedWriter fileBuff = new BufferedWriter(new FileWriter(fileName , false));
//write your content here
//bla bla
//.....

fileBuff.close()

Categories: Programming

awesome SVN branching in Eclipse

March 14, 2011 Leave a comment

Exactly what official eclipse manual is missing

http://www.saltycrane.com/blog/2007/03/how-to-setup-subclipse-project-to/

ideas Mar 07

March 7, 2011 Leave a comment

07/03:

State:

  1. Green, car start moving, leading part of the queue  with speed significantly > 0, trailing part still 0
  2. Green, cars well into moving stage, no cars with speed = 0, we can reach this stage without previous green stage (new oncoming cars hit green light timely)
  3. Green, but green is about to expire soon, and cars going to make stops (the closest cars will hit the red light)
  4. Red, new red, with a bunch of cars coming (cars still moving, and making stops soon)
  5. Red, well into red, with leading part queuing, later part still moving
  6. Red, all cars stopped.
  7. Red, but red going to expire, some coming cars don’t have to stop.

Some thoughts: to capture case 1 and 2, just use car features (with corresponding weight components of weight vector): moving queue, still queue. Again, to capture cases 4, 5, 6, just need moving queue and still queue.

Case 3, case 7: do I need more feature for it?

Categories: Daily ideas

password-less ssh login

January 9, 2011 Leave a comment

- On local machine, generate key pairs by

ssh-keygen

follow the prompt, enter nothing as password, a pair of key files (id_rsa, id_rsa.pub) is generated in folder .ssh

- Copy the file .ssh/id_rsa.pub to the .ssh folder as new name “authourized_keys” via scp, command as below:

scp .ssh/id_rsa.pub user@host.com:~/.ssh/authorized_keys

That’s it!

 

Categories: Uncategorized

How to use 3G Internet in Vietnam

July 23, 2010 Leave a comment

Hey,

From my travel experience, Internet is really saving awkward foreign travellers bunch of hassle. So, here come the time-saving tips on how to use Internet on your smart phones (iPhone, Blackberry, any phone that have 3G function works).

Step 1:

Once you arrive in Vietnam, find any phone-card shop (wherever you see a sign listing all kinds of carriers’ names, must be it). Ask for Vinaphone SIM pack. The credit you get on the first charging is always at least double, sometimes triple the amount you pay. Depending on your stay, pick suitable kit. As of July 2010, for a week, I suggest the 180,000VND (which get you 360,000 VND credit). More on SIM pack tip later, at the footnote.

Step 2:

Compose a message with content “GPRS ON” (without the quote), send to 333 or 888.

Step 3:

Compose a message to send to 888, with content as listed down here, according to your usage

SMS content Price Bandwidth
M10 ON 10,000 VND/30 days 10 Mb
M25 ON 25,000 VND/30 days 35 Mb
M50 ON 50,000 VND/30 days 100 Mb
U1 ON 12,000 VND/days unlimited
U7 ON 80,000 VND/days unlimited
U30 ON 300,000 VND/30 days unlimited
That’s it! Enjoy Internet on the go!
Note on SIM: As mentioned above, first charging will get you double/triple credit, unfortunately it doesn’t apply to recharge. So if you don’t really care about your phone number, after using up credit, just ditch your SIM and buy a new one.

Categories: Travel

Hello world!

July 23, 2010 1 comment

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.