Friday, January 14, 2011

Import your Facebook events to your Google Calender

Go to your Facebook account, Go to Events, Click on Export Events -> You would get a link
Then go to your Google Calender -> Setting -> Calender Setting -> Calenders -> import calender link in the middle of the page. There you can use the Link you received from Facebook to import the events to your Google calender.

Category 5, cable standard

Category 5 cable (Cat 5) is a twisted pair high signal integrity cable type. This type of cable is used in structured cabling for computer networks such as Ethernet and ATM, and is also used to carry many other signals such as telephonyand video. Most Category 5 cables are unshielded, relying on the twisted pair design for noise rejection. Category 5 has been superseded by the Category 5e specification.


I usually use these cables in my robotic projects as well, as they come in a well packaged easy way and one can easily setup one protocol to use one color for one kind of signal :-)

Thursday, January 13, 2011

String & Javascript

String in Javascript, cool link : http://www.javascriptkit.com/javatutors/string4.shtml

Javascript, forward to another page according to the refferer URL

<!-- Hide script from old browsers<br>

if (document.referrer.indexOf("facebook") != -1)
//document.write("From facebook")
location.href = "www.yourpage.com";
else
document.write("Not from facebook so we stay on this page")
//-- Stop hiding script -->

Monday, January 10, 2011

KeyListener in Java

If you want to write a code in Java which is based on keys being pressed on keyboard, then KeyListener is your way a head. This link at Oracle.com has a very nice description of the whole class and a very good example :

http://download.oracle.com/javase/tutorial/uiswing/events/keylistener.html

Friday, January 07, 2011

HOWTO : add/remove a String Item to jComboBox, Java

jComboBox :
// Add an item to the start of the list
cb.insertItemAt("item0", 0);

// Add an item after the first item
cb.insertItemAt("item0.5", 1);

// Add an item to the end of the list
cb.addItem("item3");

// Remove first item
cb.removeItemAt(0);

// Remove the last item
cb.removeItemAt(cb.getItemCount()-1);

// Remove all items
cb.removeAllItems();

HOWTO : get a list of available ports, Java

If you want to ahve a list over all ports, the code down here can help alot
protected void list() {
// get list of ports available on this particular computer,
// by calling static method in CommPortIdentifier.
Enumeration portList = CommPortIdentifier.getPortIdentifiers();

// Process the list.
while (portList.hasMoreElements()) {
CommPortIdentifier cpi = (CommPortIdentifier) portList.nextElement();
System.out.print("Port " + cpi.getName() + " ");
if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) {
System.out.println("is a Serial Port: " + cpi);
} else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
System.out.println("is a Parallel Port: " + cpi);
} else {
System.out.println("is an Unknown Port: " + cpi);
}
}
}

Source : java2s.com, modified as javax.comm does not exist anymore on Windows and RxTx should be used

Thursday, January 06, 2011

HOWTO : The code which lets you share a link on Facebook on your website

If you want to share the link of a current page on your website or a permanent link on Facebook, you just need to do the following :

Facebook has a very good documentation on it which you can read here.

</SCRIPT> <a name="fb_share" type="button"></a> <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share"
type="text/javascript">
</script>

Result :

Wednesday, January 05, 2011

HOWTO : change the location of Desktop folder at Windwos 7

If like me you would also like to change the location of your Desktop folder(security reasons or willing to share the same Desktop on all of your computers), keep reading.


The solution is pretty simple :-) Simply go to following path : 
C:/users/name/Desktop
Then right click on the Desktop folder and then choose properties. After it click on "Location tab" and there you can change the location of the Desktop folder.


in XP, it is the same story but a little bit more complicated as you should go to registery(Start->Run->regedit) and change the value of this entry in registry : 


HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Desktop

HOWTO : insert a code in blogspot weblogs


<"border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%>

Some code here

Monday, January 03, 2011

HOWTO : Add a program to Applications Menu

In Gnome(edgy) : System -> Preferences there is an item called "Main Menu". Here you to edit the application menu.

HOWTO : Find out if you have a 64 bit Ubuntu or a 32 bit one ?

Simply open a terminal and write the following command :

uname -m
x86_64 = 64 bit
i686 = 32 bit

Sunday, January 02, 2011

Setting limitation on uploading file, PHP

You can always set limitations on the uploading process as it is a big security risk to let users upload whatever they like ...
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  }
else
  {
  echo "Invalid file";
  }
?>

More detailed types of files : 
"application/pdf" - PDF Files
"application/msword" - MS Word Files
"application/powerpoint" - MS Powerpoint Files
"application/excel" - MS Excel Files
"text/plain" - Text Files


Source : W3Schools

Uploading a file, PHP

With PHP you have the power to upload files to the server.


An example code(The client side) :
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>


In the HTML code above :

  • The enctype attribute of the tag specifies which content-type to use when submitting the form. "multipart/form-data" is used when a form requires binary data, like the contents of a file, to be uploaded
  • The type="file" attribute of the input tag specifies that the input should be processed as a file. For example, when viewed in a browser, there will be a browse-button next to the input field

****
An example for the "server side" script

The "upload_file.php" file contains the code for uploading a file:

<?php
 if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br />";
  echo "Type: " . $_FILES["file"]["type"] . "<br />";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?>



By using the global PHP $_FILES array you can upload files from a client computer to the remote server.

The first parameter is the form's input name and the second index can be either "name", "type", "size", "tmp_name" or "error". Like this:


  • $_FILES["file"]["name"] - the name of the uploaded file
  • $_FILES["file"]["type"] - the type of the uploaded file
  • $_FILES["file"]["size"] - the size in bytes of the uploaded file
  • $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server
  • $_FILES["file"]["error"] - the error code resulting from the file upload

This is a very simple way of uploading files. You better add restrictions on what the user is allowed to upload to your sever. Down here you can also see a code which saves the uploaded file to a physical place on server. If you do not save the file, the temporary file will be deleted after the script ends. It also checks if the file already exist.


<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>



Source : W3Schools