Sunday, October 20, 2013

My First Javascript Game - Constructing the Turn

In order to have any game run smoothly a you have to build in a flow, an ordered structure to the turn. Building this up for Chinchirorin was certainly not as straight forward as I thought it would be. The only thing more complex than getting the game to proceed in a logical manner for the player (also meaning in a way that they could track) was getting the scoring built in. The two tasks are closely related as it is possible for both the house and player to score automatic wins and losses on their respective turns. I chose to construct both the player and house turns seperately. Though given their similarity this was mostly a choice made to allow my own tracking of the programming to be simplified.

 

function houseturn ()

{stage=2;

score=0;

housescore=0;

winlose="undecided";

triples="undecided";

doubles="undecided";

yourscore=0;

rolldice ();

dieroll1.innerHTML="<p>"+die1+"</p>";

dieroll2.innerHTML="<p>"+die2+"</p>";

dieroll3.innerHTML="<p>"+die3+"</p>";

scoring ();

housescore=score;

if ((die1==4 || die2==4 || die3==4) && (die1==5 || die2==5 || die3==5) && (die1==6 || die2==6 || die3==6))

       {zelda.innerHTML="<p>4-5-6 Straight Kill Win! House Wins!</p>";}

if (triples=="yes")

       {zelda.innerHTML="<p>Leopards Win! House Wins!</p>";}

if (score==6)

       {zelda.innerHTML="<p>Big Six Win! House Wins!</p>";}

if ((die1==1 || die2==1 || die3===1) && (die1==2 || die2==2 || die3==2) && (die1==3 || die2==3 || die3==3))

       {zelda.innerHTML="<p>1-2-3 Straight Lose! You Lose!</p>";}

if (score==1)

       {zelda.innerHTML="<p>Asshole Ones! House Loses!</p>";}

if ((winlose=="undecided") && (score>0))

       {zelda.innerHTML="<p>House Scores "+housescore+", Your Turn!</p>"}

if ((winlose=="undecided") && (score==0))

       {zelda.innerHTML="<p>No Score - House Rolls Again!</p>";}

timer=setInterval(timefunction, 3000);}

 

The houseturn () function above, and playerturn () function below are pretty much identical. The only differences between them is what they set the stage to at the beginning of the turn, and in how the rolls produced during the turn affect the scoring and betting for the game. After designating the stage of the game the function sets all of the temporary score variables to zero. This is done so that previous rolls done in either past turns, or previous iterations of the current turn, can not confuse or make the scoring on the following roll incorrect. Next the dice are rolled, then scored, by calling other functions. Then there are a series of if statements measure whether roll was an automatic win are loss. If none of them apply, after that the last two if statements see whether any score was generated at all. If there was, the game precedes on to either the next turn, or comparing the two scores. If no score was generated, then the turn is repeated.

 

function playerturn ()

{stage=3;

winlose="undecided";

score=0;

triples="undecided";

doubles="undecided";

yourscore=0;

rolldice ();

dieroll1.innerHTML="<p>"+die1+"</p>";

dieroll2.innerHTML="<p>"+die2+"</p>";

dieroll3.innerHTML="<p>"+die3+"</p>";

scoring ();

yourscore=score;

if ((die1==4 || die2==4 || die3==4) && (die1==5 || die2==5 || die3==5) && (die1==6 || die2==6 || die3==6))

       {zelda.innerHTML="<p>4-5-6 Straight Kill Win! You Win!</p>";}

if (triples=="yes")

       {zelda.innerHTML="<p>Leopards Win! You Win!</p>";}

if (score==6)

       {zelda.innerHTML="<p>Big Six Win! You Win!</p>";}

if ((die1==1 || die2==1 || die3===1) && (die1==2 || die2==2 || die3==2) && (die1==3 || die2==3 || die3==3))

       {zelda.innerHTML="<p>1-2-3 Straight Lose! You Lose!</p>";}

if (score==1)

       {zelda.innerHTML="<p>Asshole Ones! House Loses!</p>";}

if ((winlose=="undecided") && (score>0))

       {zelda.innerHTML="<p>You Score: "+yourscore+"</p>"}

if ((winlose=="undecided") && (score==0))

       {zelda.innerHTML="<p>No Score - You Roll Again!</p>";}

timer=setInterval(timefunction, 3000);}

 

It became apparent to me after rhe initial programming was done, that it was quite possible for the game to generate, process, and report results, and then move on, before I could even read that it had done the first step, much less what the results had been. This was the reason that I added the timer line at the end of the player and house turns. I needed to create a function that would simply tell the game to puase, allowing the player to see what was rolled or what was scored - so that they understood what the game wanted them to do next.

 

I mentioned stages briefly earlier when describing how I set up the turns. The stage variable was meant to be a variable that the game could refer to, to let it know what part of the game it currently is running, and therefore what it needed to run next. If the timefunction is called it checks what stage the game is in, as well as ant other important parameters such as the score, and tells the game which function to run next. I set the game up to follow these stages: 1=beginning/place initial bet, 2=houseturn, and 3=playerturn.

 

function timefunction ()

{clearInterval (timer);

if (stage==1)

       {houseturn ()} else

if (stage==2 && winlose=="undecided" && score==0)

       {houseturn ()} else

if (stage==2 && winlose=="undecided" && score>0)

       {playerturn ()} else

if ((stage==2 || stage==3) && (winlose=="win" || winlose=="lose"))

       {autoresolve ()} else

if (stage==3 && winlose=="undecided" && score>0)

       {playerturn ()} else

if (stage==3 && winlose=="undecided" && score>0)

       {comparescore ()}}

 

The last function that was put in to have directdirect bearing on the processing of the turn was the autoresolve function below. This function was designed to be called win an auotmatic win or loss condition was met in one of the turns. It would then call the appropriate end of the round win or loss resolution based on the stage it was called and the score.

 

function autoresolve ()

{if (stage==2 && winlose=="win")

       {stage=2.5;

       youlose ();}

if (stage==2 && winlose=="lose")

       {stage=2.5;

       youwin ();}

if (stage==3 && winlose=="win")

       {stage=3.5;

       youwin ();}

if (stage==3 && winlose=="lose")

       {stage=3.5;

       youlose ();}}

Friday, August 16, 2013

Javascript Game pt. 2 - Rolling the Dice

 Since this game revolves around rolling dice, that is the first thing that I needed to do. Rolling a die is in essence, a random number generation function. So I ended up with the following function:


function rolldice ()

{die1=Math.floor(Math.random ()*6+1);

dieroll1.innerHTML="<p>"+die1"<p>";

die2=Math.floor(Math.random ()*6+1);

dieroll2.innerHTML="<p>"+die2+"<p>";

die3=Math.floor(Math.random ()*6+1);

dieroll3.innerHTML="<p>"+die3+"<p>";}


Math.floor () is the Javascript round down command. Therefore Math.floor (12.6) would result in 12. Nested inside the round down command I placed the actual random generator. Math.random by itself will generate a random decimal greater than zero, but less than one, and up to 10 digits long. Therefore to turn this random generation into a method that resulted in an integer between one and six, I had to multiply the result by six, add one, and round it down – as shown above. In totality the rolldice () function showed above will obtain a random die result for three dice, and then show them in the HTML of the page.

Monday, August 12, 2013

Javascript Game pt. 1 - Defining the Variables

I have learned that the best way to learn something is to do it. Therefore in my quest to learn Javascript I set myself the task of programming a game. I based this game off of an ancient Asian dice game used to gamble, known here in America as Chinchirorin. The basic rules for this game can be found here. This really taught me a lot, especially in terms of planning out how to program something. Previous to this the program effects I was trying to accomplish through Javascript were relatively simplistic.

It turns out that the keys to successfully defining a larger Javascript project is to successfully map the functions that you'll need as well as the variables. In this particular blogpost I'm going to only review the variables that I ended up defining for this game, a list whose length surprised me. All these variables I defined in a list at the beginning of my embedded script.

var housemoney=500; (This variable is what I used to track the money held by the bank that the player could gamble against and potentially win. Though you could create the game without this variable, the game would be endless without it. I used it in the programming to track when the player has 'broke the bank' and provide a win condition to the game.)

var h0us3m0n3y=document.getElementById("housemoney"); (This variable was created to interact with the HTML of the page so that the current amount of house money could be displayed and updated.)

var yourmoney=50; (This is the variable that I used to set how much money the player had available to bet. If a player runs out of this they could lose.)

var y0urm0n3y=document.getElementById("yourmoney"); (This variable was created to interact with the HTML of the page so that the current amount of player money could be displayed and updated.)

var housescore=0; (The internal variable to define what the house scored on a given turn barring a auto-win/loss.)

var h0us3sc0r3=document.getElementById("housescore"); (This variable was created to interact with the HTML of the page so that what the house scored could be displayed and updated.)

var yourscore=0; (The internal variable to define what the player scored on a given turn barring a auto-win/loss.)

var y0ursc0r3=document.getElementById("yourscore"); (This variable was created to interact with the HTML of the page so that what the player scored could be displayed and updated.)

var score=0; (The internal variable designed to keep track of a score on a given roll. This was then reassigned to the yourscore or housescore variable as appropriate. Resets every roll.)

var yourbet=0; (The internal variable designed to keep track of what the player chose to bet on a given turn.)

var y0urb3t=document.getElementById("yourbet"); (This variable was created to interact with the HTML of the page so that what the player chose to bet could be displayed and updated.)

var housebet=0; (The internal variable designed to track the house's bet on a given turn.)

var h0us3b3t=document.getElementById("housebet"); (This variable was created to interact with the HTML of the page so that the player knew that the house always matched their bet, and the the house's bet could be displayed and updated.)

var die1=0; (The internal variable designed to keep track of the result of die rolls on the first die.)

var dieroll1=document.getElementById("die1"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the first die could be displayed and updated.)

var die2=0; (The internal variable designed to keep track of the result of die rolls on the second die.)

var dieroll2=document.getElementById("die2"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the second die could be displayed and updated.)

var die3=0; (The internal variable designed to keep track of the result of die rolls on the third die.)

var dieroll3=document.getElementById("die3"); (A variable designed to interact with the HTML of the page so that the results of the die rolls of the third die could be displayed and updated.)

var winlose="undecided"; (An internal variable designed to keep track of whether a given roll matched a automatic win or loss condition.)

var triples="undecided"; (An internal variable designed to keep track of whether the roll result was a triple.)

var doubles="undecided"; (An internal variable designed to keep track of whether the roll result was a double.)

var stage=0; (An internal variable designed to keep track of what stage the game is currently at so that the programming can implement the appropriate next functions, or wait for player input.)

var zelda=document.getElementById("zelda"); (This variable was arbitrarily named after my cat. It was created to interact with the bottom text bar of the page, and display announcements about game play as they were triggered.)


Saturday, August 10, 2013

Announcing Urban Hermit Games

Since writing last I have been focusing my efforts on a website that I have worked to help launch. As one of the founding members I will have many more interesting experiences to share with this process that I have been going through in founding this website with my partner: the Hermit. Please go and check out Urban Hermit Games! I will need to do further posts on finding and configuring a VPS, choosing your VPS OS and configuring it, learning SSH, choosing your web content management system, and then making it work. However setting up this website has been an interesting experience to say the least.

We are currently trying to set up some social media interaction and see if we can find a way to get the free SSL certificate we obtained to not slow down our site by 200%. I have also managed to program a somewhat complex if terribly ugly game. At least it functions the way its supposed to. So there is much to come on this blog! There may even be reviews for the free library-boosting utilities that I originally intended to focus this blog on soon. But please, go take a look at Urban Hermit Games!

Tuesday, July 30, 2013

Submission Experience

                So this is meant to be a review of my experiences trying to submit the websites I work on to search engines. Though I started this experiment using this blog, which is posted through the third party sites (tumblr.com, wordpress.com, and blogspot.com); I found I was unable to use my blog as a good demo for the search engine submission process. I quickly found that with the two largest search engines (Google and Bing) the way to submit your site is by using their webmaster tools, and to do this you had to be able to alter the header HTML, or create a meta-tag on the site with a specific key – or otherwise modify the site to show the specific key generated for you. This is not readily apparent or easy for you to do with these third party sites. That said there are ways. So far I have only investigated this with the wordpress.com site, but if you install certain SEO plugins they have ways through their options or setting settings menu for you to just input the key generated. The specific plugin I used was the All in One SEO Pack.
                Naver and Daum both serve as phone directories in their respective countries as well as web search engines. So the default URL submission settings include a space where you are supposed to put your phone number, and of course the country area codes are restricted to Asia. In Naver you can just leave the phone number blank and hit submit and it will process just your website. For Daum there are bubble options right before the URL submission box, start clicking them until you find the one that just shows the URL submission box, and hides the phone number box. This is the option to submit just a website; once you have the right button clicked you can submit your website.

                Qihoo 360 Search had a slightly longer form where you also had to submit your email and a captcha. Yahoo gets their search results from Bing, so your use of their webmaster tools covered Yahoo as well, they also pull their directory results from DMOZ so you can submit there to possibly be included in the Yahoo Directory. The rest of the search engines mentioned in my first post on submitting to search engines were extremely easy; basically input the URL and hit go. All told if you are already registed with a Microsoft and Google account, the whole process should take less than 25min. If you have to create new accounts for them however you could easily tack on another 15-30 minutes.

Wednesday, July 17, 2013

Submitting to Search Engines

            Part of every webmaster's job will be submitting their creations to search engines. Even if you are not a digital librarian directly responsible for submitting your library's site to search engines you may find a buried treasure on the internet that you wish was a whole lot easier to find than it turned out to be. Many librarians then feel this mild case of OCD trying to understand if there is some form of corrective indexing or cataloging you can do to help others more easily find this information in the future. Well yes there is, you can submit these hidden websites to search engines. I found myself wishing that I had thought, or been told to, do this simple step with some of my library class projects.

Submitting a site to a search engine is about more than finding that site. If you prepare a site well enough before submission your site can be listed in the top 10 search results for your relevant keywords – this has become the best way to gain traffic to your sit; beating out some of the classics such as banner advertising.

There are several apparent ways to achieve comprehensive URL submission after first googling the problem. There are a myriad of websites out there, including a good many free ones, which will do this for you. They will submit your site from anywhere from 10-400 search engines. Sounds awesome right? Not really, first of all when looking through these you rarely learned all of the search engines that you would be submitting to. Secondly, these sites did not usually specify how they were submitting your site (many search engines will only take certain kinds of submissions) so there was no way of checking to see if your site was being submitted in a way that actually worked. Finally, many of these sites attempt to submit your site over and over again. This is called spamming your site, and actually gets it blocked or ranked lower in many search engines. Once again it is difficult if not impossible to tell which submission service do this, and which do not. So like many things in life, it turns out that if you want to do this properly, you ought to do it yourself.

Whenever I have read about site submission previously, it has always been written about hand in hand with SEO, or search engine optimization. If you don't know what this is, it is the idea of promoting your site by having it appear near, if not at, the top of the results list when someone types in a relevant search query. It is true that submitting your site is the final step of the SEO process (likely why it is mentioned there), but this process is only something that can really be controlled if you have access to your website's base HTML code. People who have used turnkey solutions, blogs, or have some other sort of preformatted web site you want to submit not have the ability to affect this process in the traditional way. However you may have something in your authoring or control panel that will allow you do things like choose your keywords for your articles – this does filter down into SEO. The main point here though is that I had thought that I would need the traditional information compiled for SEO in order to submit my site. This is not true, you only need your site's URL, and to occasionally prove you are not a robot.

             So now you're ready to submit to search engines, but which search engines do you want to submit to, and how many are you going to submit to? Part of this answer is obvious. If you only want to submit to one engine, by far the most popular search engine in the world is Google. So if nothing else you should submit here. The next question to ask is how global you want your website to be. It is true that Google by itself takes care of the majority of that too; however there are certain countries where Google is not the top search engine. These are: Yahoo! (Japan), Baidu (China), Yandex (Russia), Naver (South Korea), and Seznam (Czech Republic). Next you may want to consider including the runner-ups in your list as well, after all if you include Yahoo! and Bing, you already have the majority of that list covered. There were several search engines that were originally on my list which I ended up excluding because they either: directly used the search results of another search engine already on my list, or did not accept URL submissions at all- they get all of their data directly from their crawling bots. The only way to get included on the latter type of search engines is to ensure that other sites have links that will lead them to your site. Perhaps the best way to do this is to create social media splash pages, or a Wikipedia entry. After all is said and done I ended up with the list below.

 

           

·         BaiduBaidu Submit

·         BingBing Submit

·         DaumDaum Submit

·         DMOZ Open Directory ProjectDMOZ Submit*

·         GoogleGoogle Submit

·         NaverNaver Submit

·         SeznamSeznam Submit

·         Qihoo 360 SearchQihoo 360 Search Submit

·         Yahoo! - Yahoo! Submit

·         YandexYandex Submit

 

*Unlike the other links this is not the actual submission page, but the submission guidelines and instruction page. To submit properly on DMOZ you have to go directly to the most appropriate category for your page to be filed under and then click on the submit URL link at the bottom of that category's page. 

Wednesday, June 26, 2013

My Second JavaScript

                So I have now completed my second JavaScript exercise, short, sweet, and right below:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Second Javascript Lesson</title>

</head>

<body>

<script>

function relister ()

{var text = document.getElementById('text').value;

var count = document.getElementById('count').value;

var zelda = document.getElementById('zelda');

while (count>0)

{zelda.innerHTML=zelda.innerHTML+"<p>"+text+"</p>";

count=count-1}}

</script>

<form>

Text: <input type="text" name="text" id="text" /><br>

Count: <input type="text" name="count" id="count" /><br>

</form>

<button type="button" onclick="relister ()">Submit</button>

<div id="zelda">

</div>

</body>

</html>

 

                The idea with this exercise was for me to learn how to grab input for the user and then be able to manipulate it with JavaScript. So I needed to let a web-surfer enter a string or phrase, and then a number separately, and then when they hit a button this would list that phrase that number of times at the bottom of the page. I actually learned a little HTML that I didn't know before this as I had never really created any sort of form or input button just using basic HTML code before. Previously I had used a graphics editing software to make custom buttons and the like.

                To be able to pull information from a form you have to define that information as a variable.  You then set that newly defined variable=document.getElementByID('destinationID').value in order to tell your script to pull the value of that variable from the input in the form. You do have to be careful to link the form's HTML id tag inside the quotes exactly to the right variable's tag inside it's quotes and parenthesis. Then create another variable and div id tag matchup where you want to write your output text. Finally you put in the while JavaScript above the loop that actually writes the new content. The while loop will keep writing the new content until the count hits zero, and every time it writes the content the count is reduced by one. Finally by adding the new writing to the current content of the div tag we can insure the lines are repeated, rather than replaced.

Monday, June 17, 2013

My First Javascript

One thing that I have learned while on this quest is that thus far I have been a terrible project planner, likely due to my relative lack of programming experience. I wasted a large portion of the time that I had for the project attempting to find the right tools for the job, and find the right APIs. Then I spent a lot of time reading about what to do and attempting to dive in the deep end of what I finally determined to be the right code. What I have come to realize is that this is really putting the cart before the horse. I was focusing on getting the website up and running in what I, at the time, thought was the most direct method possible. What I lost sight of was that the entire point of the exercise was to improve my skills, and ultimately, learn how to program.
It took me entirely too long to determine which tools to use, that stemmed from my general unfamiliarity with web programming. I did learn how to create web pages in library school; however we were taught the basics and then given a version of Adobe Dreamweaver to learn with. Though I believe I did grasp the basics of HTML and CSS, Dreamweaver is such a powerful tool that it pretty much does all the other web programming for you. Though I used PHP and Javascript through Dreamweaver, I never really learned any of it. Once I realized that most of the API code samples that were given were given in Javascript and attempted to start to learn it I had already wasted too much time.
Then feeling the time crunch, I took the code samples that I was given in the API documentation, and simply took the code lines and started plugging them into Google. The idea was to try to understand what the individual lines meant. However all this really did was reference me back to the API documentation. I didn’t understand the code well enough to know the difference between the defined function, the function arguments, or the variables and parameters that they utilized. It is right around this time that I was brought to the realization that I was not, effectively, learning code – my actual goal from the beginning.
Coding is something that you learn by doing, by learning the most basic of commands and playing with them. Learning what breaks the code and what doesn’t. I also realized that I had a few other skills to brush up on beyond even my goal of learning and implementing a Javascript based federated search engine, if the site was going to be even remotely presentable I would need to learn the new CSS3 formatting in order to make the search and results presentable. Therefore, in order to get back to the purpose – I reprioritized.
I found a very basic, but great, Javascript tutorial that I have started working through. I wrote the following, in attempting to learn some of the basics of Javascript.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Nich's first Javascript Lesson</title>
</head>
<body>
<p onclick="alertbox ()">This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text. This is sample text.</p>
<script>
var x=0
</script>
<script type="text/javascript">
function alertbox ()
{x=x+1
       if (x<5)
       alert ("You clicked the sample text "+x+" time(s)! ("+y+")")}
</script>

</body>
</html>

With this script I learned how to call Javascript functions with HTML, and how to build a basic function that utilizes variables and limitations. You can attach onclick="alertbox ()" to any HTML element. This means that whenever that element is clicked that function will happen. This little bit of script defined a variable:

<script>
var x=0
</script>

I then used that variable in the script alert text: ("You clicked the sample text "+x+" time(s)! ("+y+")") to ensure that x is treated as the variable, and not just another letter in the string you use the + signs and quotations marks to separate out the string and let it know how to include the variable. However to get it to actually display the correct number you need to add x=x+1 at the very beginning of the function. The last thing that I played with today is beginning to use conditional statement. By putting in if (x<5) I made it so that the alert box only pops up the first four times that you click on the text.
       I am going to prep my application materials next. I intend to submit them immediately as is only linking to this blog. This way I will continue to build the website and actually learn the Javascript at a manageable rate. I still intend to build the site, and I still intend to learn Javascript and through that become more familiar with programming itself. However by submitting my materials immediately without the site I will approximately the same chance at getting the jobs and really be able to focus on the entire point of this exercise – self-improvement.

Tuesday, June 11, 2013

Dream Job Longshot - Course Re-evaluation

So here I am, very impressed with Drupal and reading an awesome book about it and I finally realize the obvious. For the purpose of my two-page demo site, using Drupal is the equivalent of getting yourself a pool with a wave machine in order to splash water on your face. Drupal is definitely still on my to-do list. I’m making it a personal goal to learn Drupal and hopefully work on a Drupal mod, scheme, or program that will allow libraries to start utilizing Drupal the way Openscholar has helped universities. I’d like to help libraries tie their easily configurable Drupal sites into their catalogs, federated searches, and library user info in a way that will allow small local libraries or community college libraries to expand their sites beyond the common where we are/policies/search our catalog sites that they have now.
However all those big dreams are not relevant to my current goal. The two obvious first steps to my goal are going to be to download and start using a free web editing software, and to find all the free search APIs that I can, sign up for them if need be, and start poring over the code examples to figure out how I can integrate as many of them as possible into one search box interface. I will need a CSS page to help standardize, theme, and define my whole site, at least two – likely three HTML pages, and an unknown number of PHP pages to make the scripting work.
Based on the recommendation of my partner I selected Eclipse. Understanding everything the Eclipse Foundation does would be well beyond me, but to sum quickly as I understand it is that they provide free runtime writing and testing environments for all kinds of code or programming infrastructures. Though it took a separate web search to understand this, I just wanted their web development platform. This was hidden inside a larger bundle of platforms which is why it wasn't immediately apparent, but I soon found and downloaded the Eclipse IDE for Java EE Developers. To complete this I just went to the Eclipse Downloads page, made sure I had the right OS in their drop-down menu, and then selected the right version for my computer. I made sure by right-clicking the computers tab from my windows tab and matching what I saw on the screen there. You then pick a download mirror and get your download, which of course came zipped. To unzip it I went and downloaded 7zip, a free and open-source file extraction program. Then I installed Eclipse, created a new dynamic web project – and I was off and running.
However having a use-able tool to create my website was only the barest beginnings of a first step. I needed to locate free search API utilities on the internet. There are many existing sites that already exist that already do what I am doing such as metacrawler.com and dogpile.com. I found this encouraging, as the blatant existence of these sites meant that what I was attempting to do is neither illegal nor discouraged by the builders of the search APIs. It meant that I would not likely be violating any API agreements. However I still intend to review these carefully as I build up my interface.
So what did I find out there when I started exploring freely accessible search APIs? Well I have to admit I was rather surprised. Only two of three commonly used APIs for the previously mentioned federated search sites are actually free. It turns out that Yahoo! no longer offers a free search API. I will admit that the pricing is cheap in the order of dimes on the dollar per 1000 queries per type (i.e. web, image, etc.) of queries that you do per day. What Yahoo! offers now is Yahoo! Boss Search, and though it appears to be a solid and reasonably priced product; it does not fit into my overall budget (of $0).
Next I researched Google’s API, the original Google search API had been deprecated meaning that Google no longer offers it for development and points everyone towards Google Custom Search API.  After you login to Google with a Google account setting up a Google Custom Search is the easiest I've seen yet. Though this search API is obviously intended to search a specific site for you, I found easy directions  provided by Google to tweak this to whole internet searches. After having tweaked these instructions and played around with the features it is easy to get code samples and an API key. So at this point I moved on to find more accessible search APIs to integrate.
The next place I ended up at was Bing. Bing is the other large search engine that is somewhat famous in America as it is the one developed by MicrosoftBing does have a free to use basic search API, their Bing API has extensive documentation on its implementation. All I had to do to get access to this one was sign up for a Microsoft Account and sign up to use the API on their Azure Marketplace.

I found three other free APIs which I will continue to look into tomorrow. They are the Faroo Free API, the Entireweb Search API, and the Yandex API. Not all of these may prove useable, or useable all at once like I hope. To be continued.

Monday, June 10, 2013

Dream Job Longshot – 1rst Weekend Recap

Being something of a bibliophile, as I expect all librarians at heart are, instead of immediately finding and installing Drupal like a promised myself I would do. I instead went out and starting reading a book about it. There are many Drupal books out there, however the one that I ended up using was The Definitive Guide to Drupal 7. If I was going to invest the time into  learning this I wanted to make sure it would actually help me achieve my goal. The best way to start that is by learning exactly what Drupal is, and if this would help me with my target goals.
Drupal is a content management system. Drupal is written in PHP and Javascript (using Jquery). Drupal uses databases on the web servers (either, MariaDB, MySQL, or PostgreSQL). The point of using Drupal instead of developing these things yourself from the ground up is because Drupal is an open source system. It saves the web developer (me in this case) from having to figure out the programming from the ground up. It could also accelerate my learning curve. By using Drupal I can figure out which pieces I need and why, and then go look at their core programming to learn exactly how the PHP I desired works, instead of having to figure this out the hard way.
Unlike other content management systems such as Wordpress, which is very focused on blogs, Drupal is designed to be highly diverse, extensible, and scalable. It is literally designed to be able to handle all types of websites from e-merchants to (and this surprised me) the White House website.
Drupal is an application framework. This means that it is designed to be a platform for developing serious web applications. It is meant to handle multiple APIs well. Since it is an application framework it can be used as the basis for a variety of apps, from smartphone to Facebook. It can also be found in non-CMS roles such as the front end of Java-based apps or as the back end for AJAX or Flash. An example of this that I found personally interesting was OpenScholar – a Drupal based website creation and hosting program that was designed to allow Academic Institutions to host an unlimited number of Academic websites. It allows professors and students to create those websites with no knowledge of programming or HTML. This includes being able to manage their own dynamic content, publications, events, blogs, classes, themes, and even online collaborations.
Drupal supports RDF. I first came across RDF when it was mentioned as an aside in my cataloging course, and then more thoroughly in my metadata course. RDF is a very simple ‘triple’ framework, where ‘thing A/has property/value” so one common triple would be “ebook 1/has author/john smith”. RDF is a core component of the semantic web, the idea that becomes embodied with interactive API frameworks such as Drupal which can use these assigned properties to pull and interact with the data as the various API interfaces, or programs talk to each other; speaking in either SOAP or REST, the ‘languages’ that I discovered on Friday.

The final straw that convinced me that Drupal is the key that I want to use to try and unlock my dream job was the fact that one of the modules of Drupal (a Drupal module is a bit of extensible code that has already been made and released to the open source community that can add extra features or depth to your website) is an Apache Solr search function module. Solr familiarity and working knowledge was mentioned as a desirable quality on my dream job listing; and though I don’t know much about it yet – this is the first real lead I have had! My plans for tomorrow include: continue reading up on Drupal, try to design a wireframe for my demo site, and try to start determining which modules and content I wish use in my design.

Friday, June 7, 2013

Dream Job Longshot - Recap Day 1

Today I spent designing a project that I would be able to work on and then display online that would help prove my “Ability to lean new technical skills quickly; ability to meet deadlines; strong service orientation.” I hoped to do this in such a way that it would tie in many of my other missing desired skills in a neat little bundle. For my project I decided to try and build a search aggregator, otherwise known as a federated search engine for the web, by integrating their multiple APIs using RESTful xhtml and hopefully one of those “object oriented languages (Ruby, Python, PHP, etc.)” thereby tying together a very handy demo of my job suitability. Loaded with optimism I began to search the internet for how to best do this, not knowing I was in for hours of frustration. What I did not realize is that as a university student I was spoiled. I had always had the exact steps laid out for me to be able to achieve my assignments. Back then all I had to do was follow that path laid out for me and then add a creative twist in order to excel. Here I felt blocked at every turn.

I though to start by looking at Google's API. Not only does Google have the honor of being THE major search engine on the web nowadays, but I know that they post their APIs and have specific instructions on how to use them in order to encourage programmers to build with them. What I found however was not encouraging. I did quickly find a comprehensive list of APIs that Google offerred in their APIs interface. However I couldn't but help notice that a full-fledged Google Search was not among them. It also occurred to me that I had developed this plan without fully knowing what an API was.

An API stands for Application Programming Interface, and I found the following handy definition:

(Application Programming Interface) A language and message format used by an application program to communicate with the operating system or some other control program such as a database management system (DBMS) or communications protocol. APIs are implemented by writing function calls in the program, which provide the linkage to the required subroutine for execution. Thus, an API implies that a driver or program module is available in the computer to perform the operation or that software must be linked into the existing program to perform the tasks.PC Magazine Encyclopedia - API

So plugging in an API into a webpage was basically like outsourcing a specific part of the function in that webpage that you wanted to implement. Thinking back on this I realized that we had in fact learned about this in library school! I may have never had heard of the term API before, but we had talked about the the increasing functionality of XHTML over basic HTML and how the idea of having cross-program functionality would greatly increase the utility and capabilities of the web.

Turns out, this is also connected to RESTful infrastructure that was also mentioned in by my dream job. Yet once again I was discovering that I was unfamiliar with terminology, even if I was aware of concepts.

SOAP – is the acronym for Simple Object Access Protocol, which to remove the computer geekness and IT terms from the definition – is basically the universal language for computers. It is what a windows computer will send to a linux server to ask it for information and be understood. Technically SOAP refers to the tiny information packets or messages that are sent between machines in order for them to communicate. -Techterms.com – SOAP

REST – is the acronym for Representational State Transfer, is a similar universal language for computers. However unlike SOAP it is also an architecture for computer websites as well as a language. Confused? I was! Sites that implement REST are termed RESTful systems. RESTful systems have URI or Universal Resource Identifiers attached to everything. These identifiers are in practice URLs, however instead of just having them attached to each page, they are also attached to things like users, database objects, transactions, etc.. REST also has a few other building blocks: it assumes that there is a client (i.e. you on your local computer through the website designed with REST) and a server (obviously a RESTful system), each client request is individually generated with all necessary data and using the basic REST commands the server responds statelessly (meaning without storing any data regarding the request on the server), every request will be designated on the client's side as cachable (or not) which will tell the clients computer whether or not to store the results (results could be stored for faster future processing, or not to ensure that old data is not inappropriately used or submitted), and finally that there are several communication layers in REST, the client computer, client web-browser page, the server response system, and all the data within the server itself. This allows for servers to scale what the house dynamically and appropriately. -techopedia REST

I found a good article the compares REST and SOAP called "Knowing when to REST". This article was very good at describing the difference between the two systems and which would be appropriate to use when. What this boiled down to is that if the website is providing a service based activity through its website, such as a merchant or calender, then SOAP is likely the better choice as it provides solid best practice standards in reliability and security where REST does not. (REST still can be secure, but every case has to be judged individually – there is no 'best practice'.) Whereas if the site is providing a resource, such as a digital library, search engine, or typical news site, then REST makes more sense to use.

To go back to my previous thought, REST or SOAP are related to being able to use APIs in your site because they will need one or the other in order to communicate their interactive data successfully. Which to use in a given scenario is often chosen for you based on the server requirements or API requirements in a given scenario as I discovered “SOAP vs REST API Implentation” by FliquidStudios.

Going back to my original frustration it looked like the API that Google offered for free was really only designed to search specific sites and had a limited number of uses per day. Well its not like I ever expected to exceed the limited number of uses per day, but I didn't want to just search specific sites, I wanted to do a whole-internet Google Search, and that was just for starters!

Then while poking around I found some interesting leads on how to do this theoretically with RSS feeds. Now as far as I knew, RSS feeds were information streams that you could hook your email/mobile app platform/whatever into to get constant updates on whatever topic the RSS feed was designed to cover – so how could you use it to write help plug into a search engine? Admittedly the page that claimed this was a Wikipedia page on Search Aggregation, and as a trained librarian I know full well that those are not always accurate, especially the ones that claimed to have issues like this one did. However I also knew that this was due some further investigation.


While looking around for this I stumbled across the website Wopular. I was excited by this discovery because this site appears to have achieved tangentially on a large scale what I will be trying to do on a small one. I also found this neat article describing how and why the site was designed the way it was. So my goal for tomorrow: download a localhost version of Drupal in order to start playing with it, perhaps this can count as my web-oriented programming language!