Web Development

JavaScript to Calculate the angle between two points in degrees

Posted in Geekdom, Programing, Web Development on February 19th, 2012 by Jarred – Comments Off on JavaScript to Calculate the angle between two points in degrees

Quick little snippet here for later reference (Yeah this one took me a bit to figure out).  The below function will return the angle between two points and return it in degrees from 0-360.

 

 

		function calcAngle(x1, x2, y1, y2)
		{
		calcAngle = Math.atan2(x1-x2,y1-y2)*(180/Math.PI);	
		if(calcAngle < 0)	
		calcAngle = Math.abs(calcAngle);
		else
		calcAngle = 360 - calcAngle;		
		return calcAngle;
		}

 

 

Sources http://board.flashkit.com/board/showthread.php?t=778094

 

HTML5 Game Portal Completed

Posted in Entrepreneurship, Web Development on February 16th, 2012 by Jarred – 1 Comment

At long last I have finally finished my HTML5 game portal. You can find it here. I have been working on it for about 8 or 9 months and I think it is finally ready to go! I included a unique ranking system that hopefully will improve the user experience. This is the first website that I have done that is data base driven, so it took me a bit longer to figure that out. I am hoping that it will be a good way to promote my future HTML5 games. If you are trying to promote an HTML5 game, please visit the site and submit your game

Universal AJAX function

Posted in Geekdom, Programing, Web Development on February 13th, 2012 by Jarred – 1 Comment

Here is my universal AJAX function. I am posting it here for reference. Over the months I have adapted/revised this function and now have finally gotten it to do pretty much what I want it. I did not write all of this myself I pulled most of it off of somewhere, but I can not remember so I can not give proper credit. Let me know if you have any suggestions on how to improve it.

 

// ******************************************************
// Universal Ajax Function
// Useage Example:  universalAJAX('http://url.com', "var1=true&var2=false", functionWhenDone, functionWhenWaiting, functionWhenFail);
// ******************************************************

function universalAJAX(URL, DataToSend, doneFunction, waitingFunction, errorFunction)
{

var json_http;
if (window.XMLHttpRequest)
{json_http=new XMLHttpRequest();}
else
{json_http=new ActiveXObject("Microsoft.XMLHTTP");}

json_http.onreadystatechange=function()
 {
   if (json_http.readyState==1)
    {waitingFunction();}
  if (json_http.readyState==4 && json_http.status==200)
    {
	if (json_http.status==200)
		{
		doneFunction(json_http.responseText);
		clearTimeout(timeOutVarCancel);
		}
	else
		{
		errorFunction();
		clearTimeout(timeOutVarCancel);
		}
	}
}

  json_http.open("POST",URL,true);
  json_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
  json_http.send(DataToSend);

  var timeOutVarCancel=setTimeout(errorFunction,10000);
}

Iterating through properties of a JavaScript Object with the “For In” loop

Posted in Geekdom, Programing, Web Development on January 16th, 2012 by Jarred – Comments Off on Iterating through properties of a JavaScript Object with the “For In” loop

As I have mentioned before I am a novice self taught programmer and I often come across little problems that take me quite a while to figure them out. I like to post them here so I can come back and remember how I solved the problem and also so hopefully others can benefit from my struggles. I came access one of these said problems this weekend trying to iterate through a object in JavaScript using a “for in” loop. I understood the looping mechanism quite well, however getting the syntax to work for me through me for a loop.

 

Incorrect (This is how I would assume it would work)

 for (var x in someObject.someProperty)

{
newVar = someObject.someProperty.x.anotherProperty;
}

This is how I got it to work

 for (var x in someObject.someProperty)

{
newVar = someObject.someProperty[x].anotherProperty;
}

You will notice you cant use .x to access the property the loop is currently processing,  you must use the [x] In truth I do not understand why this is so if anybody out there cares to enlighten me that would be appreciated. Either way hopefully this might save some frustration.

PHP code snippet to put mySQL query results into a 2 dimensional array

Posted in Geekdom, Programing, Web Development on December 16th, 2011 by Jarred – Comments Off on PHP code snippet to put mySQL query results into a 2 dimensional array

More often then not when I am are working with a mySQL database using PHP I want to put my results into a 2 dimensional array. A while back I found a snippet of code that very effectively does this. However, I am constantly digging through old projects trying to remember/find the piece the code that does this, So I figured I would post it here for reference. The code is only one line and will put the results of a mySQL query ($mySQLresults) into a 2 dimensional array.

 

while(($resultArray[] = @mysql_fetch_assoc($mySQLresults)) || array_pop($resultArray));

 

 

 

Source http://php.net/manual/en/function.mysql-fetch-assoc.php

Free 2 Column Webpage Template with Sticky Footer

Posted in Programing, Web Development on November 25th, 2011 by Jarred – Comments Off on Free 2 Column Webpage Template with Sticky Footer

Here is my first installment for my recent “Do more, Write Less” initiative I started for myself. I find myself constantly rewriting the same basic building blocks for my webpages and figure its about time to create a template that I can reuse to save myself time. I will post my code snippits here to not only archive them for my own use but also provided them to my visitors for free to try and help attract more traffic to my blog.

This is a free template for a webpage with a two column layout with a header and footer. This layout is very common and is used widely on the web. The template is just a basic building block for a web page and can be customized to however you see fit. One of the trickier things I find myself having to figure out over and over again is the sticky footer. This has also been included in the template and should work in all browsers. I have also included the basic template for the CSS which should probably be pasted into an external style sheet for bigger sites.  This template is free to use in any way you like and can be used for personal, commercial, or any other type of project.  Let me know if you find anything that does not work. Right click on the link below to download the free template (You may have to view source and then copy/past the HTML into a new file if your browser will not download the HTML file).

Free Website Template 2 Columns with Sticky Footer

Sources: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/

 

 

Do more – Write less

Posted in Geekdom, Web Development on November 21st, 2011 by Jarred – Comments Off on Do more – Write less

Something occurred to me today that is likely quite obvious to seasoned professionals but I really never gave it much thought. Over the past few years I have started numerous website projects. They usually are a significant undertaking and require lots of time to complete(seems like I rarely finish them). The thing I realized is that on each one I always start from scratch. When I have an idea to make a website I will create a brand new text document and start from building from there. I never save a template or code snippets to reuse. I have to reinvent the wheel every time and it is taking me a lot of time.

My Idea is that I need to start reusing some of my code and writing/developing it in such a way that my work can be useful for other projects. I think it may take a bit more effort initially to do this, however in the long run it could save me countless hours. I am positive that as soon as my current project is completed (hopefully I will finish it someday)I will just come up with yet another one to start. If I already have some of the building blocks ready to go this greatly increase the odds of me finishing and decrease the amount of time it will take. In the end I hope this will enhance my ability to monetize my various online efforts. I think the best place to archive some of these snippets is right here on my blog. I am almost positive that closely follows this blog yet, but if there is or when you do come (hopefully) you can expect to see some of my templates and code snippets coming. Best of all is I intend to release them all free to use for any reason.

Attempting to Monetize a Personal Blog

Posted in Entrepreneurship, Web Development on September 29th, 2011 by Jarred – Comments Off on Attempting to Monetize a Personal Blog

For the past month I have been on a cross country road trip living it up with my wife. Our road trip so far has taken us across most of the United States and now we are almost to Maine. We plan on living on the road for another couple of months or so. It really has been a wicked awesome good time. We have both spent a lot of time creating a blog of our experience (you can find it here Road Trip Blog). I decided that it might be worth it to try to monetize the blog to see what happens. The blog is a little more personal in nature and so far pretty much only family and friends have visited it, but I see potential that it might be something interesting to a broader audience. In an effort to help make it appeal to more than just family and friends we are adding a few categories full of more general posts about road trips including tips, tricks, economics, and ideas that we are learning from our time out on the road. I figure we are already spending the time making the blog, and we don’t mind making it public so why not try and make some money off of it. I am not sure if monetizing a project like this will be very successful or not, and I don’t plan on spending much time promoting it, but I really don’t have much to lose so why not try.

As of yet I have no advertising on the blog but I will try and get this set up before the end of the month. We already have quite a few visits from family and friends and am toying with the idea that possibly monetizing this traffic alone may be enough to fetch a few bucks a month. It will be interesting to see if it works.

Remove Extra Line after Smiley Faces in WordPress

Posted in Geekdom, Web Development on September 24th, 2011 by Jarred – Comments Off on Remove Extra Line after Smiley Faces in WordPress

So I noticed in one of the wordpress blogs I am working on that while the emoticon (smiley faces) I was using were properly being converted into images, they all had an extra line spacing after all of them. Needless to say this was quite annoying and screwed up the paragraphs in my posts. Getting rid of the extra spacing around the smiles was quite easy once I knew the correct search terms (display emoticon inline). After a bit of digging and fooling around with the styles in chromes Developer Tools I figured out my smiles were inheriting the “display: block” from another class. To solve the problem I included the following line into the style sheets and all the extra spacing was removed.

img.wp-smiley {display: inline;}

Source: http://lorelle.wordpress.com/2007/09/30/the-art-of-smilies-in-wordpress-blogs/

PR from 2 to 0 (box grayed out)

Posted in Geekdom, Web Development on September 20th, 2011 by Jarred – Comments Off on PR from 2 to 0 (box grayed out)

So, I used my old domain names (Infobrink.com) for this blog in hopes that the then existing PR (2) and back-links would help jump-start my blog and put me on the fast track for monetization.  However I am beginning to wonder it that was the best move as google has taken away my PR.  Looks like I should have just used a new domain name.  Seems like google is able to detect when a new site is put up over an old one and voids out all the current rankings (which is quite understandable).

The google toolbar (Which used to say 2) now only shows a 0 Page Rank (grayed out “current page is not ranked by google”). Bummer!!! I am not quite sure what this means, or when it started.  I did switch the preferred domain to the non www version in the google webmaster tools which may have something to do with it…

Guess I will just wait and see what happens during the next PR update.