Fedora 18 Yum errors

I was getting an odd error whenever I tried to use yum.
I checked my /etc/yum.repos.d/ folder and there were no ‘dag’ entries.

[root@localhost yum.repos.d]# yum list php\*
Loaded plugins: auto-update-debuginfo, langpacks, presto, refresh-packagekit
http://apt.sw.be/fedora/18/en/i386/dag/repodata/repomd.xml: [Errno 14] curl#22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
Error: failure: repodata/repomd.xml from dag: [Errno 256] No more mirrors to try.
http://apt.sw.be/fedora/18/en/i386/dag/repodata/repomd.xml: [Errno 14] curl#22 - "The requested URL returned error: 404 Not Found"

I ignored it at first but eventually updates started failing and Yum wasn’t finding software I knew existed in the repos.
The solution was that the dag repo was listed in my /etc/yum.conf

I removed that and ran a

sudo yum clean all

and everything was fine again!

PHP << and >> (bitwise operators Shift Left and Shift Right) Introduction

If your are new to PHP and stumble upon the << and >> operators they are not similar to the << and >> operators in C++. This guide attempts to explain the concept behind shift left and shift right – what << and >> do.

Lets say we have a variable called $a. If we were to shift it 5 times to the left it would be like multiplying it by 2 five times;  $a * 2 * 2 * 2* 2 * 2. Now since you love math you know that is $a * 25

So when you see the syntax $a << 5, you know that is $a * 25;

$a << 5 = $a * 25

Lets say we have $a >> 5. In this case you can see that the we want to shift right. A great guess we be that what this operation does is it divides $a by 2 five times, $a /2 / 2 / 2 / 2 / 2, or $a / (25)

$a >> 5 = $a / 25

You might notice I purposefully chose 5 because I originally titled this tutorial as “PHP << and >> (bit-wise operators Shift Left and Shift Right) Explained for a five year old” – jokingly suggesting a five year old can handle it, maybe, I dunno, I have seen some smart kids. I also thought it would be easier on the eyes than seeing $a and $b everywhere.

Some history;

The shift operators came from the C language designed by  Dennis Ritchie. When C was designed it was running very close to the hard ware, in fact shift is an instruction from Assembly language (SHL and SHR).  This is due to the way the value is stored in memory, it’s stored in binary. A binary representation of the value, if literally moved over, will have the result (since binary is numbering system based on twos) of being divided by two.

Side note: if you don’t know binary go learn it real quick, if you do know binary, test how well you know it here

For example, 80 written in binary is 1010000. If I shift is right once I get 0101000, which is 40. If I shift it again (80 >>2) we get 0010100 which is 20. As you can see shift right and shift left are the opposites of each other, so if I shift it right five times then shift it left five times, it will cancel out.

The shift operation are not mathematically associative, that is if we do the linear order in a different fashion, we will get the same result. So if we have ($a << $b) << $c, we are not guaranteed to get the same result as $a << ($b << $c).

($a << $b) << $c != $a << ($b << $c)

The shift operation is not commutative either. So if we have $a << $b and we switch the terms around, $b << $a, we will get a different result

$a << $b != $b << $a

You are probably now wondering when  would you use this operator? Well any time you start writing code that performs a lot of integer multiplication, so for people with careers specializing in file compression, cryptography, audio and video processing, mathematics, Wall Street, accounting, banking, the list goes on.

Here is a program that performs multiplication using only bit-shifts and addition

<?PHP
$c = 0;
while($b != 0) {
     if(($b & 1) != 0) {
          $c += $a;  //also same as $c = $c + $a;
      }
      $d = $a << 1;
      $e = $b >> 1;
}
print $c;
?>

It was Aliens - they gave us the knowledge!

In fact, the Egyptians had a similar method for performing multiplication; mandatory wikipedia link.

 So now I have a question for you, please provide what you think is the answer in the comments section!

What will be printed to the screen when the below code is ran?

HINT: Wait until next month when I talk about bitwise ANDs and ORs  (‘&’ and ‘|’ in PHP)
<?php
    $a = (1 << 0 );
    $b = (1 << 1);
    echo ($b | $a) << 2;
?>

Animate a cheap Walmart Halloween decoration with Arduino

Creepier Door Knocker

 

I picked up this scary face door knocker last year at Walmart for $5, they probably still sell them but I haven’t checked. I am not actually using an ardunio, but a similair thing called a Digispark made by Digistump (hard not to mix these names around) but I friggin love these things. They are not as full featured as an Arduino, but for what I’m about to do they are overkill and super easy to use and pretty cheap. They also use the same software (the software made by Ardunio). Most hobbists will probably tell you that you could make the thing for even cheaper yourself, I am lazy and I defend that trait for two reasons, conservation of enegry and the fact that I do not need to reinvent the wheel. Ten bucks is cheap enough in my opinion (I am not mass producing anything using these).

I have some plans for what to do to it next year, I always break things up into multiple revisions. I definitely want to add a motion sensor, currently it just repeats this loop until I turn it off or until the battery dies. I also want to add sound. However instead of installing a speaker inside the knocker,  I want to try to use bluetooth and have the sound play on an external speaker hidden in the bushes or next to the porch. Maybe I can have it ping my phone so that I know someone is there before they even ring the door bell.

Parts List

  • 1 Plastic scary old man door knocker from Walmart (here is a similar one on Amazon)
  • 2 RGB LEDs (I purchased form SparkFun)
  • 1 Digispark or any arduino (not much code here so even an Uno would be overkill)
  • 1 servo (I purchased the ‘Medium Servo’ from SparkFun)
  • ! pack of 100 Ohm resistors (1/2 watt radio shack 2711108)
  • 1 AA battery pack (Sparkfun, again)
  • 1 switch (I had it left over in the parts bin)
  • Misc: Hot glue, epoxy putty, wire, solder, USB Hub (highly recommended), some think aluminum from home depot

So, I present to you my build log, happy Halloween!

 

original door knocker

The is the door knocker after I had removed the two cheezy red LEDs I put in it last year

digispark

Digispark, for those not in the know

a guy with epoxy putty goes mad

Beginning of the servo mount, don’t worry, it gets sloppier!

LEDs and servo installed

Jump ahead to where I have the eyes cut out, RGB LEDs installed, and used hot glue to shape the eyes and fill in the gaps. I also have a battery pack Velcro-ed to a metal plate that I used epoxy putty (JB Weld) to hold the plate in with 4 AA batteries. The servo is mounted and fully secured using, you guessed it, HOT GLUE. Oh, and also, I burnt out the green and blue LEDs after I had hot glued them in, so the defective ones are staying there this year. I fashion an L shape key out of some aluminum sheet metal I got from Home Depot that I had lying around. I also used this to make a bracket for the top of the servo and I epoxied it down. I coated everything in liquid electrical tape and hot glue. I would still probably take it down and bring it inside if we had any rain just to be safe.

switch install

Here I am dremeling out a space for the switch

 

The wiring for this is;

Servo

  • Brown to Digipark ground
  • Red to Digispark +
  • Orange to p0

Battery pack

  • Red to switch then from switch to Digispark +
  • Black to Digispark -

LEDs

  • Red to 100 Ohm resistor then to p4
  • Return (ground) to Digispark ground
  • Green to 100 Ohm resistor then to p5
  • Blue to 100 Ohm resistor then to p0

 

For the source code I used analogWrite to set the brightness of the LEDs. I would have probably went with a progressive green fade-in fade-out but I did something wrong and burnt out the green and blue components so I only had red left.

I did not use any servo libraries, I just used digitalWrite() and delayMicroseconds() to get the servo to the desired position. This is a really basic build up. Nothing complicated here.

Source code can be found here

 

 

 

 

 

 

 

 

 

HTML mixed text color

I rarely get to make new HTML pages, in fact on a job interview the interviewer, who was a really cool down to earth guy, chuckled when I used the font tag to set text color. I knew it was depreciated, but all the sites I work on daily still use do it this way and have not been updated.

So, being the expert googler that I am I tried to find the correct way to set mixed color. I couldn’t find it, blog opportunity!

So to be clear, all I wanted to do was after my field name, have a red asterisk to indicate that it was a required field, except I do not know the exact color the client wants yet (third party came up with the design, my client uses a lot of different third parties…).

So I only want to define this once in the css for easy changes later.

What I cmae up with is this;

css file:

.required_asterisk {        
     color: #f00; /* red */
}

Then in my html file;

Name<a class="required_asterisk">*</a>

PHP Object to string conversion notice

Ran across another poorly worded error message in PHP today:

<b>Notice</b>:  Object of class LoyaltyReply to string conversion in <b>/home/xxxxxx/public_html/xxxxx/LoyaltyReply.php</b> on line <b>222</b><br /

My line in question was checking to see if the varible was set, it was not doing any string conversion whatsoever. FYI, this server is still on PHP 5.1.6 and you will only get this message if you have notices enabled in your php.ini

error_reporting = E_ALL & ~E_NOTICE

The fix was quite easy:

if (isset($$this->session_info->bad_pos_datetime)) {

Just remove that extra ‘$’ and everything was fine.

Create a Gmail like E-mail Compose Page

Gmail-like email compsoe window

There might come a time when you would like to borrow some Gmail features to create a page or popup to send an email or create some kind of editable text body.  Since I have wanted several Gmail-like features in a couple of projects I wanted to share one way of accomplishing some of the cool features Gmail has like tokenizeing email address, auto-complete and editable text areas.

Since this guide is intended to get beginners up to speed quickly as well as avoid reinventing the wheel, I will use Jquery-tokeninput and nicEdit. There are other tokenizers/autocomplete out there, as well as other WYSIWYG editors, but I felt that these two were both easy to use, very hackable and had MIT licenses if you work for a company that worrys about licenses.

I looked into several WYSIWYG editors (rather than create one from scratch), I found that I like nicEdit better, it was exteremly easy to integrate, their webpage lets you customize it to a certainextent and it is MIT licncesned.The downsides are that there are bugs and nicEdit is no longer being maintanied. The upside is that there are many forks on github.

First thing you need to do is make sure you a webserver with PHP setup. Once you have that setup and running, we will start to build our page.  Make sure you have downloaded jQuery and nicEdit (or one of the nicEdit forks on github). I will start by  creating a file called send_email.php:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
	<title>Gmail Clone Example</title>
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" type="text/css" href="send_email.css" />	
<style>
</style>

<script src="jquery-2.0.1.min.js"></script>
<script src="send_email.js"></script>

</head>
<body id="body_email">

<?php

if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'send' ) {
	$missing_error = 0;

	if (isset($_REQUEST['subject'])) {
		$subject = $_REQUEST['subject']; 
	}

	if (isset($_REQUEST['body'])) {
		$body = $_REQUEST['body'];
        }

	if (isset($_REQUEST['to'])) {
		$to = $_REQUEST['to'];
        }

	if (isset($_REQUEST['cc'])) {
		$cc = $_REQUEST['cc'];
        }

	if (isset($_REQUEST['bcc'])) {
		$bcc = $_REQUEST['bcc'];
        }

	//send email
	$headers  = 'MIME-Version: 1.0' . PHP_EOL;
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . PHP_EOL;
	$headers .= 'From: Me <me@email.com>' . PHP_EOL;
	$headers .= 'Bcc: ' . $bcc . PHP_EOL; 
	$headers .= 'Cc: ' . $cc . PHP_EOL;

	mail($to, $subject, $body, $headers);

	//post success message

}
$html = '
	<div id="content">
		<!--- To Email Addresses --->
		<div>
			<div class="email_address_label"><span>' . _("To") . ': </span></div>
			<div class="email_address_wrapper">
				<div id="to" class="email_addresses">
					<input type="text" id="to_manuals" class="manual_email_addresses"/>
					</div>
				</div>
			</div>

			<!--- CC Email Addresses --->
			<div class="cc_container_div">
				<div class="email_address_label"><span>' . _("CC") . ': </span></div>
				<div class="email_address_wrapper">
					<div id="cc" class="email_addresses">
						<input type="text" id="cc_manuals" class="manual_email_addresses"/>
					</div>
				</div>
			</div>

			<!--- BCC Email Addresses --->
			<div class="bcc_container_div">
				<div class="email_address_label"><span>' . _("BCC") . ': </span></div>
				<div class="email_address_wrapper">
						<div id="bcc" class="email_addresses">
								<input type="text" id="bcc_manuals" class="manual_email_addresses"/>
						</div>
				</div>
			</div>

			<!--- BCC/CC BUTTONS --->
			<div>
				<div class="add_cc_label"><span>&nbsp;</span></div>
				<div class="add_cc_wrapper">
					&nbsp;
					<button id="add_cc" class="add_cc">
						' . _("Add CC") . '
					</button>
					<button id="add_bcc" class="add_bcc">
						' . _("Add BCC") . '
					</button>
					&nbsp;
				</div>
			</div>

			<!--- Subject --->
			&nbsp;
			<div>
				<div class="email_subject_label"><span>' . _("Subject") . ': </span></div>
				<div class="email_subject_wrapper">
					<input type="text" id="subject" class="subject"/>
				</div>
			</div>
			<!--- BODY TEXT --->
			<!--- BODY HTML --->
			<div>
				<div class="email_body_html_label"><span>' . _("Body") . ': </span></div>
				<div class="email_body_html_wrapper">
					<textarea cols="64" name="email_body_html" id="email_body_html" class="email_body_html" ></textarea>

				</div>
			</div>

			<!--- Send/Clear BUTTONS --->
			<div>
				<div id="button_bar">
					<button id="send">' . _("Send") . '</button>
				</div>
			</div>
		</div>
	';

echo $html;

?>
</body>
</html>

Your jQuery version might be different from the one I used, make sure to replace jquery-2.0.1.min.js with the file you have downloaded.

So now we have the basic form with some PHP to handle sending emails, so lets go ahead and make the CSS so this displays better and make the JS code to hide the BCC/CC buttons and fire the send email clicked event.

I’ll name the css file send_email.css

 

# {
	position:         absolute;
	top:              0px;
	left:             0px;
	right:            0px;
	bottom:           0px;
	overflow:         hidden;
}

#content {
	position:         absolute;
	top:              60px;
	left:             60px;
	right:            60px;
	bottom:           60px;
	padding:          5px;
	padding-right:    6px;
	overflow:         auto;
	border:           1px solid rgba(30, 30, 30, .2);
}

.email_address_label {
	float:           left;
	width:           10%;
}

.email_address_label span {
	position:        relative;
	top:             5px;
	font-weight:     600;
}

.email_address_wrapper {
	float:           left;
	width:           90%;
}

.email_addresses {
	display:          inline-block;
	position:         relative;
	width:            100%;
	min-height:       30px;
}

.email_addresses input {
	width:   100%;
	border: 2px solid #dadada;
	padding:         0px;
	box-shadow:      none;
}

.email_addresses input:focus {
	outline: none;
	border-color: #9ecaed;
	box-shadow: 0 0 10px #9ecaed;
}

.manual_email_addresses {
	position:         absolute;
	top:              2px;
	left:             2px;
	bottom:           2px;
	right:            200px;
	background-color: rgba(255, 255, 255, 0.4);
}

.email_subject_label {
	 float:           left;
	 width:           10%;
}

.email_subject_label span {
	 position:        relative;
	 top:             5px;
	 font-weight:     600;
}

.add_cc_label {
	float:           left;
	width:           10%;
}

.add_cc_label span {
	position:        relative;
	top:             5px;
}

.email_body_html_label {
	 float:           left;
	 width:           10%;
}
.email_body_html_label span {
	 position:        relative;
	 top:             5px;
	 font-weight:     600;
}

.email_subject_wrapper {
	 float:           left;
	 width:           90%;
	spellcheck:     true;
}

.email_subject_wrapper input {
	width: 100%;
	border: 2px solid #dadada;
	padding:         0px;
	box-shadow:      none;
}

.email_subject_wrapper input:focus {
	width: 100%;
	outline: none;
	border-color: #9ecaed;
	box-shadow: 0 0 10px #9ecaed;
}

.add_cc_wrapper {
	float:           left;
	width:           90%;
}

.email_attachments_wrapper {
	 float:           left;
	 width:           90%;
}

.email_attachments_wrapper button {
	position:        relative;
	margin-top:      2px;
	height:          26px;
}

.email_attachments_wrapper button span {
	position:        relative;
	bottom:          2px;
}

.email_body_html_wrapper {
	float:           left;
	width:           90%;
	spellcheck:     true;
}

.email_body_html_wrapper textarea {
	height:          100px;
	width:           100%;
	max-width:       100%;
}

div.nicEdit-panel {
	width: 100% !important;
}

.nicEdit-panelContain {
	width: 100% !important;
}

 

So lets write up the JS file now, I named mine send_email.js

window.onload = function() {

	//Hide intial CC feild and show the button, onclick hide the button and show feild
	$(".cc_container_div").hide();
	$(".add_cc").click(function() {
		$(".cc_container_div").show();
		$(".add_cc").hide();
	});

	//Do the same for BCC
	$(".bcc_container_div").hide();
	$(".add_bcc").click(function() {
		$(".bcc_container_div").show();
		$(".add_bcc").hide();
	});

	$('#send').click(handleSendClick);	

};

/**
* Handles a click of the Send button.
*/
var handleSendClick = function(event) {
	var confirm_msg = 'Are you sure you would like to send this message?';
	var missing_msg = '';
	var missing_count = 0;

	var my_subject = $('#subject').val();
	var my_body = $('#email_body_html').val(); 
	var my_to = $('#to_manuals').val();

	if (my_subject.length == 0) {
		missing_msg += 'subject';
		missing_count++;
	}

//length is not zero bug
	if (my_body.length == 0) {
		if (missing_msg.length)
			missing_msg += ', ';
		missing_msg += 'body';
		missing_count++;
	}

	if (my_to.length == 0) {
		if (missing_msg.length)
			missing_msg += ', ';
		missing_msg += 'to';
		missing_count++;
	}

	if (missing_count) {
		//capitalize first letter
		if (missing_count == 1)
			missing_msg += ' feild is empty, would you like to send anyway?';
		else 
			missing_msg += ' feilds are empty, would you like to send anyway?';
		confirm_msg = missing_msg;
	}

	if (confirm(confirm_msg)) {
		var form = document.createElement("form");
		form.setAttribute("method", "post");
		form.setAttribute("action", "send_email.php?action=send");

		var params = new Array();
		params['subject'] = my_subject;
		params['body'] = my_body;
		params['to'] = my_to;
		params['cc'] = $('#cc_manuals').val();
		params['bcc'] = $('#bcc_manuals').val();
		params['fileuids'] = $('#attachments').val();

		for(var key in params) {
			if(params.hasOwnProperty(key)) {
				var hiddenField = document.createElement("input");
				hiddenField.setAttribute("type", "hidden");
				hiddenField.setAttribute("name", key);
				hiddenField.setAttribute("value", params[key]);
				form.appendChild(hiddenField);
			}
		}
		document.body.appendChild(form);
		form.submit();
	}
}

Okay, so now we should have  a page that looks quite simliar to gmails email composing page. When the user clicks on “Add CC” the “Add CC” button should disappear and the div holding our CC field should appear, same goes with Bcc.

I should also talk about sending emials in PHP, you might want to use a third party (such as Amazon SES) but if you decide to use the server that PHP is running mail() works quite well. You can configure PHP to use itself (localhost) or an external sendmail server.

I chose the easy route for this guide, but as you copy and paste realize that wrapping mail() in a class would be a better choice design wise.

 

Gmail-like E-mail compose screen

 

Now let’s start enhancing this by adding the Tokenizer functions. In send_email.js we will add:

      $("#to_manuals").tokenInput("emailLookup.php?q=", {
                theme: "facebook",
                tokenValue: "name",
                resultsFormatter: function(item) {
                        return "<li><div style=\'display: inline-block; padding-left: 10px;\'><div class=\'email_row\'>" + item.first_name + " " + item.last_name + " &lt;" + item.name + "&gt;" + "</div></div></li>";
                },
                tokenFormatter: function(item) {
                        return "<li><p>" + item.displayname + "</b></p></li>";
                },
                preventDuplicates: false
        });

        $("#cc_manuals").tokenInput("emailLookup.php?q=", {
                theme: "facebook",
                tokenValue: "name",
                resultsFormatter: function(item) {
                        return "<li><div style=\'display: inline-block; padding-left: 10px;\'><div class=\'email_row\'>" + item.first_name + " " + item.last_name + " &lt;" + item.name + "&gt;" + "</div></div></li>";
                },
                tokenFormatter: function(item) {
                        return "<li><p>" + item.displayname + "</b></p></li>";
                },
                preventDuplicates: false
        })

        $("#bcc_manuals").tokenInput("emailLookup.php?q=", {
                theme: "facebook",
                tokenValue: "name",
                resultsFormatter: function(item) {
                        return "<li><div style=\'display: inline-block; padding-left: 10px;\'><div class=\'email_row\'>" + item.first_name + " " + item.last_name + " &lt;" + item.name + "&gt;" + "</div></div></li>";
                },
                tokenFormatter: function(item) {
                        return "<li><p>" + item.displayname + "</b></p></li>";
                },
                preventDuplicates: false
        })

We will also create a file to handle our database lookup named emailLookup.php. In my version I just created a fake example of hard-coded email addresses. You should get a little creative and make database calls or API calls to your favorite database.

<?php

class EmailLookup {
        private $emails = array( array('chuck', 'wolfe', 'chuckwolfe@email.com'),
                                        array('Susan', 'Orville', 'sorville@pops.com'),
                                        array('Stacy', 'Lacey', 'slacey@doamin.com'),
                                        array('Brad', 'Humchucker', 'captainStan@rideglide.com'),
                                        array('Herbert', 'Stankiver', 'mayorbob@ymail.com'),
                                        array('Cat', 'Manchester', 'Cmanchester@email.com'));

        private function contains($array_unit, $term) {
                if (stripos($array_unit[0], $term) !== false)
                        return true;
                if (stripos($array_unit[1], $term) !== false)
                        return true;
                if (stripos($array_unit[2], $term) !== false)
                        return true;
                return false;
        }

        private function queryEmails($search_term) {
                $email_addresses = array();

                foreach ($this->emails AS $email) {
                        $email_address = array();
                        if ($this->contains($email, $search_term)) {
                                $email_address['first_name'] = $email[0];
                                $email_address['last_name'] = $email[1];
                                $email_address['displayname'] = $email[0] . " " . $email[1];

                                $email_address['name'] = $email[2];
//had to use name, since i couldn't format my results with 'email'
//seems it only has support for name and id
                                $email_addresses[] = $email_address;
                        }
                }
                print json_encode($email_addresses);
        }

        function __construct($search_term) {
                //do i need to inti this list?
                //$email_list = new emailList();
                $this->queryEmails($search_term);
        }

}

$email_lookup = new EmailLookup($_REQUEST['q']);
?>

 

 

Screen Shot 2013-08-17 at 1.00.19 PM

Now we have nice tokenized email addresses. You can customize this further, Loopj is designed so you can change the color, the orientation (vertical lists or horizontal lists), you could show an avatar next to each persons name, or show other data like how many times you email them, or if they are a current employee, whatever data you have about them you could show somehow, it is a very nice script. Of course other tokeizners are easier to use and lighterweight.

Now we need to add a WYSIWYG editor. WYSIWYG means What You See Is What You Get. I’m writing this blog post in a WYSIWYG right now using WordPress.
Add PHP, js, etc

Add to send_email.js:

nicEditors.allTextAreas();

This enables text editors on every text area in you page, in our case this is okay since we only have one text area. If your page has more than one text area and you do not want an editor in it you would not use this method.

 

Gmail-like email compsoe window

 

 

 

This concludes my tutorial. The source can be found on github here. Feel free to ask questions in the comment section, thank you.

Android/Java error: can be an out parameter, so you must declare it as in, out or inout.

This was an easy fix, but it was quite weird. Android AIDL files can only contain primitive data types such as int, long, char and boolean, as well as String, List, CharSequence and Map.

In my case, I was passing around a Bitmap.

All I need to do was to add an import statement at the top of my .aidl file for Bitmap library:

import android.graphics.Bitmap;

and in my function declaration state whether it was in/out/both:

void openFile(String path, int hash, String title, in Bitmap image);

In my case it was input only, but, as the error message says, it could have been in, out or inout.

 

Finding unknown keys from an array in Javascript

I had an issue today where I wanted to get the keys from an array (they were not not known to me and were variable) and assign them as a property to an object.

Turns out the solution was very simple.

var result = results[i];
for (var key in result) {
   row.prop(key, result[key]);
}

 

Since I couldn’t access the value by ‘results[i].key’, I assigned results[i] to result. Then accesses it by results[key]. This is due to how javascript really stores things.