Archive for the ‘Coding’ Category

Some Like It Hot

Saturday, March 15th, 2008

Leave your feed reader for a bit, so you can check out my new design. The design and logo are the work of by my buddy, Oak, who I cannot give link cred because he is unable to design for himself. Maybe someday Oak. The development was all by me, obviously. It was an interesting slice and I recorded most of it so I’ll probably put out a new version of my “How to nail a sexy layout” series, screencasts included.

I was going to wait to launch this until I had finished my own blogging system (which I really haven’t started yet) but couldn’t wait. Chances are there are some bugs and I haven’t finished styling/updating everything yet, but there is enough to check out.

I have some cool ideas for this site and for railstips in the near future. That is all for now, just thought I would give people a heads up.

I Take the Internet For Granted

Wednesday, December 5th, 2007

I hate grocery shopping but I love Starbucks and my computer so while Steph goes shopping at Meijer, I sit in the cafe and enjoy a non-fat latte while hacking away. One point of interest is that the Starbucks has no wifi. What this has made me aware of is how much I use the internet while coding. What is the name of that function? What was that bookmark on Ma.gnolia? What was that feed I just read on Google Reader? I am constantly installing gems, searching for code snippets and looking up documentation while I code.

Whenever I run into a small problem, I Google it and I take the internet for granted. I continue in this pattern until I find myself without a beloved internet connection. It is then that I realize I don’t really know that much. I mean, what do I really know? I guess the answer to that question would be, Google.

Not a problem has arose that I have been unable to find a solution for, using the right keywords on Google. Noticing this tonight, as I sipped on my latte, it got me thinking. How ineffecient would I be if I had to code without the internet? Granted, I am a web developer, so at some point I would need the internet to deploy my work, but what would happen if each time I buried my nose in TextMate, I disconnected from the net.

Would I struggle for weeks until desperation forced me to turn it back on? Would I start to challenge my own brain for solutions instead of quickly finding and implementing a solution someone has blogged about? Would I begin to think outside the box and come up with innovative solutions to problems? Or, would I repeat everyone else’s mistakes when a simple search could have enlightened me? I don’t know. Got me thinking though.

Integrating Google Analytics and Actionscript 3

Monday, September 3rd, 2007

GA is quite easy to integrate with anything but the examples in the Help Center use AS2, at least last time I checked they did. Make sure you import the libraries you need and that you include the GA script above where you embed your swf and you are good to go. The following code is untested but if you know any AS3 you should get the idea.

package {
  import flash.display.Sprite;
  import flash.net.*;

  public class GATest extends Sprite {
    public function GATest():void {
      init();
    }

    private function init():void {
      sendToURL(new URLRequest("javascript:urchinTracker('/flash_event_folder/they_clicked_to_watch_a_video')"));
    }
  }
}

Nothing fancy.

Building AS3 Files From TextMate

Monday, July 30th, 2007

Once again, here is another actionscript post. One of the things that got really annoying to me was re-running the builder to create my swf and test the actionscript I had been working on. I would modify an as file in TextMate, then click on iTerm, hit up and enter to rerun the last command, and then view the swf in Finder. Way too much work. I have a bundle in TextMate called John’s Helpers. Inside that, I created a command called ‘Build File’, set the activation to Key Equivalent ctrl-b and the source to source.actionscript. Below is the code that does the dirty work.

TextMate AS Command

#!/usr/bin/env ruby -w

$LOAD_PATH << "#{ENV['TM_SUPPORT_PATH']}/lib"
require "web_preview"
require "open3"

html_header("Building ActionScript File")

if ENV.has_key?("AS_DOCUMENT_CLASS")
	filename = File.basename(ENV["AS_DOCUMENT_CLASS"])
	dir = File.dirname(ENV["AS_DOCUMENT_CLASS"])
else
	filename = File.basename(ENV['TM_FILEPATH'])
	dir = ENV["TM_DIRECTORY"]
end

puts "

Building #{filename} in #{dir}

"

swf = filename.gsub(".as", ".swf")
dir = dir.gsub(' ', '\ ') # fix space in path

puts "<pre>"

Open3.popen3("cd #{dir} && /Applications/flex_sdk_2/bin/mxmlc #{filename}") do |stdin, stdout, stderr|
	puts stdout.gets
	if error = stderr.gets
		puts "\n\n" + error
	else
		system("open #{File.join(dir, swf)}")
	end
end

# system("cd #{dir} && /Applications/flex_sdk_2/bin/mxmlc #{filename}")
puts "</pre>"

html_footer

Assumptions

  1. You have the free Flex SDK
  2. The Flex SDK is installed in your Applications folder (ie: /Applications/flex_sdk_2/bin/mxmlc)

Two Ways of Using

1) If you simply have a file open and you hit ctrl-b, it will create a swf of the same name in the same directory and then open it using Finder. Simple enough.

2) If you have a TextMate project saved with multiple ActionScript files, you can set a Project Specific Shell Variable named AS_DOCUMENT_CLASS equal to the full path to your main document class (ie: /Users/nunemaker/flash/carousel3/classes/Main.as). If that environment variable is set, no matter what ActionScript file you have open in your project, the main document class will be the only file built when you hit ctrl-b.

ActionScript Is Easy

Thursday, July 19th, 2007

So I have been learning a lot of ActionScript the past week for a project at work and I’m continually amazed at how awesome AS3 is. Tonight in like five minutes I created a basic drawing app. I always thought that was really difficult but I am quickly learning that AS3 is actually very easy to learn (if you have a solid JavaScript and programming background).

Screenshot

AS3 Fun

The code below is all it takes to create the boring drawing app pictured above.

package {
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class DrawingApp extends Sprite {

		public function DrawingApp() {
			init();
		}

		private function init():void {
			graphics.lineStyle(1);
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}

		public function onMouseDown(event:MouseEvent):void {
			graphics.moveTo(mouseX, mouseY);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}

		public function onMouseUp(event:MouseEvent):void {
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
		}

		public function onMouseMove(event:MouseEvent):void {
			graphics.lineTo(mouseX, mouseY);
		}
	}
}

You can try out the example swf file here. Just click on the link and use your mouse to draw as you would in Microsoft Paint.

About This Site

Addicted to New is the personal website of John Nunemaker (Noo-neh-maker), a Web Developer enamored of Ruby on Rails and a wide-eyed fan of all things new and cool.

You are currently browsing the archives for the Coding category.