Subscribe to Alvin Poh's Blog by RSS reader
Subscribe to Alvin Poh's Blog by Email
Gadgets, Technology, Public speaking and IT from an undergraduate's perspective.
Running UNIX commands in your Java application
I was looking around for a method to run commands from the prompt automatically from within my Java application, and then I found it. Here’s the solution - and it works like a charm!
static void doExec1() throws IOException {
// use pipes and I/O redirection
// but without using a shellRuntime runtime = Runtime.getRuntime();
runtime.exec(”ls | wc >out1″);
}
Subscribe to my blog:
RSS reader
Email
Vbulletin Can’t Login - Solve the Login Problem
Some Vbulletin users and owners may have experienced that some users face a problem logging in, especially with Internet Explorer (IE).
Does your problem sound like this: When the user logs in, the page shows the “Thank you for logging in” message, then refreshes, and the user is shown that he is not yet logged in. No error message is shown.
Well, the following 3 steps may help in solving this Vbulletin log in problem:
- Close all open browser windows and clear all cookies. Then load your browser and try logging in again. If that does not help, continue with the next suggestions.
- Login to your Admin CP, click on “vBulletin Options” in the left frame, and then select “Cookies and HTTP Header Options”. Once there, make sure that your “Path to Save Cookies” setting is set to “/” (without the quotes). If it is not, change it to “/”, save your settings, close your browser, clear your cookies, and try logging in again. If that still does not help, continue to step #3.
- Go back to your Admin CP, click on “vBulletin Options” in the left frame, and select “Cookies and HTTP Header Options” again. Check your “Cookie Domain” setting and make sure it is set to “(blank)”. If it is not, change it to “(blank)”, save your settings, close your browser, clear your cookies, and try logging in again.
If that still does not help, or the setting is already set to “(blank)”, change the setting to “.yoursite.com” (note the 2 dots!). Save your settings, close your browser, clear your cookies, and then try logging in again.
Note: By changing your “Cookie Domain” setting, it is possible to lock yourself out of the Admin CP if this is changed to an incorrect value. If this happens, upload the tools.php script (located in the ‘do_not_upload’ folder of the vBulletin zip file) to your admincp directory. Load the file in your browser and select the option to reset the cookie domain and path back to the defaults.
Subscribe to my blog:
RSS reader
Email
Get Random Colour in PHP
Ever wanted to get random colours for your PHP scripts? This easy randomise script does just that - It randomly picks a few colours for you!
<?
//randomise the RGB colours
$r = rand(128,255);
$g = rand(128,255);
$b = rand(128,255);
//sets the colour code in 000000 format
$colour = dechex($r) . dechex($g) . dechex($b);
?>
That’s it! Then just use $colour in your PHP code. The dechex() method just converts the number to the hexadecimal format that you need.
I used half the colour spectrum (from 128 to 255) so that only the brighter colours will be generated. If you’d prefer, you can use the full spectrum (from 0 to 255) or the darker spectrum (from 0 to 128).
Have fun!
Subscribe to my blog:
RSS reader
Email
Replace/remove character in a String
To replace all occurences of a given character :
String.replaceAll("n", ""); // Remove all n
String.replaceAll("n", "r"); // Replace n by r
To replace a character at a specified position :
public static String replaceCharAt(String s, int pos, char c) {
return s.substring(0,pos) + c + s.substring(pos+1);
}
To remove a character :
public static String removeChar(String s, char c) {
String r = "";
for (int i = 0; i < s.length(); i ++) {
if (s.charAt(i) != c) r += s.charAt(i);
}
return r;
}
To remove a character at a specified position:
public static String removeCharAt(String s, int pos) {
return s.substring(0,pos)+s.substring(pos+1);
}
Subscribe to my blog:
RSS reader
Email
03 Jul 07 | 


