I’m learning Ruby, and as an early project, I thought I’d write a little SOAP server for exposing Solaris “kstat” output to the network.

It’s embryonic, but it works. I’d like to do a little more input sanitation, since it’s certainly possible to really hurt your server by requesting a kstat value of “::” (which returns all stats).

Here’s the server code:


require 'soap/rpc/standaloneServer'

class StatServ < SOAP::RPC::StandaloneServer
        def initialize(*args)
          super
          add_method(self, 'kstat', 'stat')
        end
        def kstat(stat)
                stat.gsub!(/[^a-zA-z0-9_:+]/i,'%');
                f = IO.popen("kstat -p #{stat}")
                return f.readlines
        end
end

server = StatServ.new('StatServ,'urn:StatServ','0.0.0.0',8888)
trap('INT') { server.shutdown ; puts "Server shutdown."}
trap('TERM') { server.shutdown ; puts "Server shutdown."}
puts "Starting server..."
server.start

…and the client code:


require 'soap/rpc/driver'
def usage
        puts "Usage: #{$0} hostname kstatvalue"
        puts "   Retrieves a kstat value from a remote machine's StatServ SOAP Server."
end

hostname = ARGV[0]
value    = ARGV[1];


if ! value
        usage;
        exit 1;
end

driver = SOAP::RPC::Driver.new("http://#{hostname}:8888/", 'urn:StatServ')
driver.add_method('kstat', 'stat')

val = driver.kstat("#{value}")

val.each do |s|
puts "#{s}"
end
  • First day at work in a week. It’s like I just got back from a vacation. #
  • Need new year’s party! #
  • Where are the good parties in Portland this New Year? #
  • Sounds like Backspace/Ground Kontrol will be fun, as does Someday Lounge, and Saucebox has DJ Mr. Mumu and DJ The Perfect Syn. What else? #
  • The portland indoor smoking ban is now in effect! Wish it were before my clothes got saturated with smoke. #
  • Eating pho and watching Shogun. #
  • Another night of Pho and Shogun! My life rocks! #
  • Mmm.. Wiibrew. #

Powered by Twitter Tools.

For dorkbotpdx last night, I made this little toy:

WiiMatrix

It’s an 8×8 red+green LED Matrix, driven by three shift registers driven by a Bare Bones Board Freeduino by Modern Device Company.

Before the meeting I just had it flashing fun patterns based on odd bit-math equations. During the meeting, I was urged to add some code to make it controllable by the Wii Nunchuk. So, I wrote a simple program that takes the X and Y of accelerometer and plots it on the matrix.

I drove the LED Matrix with three shift registers: One 74HC595 8-bit register gave power to the rows of the display, and one Maxim-IC MAX6969 sank current for the columns to the display. To turn on row 1, column one, you shift “B10000000″ into the row register, and “B10000000″ into the column register:

  1 0 0 0 0 0 0 0  
1 x o o o o o o o
0 o o o o o o o o
0 o o o o o o o o 
0 o o o o o o o o 
0 o o o o o o o o 
0 o o o o o o o o 
0 o o o o o o o o 
0 o o o o o o o o 

Altogether, it was about 30 lines of code to drive the matrix with some fun patterns.

In order to encourage us to play with electronics more, JWA and I have begun doing monthly challenges. For our inaugural challenge, we decided upon an LED Birthday Candle. This is my entry to that challenge.

LED Birthday Candle

You blow the center pole towards one side, and the LED shuts off. To turn it back on again, blow it the other direction. It’s a circuit known as a bistable multivibrator, or “flip-flop”.

I do like that it’s so simple and cheap, though.

My parts list is simply:

2 – 10k ohm resistors
1 – 1k ohm resistor
1 – 220 ohm resistor
2 – 2n3904 NPN Transistors
1 – LED
3 – AAA batteries (this thing’ll last forever!)

Not including the batteries, this thing costs less than 15 cents in parts. If I could work out the “blow” mechanism a little better, I think this would be a marketable product.

Okay, now for some photos:

On the breadboard:
LED Birthday Candle

Before being shoved in the pill bottle:
LED Birthday Candle

I had originally wanted to be able to shove this thing into a fat straw, like you get with a bubble tea, so I made it as small as possible, and soldered the pieces together straight rather than using protoboard:
LED Birthday Candle

Next: Brighter LEDs!

My Wiichuck adaptor arrived a couple of days ago, and I just hooked it up.  As my first project, I’ve written this, which uses the Wii nunchuck as a musical instrument.

Source code: Freqin’ Wii

Hook a speaker to the output pin (defined below, 13 by default), and hook the Wii adapter up to analog pins 2-5, preferably using the Wiichuck adapter. Tilt the wii from side to side to adjust the tone, and tilt forward and back to adjust  the octave.  Push the joystick forward and back to adjust the length of the note.  Push the Z button to play the note.

I’m trying to think of what else I could do with this.  There’s just not a lot of data out there that can use three dimensions of acceleration data and two dimensions of joystick data.

Awed By The Beauty Of The Light The electronic man holds his joy aloft.  He loves it, because he was built to love it.  It shines with the energy that courses through his body.  He wants to share his Light with the world, but fears that if he lets it go, he’ll never know it’s glow again. 

I’ve recently become enraptured with a little microcontroller development board called the Arduino (pronounced “Arr-dwee-no”).

Arduino Diecimila

This little thing is a great way to get started with electronics. You hook some electronic component to it, write a little bit of C, upload it to the board, and “tada!”, you’ve invented some new Gizmo.

1 box double cheese hamburger helper
2 cups nonfat milk
1 1/2 cups hot water
6.5 ounces whole wheat rotini
1 pound frozen chopped spinach
1/2 pound ground turkey

Prepare as per box instructions. Yum!

  • 1 cup of rice
  • 1 small can of mushrooms
  • 1 carrot (sliced)
  • 1/2 bell pepper (diced)
  • 1 yellow or red potato (sliced into 1″ pieces)
  • 1/2 onion (diced)
  • 1 large tomato (quartered)
  • 1 can vegetable or chicken broth
  • 2 cans canned chicken (drained)
  • 1 Tbsp paprika
  • 2 Tbsp dried dill
  • Salt and pepper to taste
  • vegetable oil

Saute the onion until soft, then add the carrots, red pepper, and mushrooms. Saute for a few more minutes. Add tomato chunks. Let it simmer for a few minutes. Add the vegetable broth, canned chicken, potato slices, rice, and spices. Cover and let simmer on low until the rice is cooked (20-30 minutes).

0142 – Workgroups
This is for sending messages to roles. Several entities may join a Workgroup queue, and other entities may request chats with the workgroup (which then routes to the different entities when the chat is accepted by one of them). So, for alerting, we can send to the “alerting” workgroup, which will route to an appropriate AlertAgentBot.

0095 – Stream Initiation
For setting up a binary stream between two entities. This is cool because it could let us push all system checks to the nodes over the JabberNet. So we have a core stub ManagementAgent on each managed node, and it just logs on, and bootstraps itself.

0137 – Publishing SI Requests
For publishing available binary streams (using pubsub). So now our binary distribution nodes can publish available code, and our ManagementAgent stub can see what’s available for pulling.

0135 – File Sharing
Provides a way for entities to publish files to other entities. This looks kinda like what 0137 does, except farther evolved.

Combined, a bootstrap would be something like:
* Agent starts
* Agent checks local cache for code, loading what’s necessary.
* Agent receives pubsub list of available code
* Agent downloads (and caches) what it needs.

0136 – Message Archiving
For using the Jabber server as a persistent message store. Provides a method of adding, updating , and removing items from the store. This could be used as an audit log for the Agents.

Solaris patching is, frankly, a pain.

Patch Check Advanced makes it less painful– even pleasant.

It’ll automatically download the patch list from Sun, correlate it against what you have on your system, and present you with a list of what needs to happen. You can tell it to install all recommended patches, all security patches, or all the patches that don’t require a reboot (saving those for special occasions).

Extremely cool tool.