Java Get OS Name

This method returns the name of the operating system that the program is running in.

public static String getOsName() {
  String os = "";
  if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) {
    os = "windows";
  } else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) {
    os = "linux";
  } else if (System.getProperty("os.name").toLowerCase().indexOf("mac") > -1) {
    os = "mac";
  }
 
  return os;
}

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

Javascript Replace All

As I mentioned in one of my previous posts, Javascript has its own replace function that, when used many times, you would have to resort using a / slash followed by options case insensitive and/or global and enclosing them to the search keyword, some cases may not be applicable to use that function. I scoured the net and found this neat function by Dave Shuck taken from this link.

The problem that I encountered was when I used Javascript’s replace() function with a search keyword that’s dynamic. If say, I want to use a search keyword like photo1 and photo2 and photo3 and place that in a for loop, doing it like this

var str = 'this is photo1 and photo2 and photo3';
for (i=0; i<3; i++) {
  alert(str.replace(/photo?/ig, '<replaced>'));
}

Notice the question mark i placed? I also tried to use the eval() function to see if appending the variable i would make it work. It didn’t. In the end, I decided to go look for a replaceAll() function in Javascript. At least I don’t have to make one anymore he he he. Here’s the function.

function replaceAll(OldString, FindString, ReplaceString) {
  var SearchIndex = 0;
  var NewString = ""; 
  while (OldString.indexOf(FindString,SearchIndex) != -1)    {
    NewString += OldString.substring(SearchIndex,OldString.indexOf(FindString,SearchIndex));
    NewString += ReplaceString;
    SearchIndex = (OldString.indexOf(FindString,SearchIndex) + FindString.length);         
  }
  NewString += OldString.substring(SearchIndex,OldString.length);
  return NewString;
}

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

Javascript Get Value Of Selected Radio Button

A great helper function to get the value of the selected radio button. Note that radio button groups can only have one value whereas checkboxes can have multiple values. These functions are from this link.

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function
 
function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...

Sony MicroMV DCR-IP5 For Sale

Back when I bought a Sony MicroMV video camcorder, it was very expensive. It was the very first model and it boasted that it was the smallest and lightest video camcorder out. Even until now, its tape is the smallset that I have seen out there. Think of it as a miniature betamax tape. Honestly, it had been my dream to buy something expensive to serve as a remembrance of the fruits of my labor haha. The camcorder looks very chic and it works ok. The only problem was how to convert the video into a file. It comes with its own editing software but the problem is, the camcorder does not work with other video editing softwares. I don’t know why Sony did this on purpose. The program didn’t impress me. It crashed a lot of times especially since I had a slow PC back then. I only got to use my camcorder a few times, probably like 7x. If anyone is interested in buying it, let me know. I bought it at 1,500$ (75k pesos) in 2002 and had kept it since. I’m selling it at 40k including 3 miniature video tapes for recording, 5 batteries (4 brand new) and 1 tape cleaner with its accompanying cables and softwares (only for people in Cebu, Philippines). Do not fret about converting the video because now, it works well with Mac’s iMovie 08. A lot of users had posted testimonials that it is now compatible with iMovie 08 so it’s good news for all MicroMV owners. I’m not saying this is a bad model or what. I just have no use for a video camcorder and I can’t figure out why of all the things, I bought this one instead. I guess it is because I’m a sucker for tiny gadgets that are chic. If you want to buy it from me, contact me and please let me know. Thanks!

Like what you see? Buy me a cup of coffee. Or subscribe to my feeds.


(No Ratings Yet)
 Loading ...