Category Archives: Uncategorized

Is it Raining?

It’s Fall in the Northwest and the rain is here. I want to query the Open Weather API and see if it is raining outside since I have no windows at work and this will be my window to the outside.

function getTemp() {
    $.getJSON("http://api.openweathermap.org/data/2.5/weather?q=seattle,usa&units=imperial&APPID=YOURAPPID", function(data) {
		var weather= data.weather,
		rain =  weather[0].main;
		weather_description =  weather[0].description;
		if(rain =='Rain'){
			rain = 'Yes';
		}else{
			rain = 'No, but it\'s ' + weather_description;
		}
		$('#rain').html(rain);
    });
    setTimeout("getTemp()",600000);
}

Is it Raining?

JSON

JavaScript Object Notation or JSON for short. JSON is smaller than xml and faster and easier to parse. Parsing JSON can be done with .getJSON

$getJSON("path to the json file",function (data)){
 // do something
}

I have used JSON to create slideshows and its good to use because if you a slideshow with multiple images the json file can be called as the image is requested. I would not use this unless your image request is more than a few.

Many API’s now have a JSON format which is much easier to work with. I will create a function to get the current temperature in Seattle, WA.

First, I would like to use an open source Weather API. http://openweathermap.org/

Second, I have requested an api and now I will create a js function to call the JSON every ten minutes.

$(function() {
    getTemp();
});
function getTemp() {
    $.getJSON("http://api.openweathermap.org/data/2.5/weather?q=seattle,usa&units=imperial&APPID=YOURAPPID", function(data) {
		var main = data.main,
		temp = main.temp;
		$('#temp').html(temp + ' °F');
    });
    setTimeout("getTemp()",600000);
}

Current tempture in Seattle, WA

If an element contains a string

I had a question today if I could change the background color if an element contained a string. I knew I could with js, but I need to do a little research.

I found methods of completing this.

indexOf

The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.
indexOf is case sensitive.

:contains

The :contains() selector selects elements containing the specified string.
The string can be contained directly in the element as text, or in a child element.
This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
:contains is case sensitive.

if ($('#someId').text().indexOf("Gene") != -1)
{
  $('body').css( "background-color", "blue" );   
}
$( "#someId:contains('Gene')" ).css( "background-color", "blue" ); 

Jillion is NaN

OK, who hasn’t heard someone referring to Jillion as a very large number. Today on the bus my wife was telling me that something was a jillion times bigger. Well, I can’t remember what our conversion was, but I know I kept telling her that Jillion is not a real number. Jillion is often used when the number is so large a real number can’t be used. I have listed below real names of large numbers and their short scale.

var Million = 10e6, /* 1,000,000 */
	Billion = 10e9, /* 1,000,000,000 */
	Trillion = 10e12, /* 1,000,000,000,000 */
	Quadrillion = 10e15, /* 1,000,000,000,000,000 */
	Quintillion = 10e18, /* 1,000,000,000,000,000,000 */
	Sextillion = 10e21, /* 1,000,000,000,000,000,000,000 */
	Septillion = 10e24, /* 1,000,000,000,000,000,000,000,000 */
	Octillion = 10e27, /* 1,000,000,000,000,000,000,000,000,000 */
	Nonillion = 10e30, /* 1,000,000,000,000,000,000,000,000,000,000 */
	Decillion = 10e33, /* 1,000,000,000,000,000,000,000,000,000,000,000 */
	Undecillion = 10e36, /* 1,000,000,000,000,000,000,000,000,000,000,000,000 */
	Duodecillion = 10e39, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Tredecillion = 10e42, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Quattuordecillion = 10e45 ,/* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Quindecillion = 10e48, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Sexdecillion = 10e51, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Septendecillion = 10e54, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Octodecillion = 10e57, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Novemdecillion = 10e60, /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */
	Vigintillion = 10e63; /* 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000 */

A function

A function is a block of statements that can be used in a file.
I will create a function to change the color of my notes.

function colorMyNotes() {
    var i;
    var postItNoteColors = [
        '#FCF0AD', '#E9E74A', '#EE5E9F', '#FFDD2A', '#F59DB9', '#F9A55B', '#D0E17D', '#36A9CE', '#EF5AA1', '#AE86BC', '#FFDF25', '#56C4E8', '#D0E068', '#CD9EC0', '#ED839D', '#FFE476', '#CDDD73', '#F35F6D', '#FAA457', '#35BEB7', '#D189B9', '#99C7BC', '#89B18C', '#738FA7', '#8A8FA3', '#82ACB8', '#F9D6AC', '#E9B561', '#E89132', '#DA7527', '#DEAC2F', '#BAB7A9', '#BFB4AF', '#CDC4C1', '#CFB69E', '#D0AD87'];
    var i = 1;
    $('.col-md-4').each(function() {
        $(this).css('background-color', postItNoteColors[i]);
        i = (i + 1) % postItNoteColors.length;
    });
}
colorMyNotes();

The function works, however the color is always the same and it would be nice if it was random. Next, create an array that will randomize the color.

Get Unix timestamp for a date

I needed to compare an event date in Expression Engine to the current date, but the time was not in a unix timestamp. So, I used PHP and converted the time given, to unix timestamp with the PHP functions date() and strtotime().

<?php 
      $time = ( date("g:i a", strtotime("{start_time} UTC"))); 
      $unix = (strtotime('{start_day}-{start_month}-{start_year}'.$time)).'000'; 	  
?>

IS NULL

How do you query results for data in column that is NULL?

SELECT * FROM TABLE 
WHERE COLUMN IS NULL

NULL is used for data that is unknown and not zero or empty.

Unix Time

A few weeks ago I was given the task to close a program on a server, but we had know idea when the last user logged into the program. The server is Linux and records time as milliseconds since January 01, 1970. This Epoch is known as Unix Time the date is the beginning of time according to Unix. This measure of time is recorded as int32. The max value of a 32 bit integer is 2147483647. So the end of time will be January 19, 2038, until this reference date is recorded as int64.

The last log in was: 1299611945 March 08, 2011 11:19:05 AM. The program now can be removed.

Here is a link to a good Epoch Converter http://www.epochconverter.com/

Foo

What is Foo? Foo is from Foobar which is from a military acronym FUBAR. Developers use the word “Foo” sometimes as a placeholder for variables. The word “Bar” is also used as a placeholder for variables.

if(foo == "something"){
 alert(foo);
}else{
}