Jay McGavren's Journal

How a Head First author spends his days off

View on GitHub
2010-11-10

RubyOnAcid: CombinationFactory::REBOUND...

Added a simple constraint type to CombinationFactory that causes values to “bounce” off of the upper and lower bounds:

-0.2 -> 0.2
-0.1 -> 0.1
0.0 -> 0.0
0.1 -> 0.1
0.2 -> 0.2
...
0.9 -> 0.9
1.0 -> 1.0
1.1 -> 0.9
1.2 -> 0.8
...
1.9 -> 0.1
2.0 -> 0.0
2.1 -> 0.1

So when scaled to screen dimensions, for example, x and y coordinates can seem to “rebound” off the edges of the screen, or an object can “bounce” back and forth between two colors, or minimum and maximum sizes. The SineFactory did some of this before, but this gives an abrupt reversal of direction instead of a smooth curve (and sometimes the former looks cooler).

Also, I had the ExampleFactory randomly choose an operation and a constraint mode for its component CombinationFactory. Since it only used the defaults before, and since it seems I never use any functionality that isn’t wrapped up in the ExampleFactory, these rather cool features were woefully under-utilized. This should fix that.

Here’s a few sample SVG files, generated with the updated ExampleFactory:

2010-11-09_232353.svg

2010-11-09_232419.svg

2010-11-09_232816.svg

2010-11-10_011839.svg

Read more...
2010-11-05

This is cheating at live-coding - I just replayed my re-do buffer in TextMate. I figured the result would be interesting if I ever want to go back and analyze my technique, though.

Train of Thought

Read more...
2010-10-15

My mountain.rb talk on Ruboto (Ruby for Android phones) is out!

Published by Confreaks, LLC under a Creative Commons Attribution Share-Alike license.

Read more...
2010-09-26

Software patents suck. A lot.

At the behest of the Free Software Foundation, I just fired off an e-mail to the USPTO:

Subject: Software patents limit the scope of my career!

From: Jay McGavren

To: Bilski_Guidance@ .gov

Cc: licensing@ .org

To whom it may concern:

I have countless ideas for new software that I would like to implement. I would love to go into business for myself, to publish new, novel, and useful software. Maybe I’d make a little money in the process, but mostly what I want is a place in the hearts and minds of devoted users, who benefit from my designs every day.

But every time I come up with a new idea, I stop myself. I do a quick mental check of the underlying technologies I would need to build on top of. Basic ones, ones we all take for granted. And almost every time, one of those basic technologies is currently in litigation over some overly broad patent, often a patent issued despite obviousness or the existence of prior art. And I drop my idea, because I’m not willing to risk my career and my family’s future on a venture that can be shot down at any moment by a huge corporation’s legal team.

…That part was from the heart. And then, not sure of the finer points of Bilski v. Kappos, I pretty much plagiarized their talking points for the rest.

Rulings from the Supreme Court of the United States have never validated the patentability of software. Bilski v. Kappos shows that the historic interpretation of patent eligibility is far too broad. The machine-or-transformation test is not suitable as the sole basis for determining patent eligibility. Software consists of mathematical computations, and combining software with a general-purpose computer is obvious. As such, software should never be considered patentable.

Sincerely,

Jay McGavren

Mesa, AZ

I actually don’t favor completely eliminating software patents. But the current system is broken, and frankly, it has developers everywhere shackled. If my options are to keep it as-is or throw it away altogether, I’ll choose the latter.

Read more...
2010-09-26

Baddest. Conference. Badges. Evar.

Baddest. Conference. Badges. Evar.

Read more...
2010-09-18

Live-Coding Lessons Learned

I had a spectacular time live-coding on a visualizer for the third Desert Bloom PHX party tonight. I learned a few lessons while doing it, though, which I thought I’d share while they’re still fresh in my mind. I’m hoping these will help anyone who needs to supply visuals for parties.

If you’re randomly generating settings, some of them are gonna look like crap. Code up a way to quickly serialize presets to disk that you can switch between when you have an audience. (You probably don’t need a file save dialog, just a save button. Think “that’s pretty, save that” and “load up the next preset, whatever it is”.)

def save_preset
    t = Time.new
    file_name = sprintf("%04d-%02d-%02d_%02d%02d%02d", t.year, t.month, t.day, t.hour || 0, t.min || 0, t.sec || 0)
    File.open(File.join(preset_directory, file_name), "w") do |file|
        file.print YAML.dump [source_factories, @assigned_factories]
    end
    file_name
end
def next_preset
    directory = Dir.open(preset_directory)
    files = directory.entries[2..-1]
    @preset_index = @preset_index ? @preset_index + 1 : 0
    @preset_index = 0 if @preset_index > files.length - 1
    path = File.join(preset_directory, files[@preset_index])
    source_factories, @assigned_factories = YAML.load_file(path)
    path
end

Turn key settings of your visualizer into a Web service or other network service. I made the onscreen text and “next preset” functions (among others) accessible over the network, then used a script on my smartphone as a remote control, leaving me free to roam the room. This also enables something as simple as control from a second terminal window on the same machine.

screen-2010-09-18-at-12412-am.png

class <<f
    attr_accessor :text, :text_separator, :max_font_size, :min_font_size, :reset_odds, :shape_type, :max_shape_count, :listen_url
    attr_accessor :max_size
end

Read more...
2010-08-26

Titled: “title”

On Wed, Aug 25, 2010, Jay McGavren wrote:

Hey, I notice the title of my talk appears to be “Programmer Analyst”. (Which is funny, since that also happens to be the title of my job. I’m guessing I made a mistake on the talk submission form. :)

Could you change it to something more exciting, like “Ruby on Android with Ruboto”? :)

-Jay

Ha, funny. It’s been fixed. You know, the field “title” was a bit vague. You weren’t the only one to do that. Somehow I didn’t catch it was a job title. I was a bit curious how it related to the talk! ;)

Cheers,

Marty

Read more...
2010-08-19

Networked Drawing Canvas in DRb

In honor of Why The Lucky Stiff’s contributions to the fun side of the Ruby community, whyday.org includes a challenge to “see how far you can push some weird corner of Ruby”. I can think of few corners of Ruby that are weirder (or more fun) than DRb.

Distributed RuBy (DRb) is, in my opinion, the most underrated portion of the Ruby standard library. It lets you take a Ruby class and network-enable it with almost no additional code (and without modifying the original class). Back in 2006 when I was considering whether to learn Ruby or not, I took one look at DRb and realized that a language that made such things possible was probably a language worth knowing.

I made this screencast to show off how powerful DRb is, and how easy it is to get started. We create a simple drawing canvas in Tk, then use DRb to network-enable it and draw to it from a 4-line client. We finish with a Ruby client that runs on Android via the Ruboto environment. And along the way, we cover a little basic security to help keep you safe (this is a network app, after all).

http://www.youtube.com/watch?v=Ca6CBm4bSU8

Here’s the complete code for the server:

require 'tk'
require 'drb'

$SAFE = 1

canvas = TkCanvas.new(:width => 800, :height => 600)
canvas.pack

class RemoteCanvas
  def initialize(canvas)
    @canvas = canvas
  end
  def circle(x, y)
    TkcOval.new(@canvas, x, y, x + 40, y + 40)
  end
end

DRb.start_service("druby://192.168.0.100:9000", RemoteCanvas.new(canvas))

canvas.mainloop

Here’s our (tiny) sample client:

require 'drb'
DRb.start_service
canvas = DRbObject.new(nil, "druby://192.168.0.100:9000")
canvas.circle(300, 400)

And here’s the complete touchscreen client for Ruboto:

require "ruboto.rb"
confirm_ruboto_version(4, false)
java_import "org.ruboto.embedded.RubotoView"

require 'drb'
DRb.start_service

$activity.start_ruboto_activity "$druby" do

  setup_content do
    @service = DRbObject.new(nil, "druby://192.168.0.100:9000")
    RubotoView.new($druby)
  end

  handle_touch_event do |event|
    @service.circle(event.get_x, event.get_y)
  end

end

Enjoy, and of course feel free to post questions and comments below. And if you’re looking for your own way to celebrate WhyDay, why not pick your favorite library and network-enable it?

Read more...
2010-08-18

Making You Happy

“Do Ophelia!”

“Please do Tigerlily!”

…came the encore requests from rapt audience members at the Natalie Merchant concert. And with the kind but commanding tone of someone who knows how to work a crowd, Natalie responded:

“To those of you asking for particular songs, don’t worry, we have something planned. But that makes us feel bad, because we might not know how to do the songs you ask for.” [I assume she meant the ensemble of 8-odd strings, woodwinds, etc. onstage, because I doubt she herself had forgotten the lyrics to “Ophelia”.]

“But this is our promise to you - we’ll make you happy.”

I think that’s a good model for every request, whether you’re asking someone to paint you a painting, code you an application, or sing you a song: Tell them the bare minimum to make you happy. Let them figure out the details, in a way that utilizes their strengths (which they know better than you). Instead of getting a clumsy interpretation of what you were imagining, you may find you’ve commissioned a work of art.

Read more...
2010-08-02

Ruboto On Acid - Multitouch

Ruboto 0.3 added TouchListener to its event handlers. Here’s my experiment with adding multitouch input to the Ruby On Acid demo…

When it starts up (or the factory resets), all attributes are controlled by an ExampleFactory, meaning they’ll randomly be assigned to LoopFactories, SineFactories, RandomWalkFactories, etc. Touch the screen, though, and control of the drawing x/y position will be given to the touchscreen. Touch in a second place, and control of random attributes will go to your second finger: r/g/b channel, opacity, width, or height.

Read more...
Copyright © Jay McGavren.