Archive for the ‘Code Logic’ Category

Creating a Chumby Configuration Widget

Friday, February 26th, 2010

In my last post, we quickly went over Writing your first Chumby widget. This time, we’ll expand on that by adding a configuration widget.

A configuration widget is another Flash file that sets up parameters for your Chumby widget, so those settings are available when the widget loads into your Chumby. For example, perhapse you have an analog clock widget. You could create a configuration widget that allows someone to choose a color for the face of the clock, or whether or not to display the second hand. The user could choose a color and save their preferences in the Chumby database. Then, when their Chumby loads your clock widget, it would look for and download any settings for that widget.

Here’s what we’ll need:

(more…)

A Very Nerdy Birthday

Wednesday, February 24th, 2010

It was just a few days ago when Justin, our lead developer had a birthday. Us nerds in the dev department (aka… me) know just how to celebrate.

Write a python script that has ascii animation of a birthday dance!

Here’s a zip file with the python scripts in it. To run it on your computer, make sure that you have python installed, and extract the files into their own directory. If double clicking on justin.py doesn’t do anything (or it opens in notepad) then you can run it easily with the console window. Just browse to the same directory and type “python justin.py” and it should start to work. I can answer any issues in the comments.

If you are looking for some more nerdy fun, check out the ASCIImator (http://asciimator.net/). Here you can build your own ASCII animation, watch other people’s animations, or visit the ASCII zoo! My favorite is karaboz’s “walking old stickman.” What’s yours?

Building your first Twitter application with PHP

Monday, February 22nd, 2010

I’ve written before about how great it is to work with a service that has a great API. Twitter was one of the tools that I talked about in that post and today I’m going to show you the basics of working with their API.

PHP is a great language for web applications, and it’s available with just about any web host. If you aren’t familiar with how PHP works, this tutorial will probably be a poor place to start. Today we are going to talk about how to work with the Twitter API and PHP, and you’ll need to know a few things about how PHP works to keep up. For a good refresher course on PHP, click here.

Click through and let’s get started!
(more…)

A Lorem Ipsum For Images

Tuesday, February 16th, 2010

exampleWhen I first started working in a true creative industry, it took a little time to understand the value of good copy writing.  Along the way, I found out about something called “Lorem Ipsum” text, or placeholder copy, mostly used in creative design, publishing and development to show what blocks of text would look like when placed on the web page or print item until proper copy could be produced.  This fake copy looks like the real thing, and gives a sense of the overall visual layout for the finished creative.  It looks kind of like Latin, but it is not.  When a web page needs this kind of treatment, I usually find this Lorem Ipsum Generator to do the trick quite nicely. (more…)

Evaluating the Buzz

Friday, February 12th, 2010

googlebuzzGoogle’s recent release of Buzz has been surrounded by hype and questions. Only a couple days after its release, it remains to be seen if this new social networking tool will actually take off.  Could it really become one of the social networking elite, or fall flat like Wave?

What is Buzz all about?
Currently, it shares a spot somewhere between Twitter and Facebook. It can be open to the public like Twitter, or updates can be private like Facebook. The API is open to developers in the same way Twitter is, but access is limited to those who own a Google account (similar to Facebook). You can send out short text updates to your followers, but it also has built-in media sharing capabilities such as: Twitter, Flickr, Blogger, Google Reader, Picasa, and YouTube. It only takes one click to tie in each service, as most of those services already belong to Google. You can have Buzz send out an update whenever you post to any of these services, or you can choose not to share. And just like Twitter and Facebook, Buzz is available on your phone to share from anywhere you happen to be. (more…)

Utilizing Google AJAX APIs CDN

Wednesday, February 3rd, 2010

jqueryWhen using JavaScript libraries to perform a function on a public-facing web site, the traditional way of referencing your library is using something like this:

<script src="/js/jQuery.min.js" type="text/javascript"></script>

Here, we are loading a jQuery library in to the HTML header for future use on the web page.  This means each time you want to use the jQuery library (or any other JavaScript library) on your new web site, you must download the latest version, upload it to your server, and then reference it here.  This technique works well enough, but lets explore a better way to perform this same library load.  We’ll do it in a way which will help us with version control, decreased latency, and better caching. How? By utilizing a CDN (content delivery network).

Below is an example on how to go about using the Google AJAX Libraries CDN, using jQuery as the library to load. (more…)

Writing your first Chumby widget

Monday, February 1st, 2010

tic-toc-goes-the-clockSo, you got your first Chumby and have browsed through the 1500 open source widgets, and now you’re ready to contribute to the open source community by writing your own widget. There’s lots of resources out there, so we’ll just cover the basics here.

Here’s what you need:

  • A Chumby
  • Adobe Flash or other developing environment for creating SWF files
  • An account at Chumby.com

Open up Flash. Set your size to 320 x 240 and frame rate to 12 frames per second. In Publish Settings, set the Player to Flash Player 8 and the Script to ActionScript 2.0. Chumby allows widget up to 100kb in size, which is plenty of room for code, but can get tight when working with audio and video.

For this tutorial, we’ll make an analog clock. But there are hundreds of clocks already! Yes there are, but I like to have every other widget be a clock, and I’ve only found about a dozen clocks that I really like. That is one of its primary functions, after all.

First of all, set up your assets. You’ll need three clock hands, positioned in the center of the stage, with the registration point properly set. Name them hourHand_mc, minuteHand_mc, and secondhand_mc.

OK, now the code:

onEnterFrame = function() {
	dt = new Date();
	//set hour hand
	hrs = dt.getHours()+dt.getMinutes()/60+dt.getSeconds()/3600;
	angle = hrs*30;
	if (angle!=hourHand_mc._rotation) {
		hourHand _mc._rotation = angle;
	}
	//set minute hand
	mns = dt.getMinutes()+dt.getSeconds()/60;
	angle = mns*6;
	if (angle!=minuteHand_mc._rotation) {
		minuteHand _mc._rotation = angle;
	}
	//set second hand
	scs = dt.getSeconds();
	angle = scs*6;
	if (angle!=secondHand_mc._rotation) {
		secondHand _mc._rotation = angle;
	}
}

Let’s break it down. On each frame we create a new date object. Then we get the hours of the date object. We also add in the minutes and seconds because we want the hour hand to move a tiny bit every second, not just once an hour. Next we convert the hours into degrees by multiplying by 30. (360 degrees per 12 hours makes 30 degrees per hour). Next we check if the hour hand needs to be changed. It should only be changed once every 12 frames, not every frame. Using this if statement prevents unnecessary redrawing of the screen, which can save processing time and make a widget run more smoothly. Though, you’ll probably not notice any difference in this simple example.

The minute hand and second hand go through the same process.

OK, save it, publish it, and upload it to Chumby.com, but don’t make it public yet. Add it to a channel on your chumby and try it out. You’ll undoubtedly find lots of things to tweak with your clock. Did you even give your clock a face? Maybe it needs a tick sound, or a gong on every hour. Maybe you don’t want a typical analog clock. Changing the code for a digital clock should be pretty easy.

This is a simple example, but it should get you on your way. In my next post, I’ll write about creating a configuration file, and playing with the accelerometer. (unless I forget or change my mind). Until then, make a cool clock.

The Problem with Probability

Friday, January 22nd, 2010

If you were to flip a coin 10 times, and it comes up heads each time, you might think, “On the next flip, it’s SURE to come up tails – it’s due.” If you flip the coin 10 more times and again it comes up heads each time, you might think, “The next flip will surely be HEADS. Just look at the statistics.” Of course, we know that any flip has just as much chance as being heads as it does tails (assuming the coin is evenly weighted and symmetrical). So how many flips does it take to change our feeling about the next flip? Somewhere between 10 and 20 flips? (more…)

Guess What? Size DOES matter.

Wednesday, January 20th, 2010

googlebrowsersizeThe Internet is full of variables.  As web developers and web designers, we constantly wrestle with web user variables.  Things like: browser types, browser versions, platforms, Flash, JavaScript, cookies, web-safe colors, connection speed, visual impairments, and fonts.

Our goal is to find the most common settings, and to deliver web sites which match settings with a majority of users viewing the sites.  Also, we need to mitigate any problems which might arise if the user doesn’t have their environment settings similar to the development team’s in-house settings.  Let’s face it, not everybody uses Firefox or Chrome.
(more…)

Google Chrome is at it again

Monday, January 18th, 2010

IEChromeOver the weekend I was researching some new web technologies and stumbled across a new plug-in for Internet Explorer (IE). It’s called Google Chrome Frame, and it solves some big problems in the current development cycle for web apps.

Many people don’t know this, but a lot of time is devoted entirely to making IE (especially older versions) behave properly with W3C standard based browsers (Mozilla Firefox, Safari, Google Chrome, Opera, etc.). This makes developing for the web more complex than it needs to be because most browsers function as you would expect them to. Unfortunately, IE is used by most users across the planet, so the fact that it isn’t based on current standards and behaves oddly isn’t something that we developers can ignore. This is where Google-Chrome-Frame comes to the rescue.

(more…)