Thursday, May 2, 2013

Bookmarklet Storage Application

A couple days ago, I was growing frustrated with how tedious bookmarking had become. Whenever I wanted to bookmark a website I would save it, however I never got to use the link if I was on another computer. The method I used before was to save the link in Gmail and that is quite tedious. I decided I wanted to write a small application for myself that would save my links online.

Bookmarking on the web is nothing new. Sites like Instapaper and Delicious use a bookmarklet to run javascript that sends information to the servers in order to save information about the web site and the contents.

A bookmarklet runs javascript through the click of a bookmark on the browser. Using your favorite browser, you first create a bookmark and enter the name. On the second field where you would usually enter the URL, the code for your javascript behavior would be inserted instead. It would look something like this.

javascript: alert('hello');

Whenever you clicked on the bookmark you would then receive an alert saying hello. The real use in this is that you can grab information from the page you are currently on and do something with it.

In this case, I wanted to save the URL of the website and be able to go back to it later on any computer rather than just one machine.

Here where I had to figure out the work flow and also how application would be used.

1. Go to a web page.
2. Click on the bookmarklet.
3. Save the URL to a server.
4. Login to my database of links and view the URLs.

First going to a web page is not a problem. At this point javascript is enabled in most web browsers, so bookmarklets should work in most web browsers as well. Therefore steps one and two are pretty straight forward. Now I just needed the correct actions in javascript to send my URL to my server. After looking through some examples I figure this bit out. My javascript was something like this:

javascript:function mark(){
var prime=document,
ele=prime.createElement('script'), 
bod=prime.body,
locate=prime.location;
try{
if(!bod)throw(0); 
prime.title='-marked-'+prime.title;
}
}
mark();
void(0)

Basically I am creating a new element in the web page I am browsing. Then I set the attribute with the web page URL I grabbed along with my special code as an unique identifier. As a last step, I append the information to the page. It's the last step which enables the URL to be evaluated. Notice the '/?url=' where I set the URL of the current web page. That is the information I want to save.

Once the information has been sent to my web server, I can run a php script to save the URL to my database.


$url = $_GET['url'];
$userCode = $_GET['code'];

if ($userCode == "######") {

$host = "127.0.0.1";
$username=""; // Mysql username
$password=""; // Mysql password

$db_name="database name"; // Database name
$tbl_name="table name"; // Table name

mysql_connect($host, database username, password)or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="INSERT INTO table_links (link) VALUE ('".$url."')";
$result=mysql_query($sql);

}


In order to view the links, I created a second page that would display them using a mysql query.

And that was it. I now have a personal application that I can use to bookmark web pages. I can do that without having to register to a social media site like delicious to catalog those links.



Friday, April 19, 2013

Java terms

I am actively interviewing for technical positions and I would like to post about terms that are mentioned. These are terms that Java developers should know and I think should be able to describe and answer questions about. I was asked questions about them and I did not know about all of the terms. So this post is a warning to myself and others that these aspects of Java matter.

I will continuously update the list as I go through interviews and see what employers expect Java Developers to know.

Abstract
Interface
Object class functions
String comparison
Collection
 


Friday, February 15, 2013

Java 2-15-2013

Here's a status update on my studies. I've been using a practice exam check my aptitude after reading the study guide. I'm at chapter 3 Decision Constructs. In order to put my all into this, I have some ideas on how to do that.

  • Progress through at least one chapter a week
  • Read up on the topics discussed in the book
  • Code in Java on projects large and small
  • Read about issues in the Java programming community

Thursday, January 3, 2013

Java

I just got a Kindle for Christmas and that by far has become one of my favorite studying tools. It's super portable and lightweight. I have loaded a few texts on java to the Kindle and it works beautifully. I was also surprised at the battery life. It just goes for hours.
Now that I am focusing on Java, I also re-installed Eclipse on my laptop so I can work a project with it. I might get back into working on an Android program.