Geekdom

Jquery click not binding to checkbox (or any other element)

Posted in Geekdom, Programing, Web Development on January 24th, 2014 by Jarred – Comments Off on Jquery click not binding to checkbox (or any other element)

I am just writing this down for the sake of my own personal sanity. I just spent way too much time trying to trouble shoot why I could not bind a click event to a checkboxes in jquery. This post here gave me a clue what I was doing wrong. If by chance you are having a similar issue make sure that the element you are trying to bind to is already created and part of the DOM or it will not work and you will be left befuddled why exactly nothing is happening (at least I was).

CSS3 Gradient Generator Tool

Posted in Geekdom, Web Development on November 6th, 2013 by Jarred – Comments Off on CSS3 Gradient Generator Tool

For my next project I am working on achieving a web 2.0 look/feel and wanted to include shadows and gradients. I came across a css gradient generator tool that I absolutely love and made my life easier so I thought I would post it here really quick. You can find it here: http://www.colorzilla.com/gradient-editor/

Combining JSON objects from the google datastore problems

Posted in Geekdom, Programing on December 10th, 2012 by Jarred – Comments Off on Combining JSON objects from the google datastore problems

So, here is the story: I have two different JSON objects stored as strings in the google app engine datastore. I have been trying to fetch both of the two JSON object in a single ajax call in an attempt to reduce the number of request made to the server which hopefully will make my application more efficient/quick. However It took me a great deal of time to figure out exactly how to merge / combine the two different JSON objects into a single object server side for ajax transfer over to the client. I kept on getting JSON validation errors even though the code looked perfectly good to me. Even worse the online JSON validators would tell me that there was an unexpected character, but they would either not tell me where it was, or the location they specified was perfectly valid JSON. So, eventually I figured out my problem (at least one of them); I was encoding (unwittingly) the objects in the datastore as UTF-8 with the “byte order mark” which was causing validation errors when I tried to merge the two object. Once I encoded the files that were creating my datastore object without the byte order mark, they successfully merged into a unified JSON object that I was able to pass via ajax and successfully parse.

In case anyone is wondering (or I have to figure out how to do it again), here is the way I combined the two python JSON objects server-side:

combinedObject = { 'obj1' : dataObj1, 'obj2' : dataObj2 }

However, for some reason (as of yet I do not fully understand) I have to call the JSON.parse on both the parent object and then child objects in order to get the objects correctly parsed into javascript.

EDIT: Another note regarding unexpected character errors when trying to parse JSON: I was pasting in formatted and what I thought was validated data from one of the many online tools, however I think I was also inadvertently pasting in hidden characters which was causing all sorts of confusion and problems. Another thing you might want to check this if you are having parsing errors.

How not to set Backbone model properties

Posted in Geekdom, Programing on November 29th, 2012 by Jarred – Comments Off on How not to set Backbone model properties

So here is another backbone.js tidbit that took me a while to figure out/understand. This may be fairly straight forward to seasoned programmers, but it really through me for a loop. If you try and set initial model (or view) properties outside of the “defaults” method you can not retrieve them using model.get(‘propertyName’). This was a point of confusion because sometimes it was working like i though it should and sometimes it did not. To further complicate things I was trying to set properties by passing them when I was instantiating the object. It took me a while to figure out what I was doing wrong.

So this is incorrect even though you can still access the object properties.


ExampleModel = Backbone.Model.extend({
propertyName: 'Some Value',
})
exampleModel = new ExampleModel ({propertyName: 'Updated Value'});
exampleModel.propertyName// 'Some Value' not 'Updated Value'

From what I understand this is the correct way to do it


ExampleModel = Backbone.Model.extend({
defaults: {
propertyName: 'Some Value',
},
})
exampleModel = new ExampleModel ({propertyName: 'Updated Value'});
exampleModel.get('propertyName') //'Updated Value'

Now that I understand the concept the documentation makes this very clear to correctly set default model properties using the defaults method.

More free animated explosions on transparent backgrounds

Posted in Geekdom, Web Development on March 2nd, 2012 by Jarred – Comments Off on More free animated explosions on transparent backgrounds

I don’t really know why or how but for some reason the single post on my blog that has received the most traffic has been my post back in 7/11 titled “free Animated explosion on transparent background. This does seem a bit strange to me as it really is not all that relevant to the keywords I am trying to target with my blog. Nonetheless, I am currently working on another HTML5 game and have some additional animated explosion sprite sheets and am going to post there here as kind of an experiment to see what happens.  You can save them by right click – save image as.

explosion with transparent background

Free animated explosion

Free animated explosion small

Free animated explosion small

I did not draw these, I simply re-sized them and removed the background. They are saved in .png format and have a transparent background making them perfect for use as a sprite sheet in a game. You are free to use them in any way you see fit. I got the original files from lostgarden.com

If you are looking for some more free animated sprite sheets I highly recommend you take a look around all the things Lostgarden has to offer. There are a lot of free to use pixel art animations including several other explosions. They do not however have transparent backgrounds so you will have to edit them out yourself.

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

 

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);
}

Hints for how to Install Adobe Photoshop 7 on Windows 7 (64-Bit)

Posted in Geekdom on February 1st, 2012 by Jarred – Comments Off on Hints for how to Install Adobe Photoshop 7 on Windows 7 (64-Bit)

Turns out installing photoshop 7 from the cd on a 64 bit windows is possible, but it is kind of buggy. Do a quick search on google and you will find it is a common problem. For a while I was stumped and had to live without my vintage photoshop, however I was finally able to get it to install. How I got it to work was I had to unhook all my monitors except my primary display, and then run the install program in compatibility mode (windows XP), and boom, it installed no problem. I don’t know if this will work for/help everyone, but prior to doing this the program would not install.

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