Saturday, July 15, 2006

Offline rdoc gem documentation in Ruby

I always forget how to do this one, even though it's really simple. (Make sure that you have rdoc installed first) To view all the API documentation in gems, simple run:

gem_server
gem server

from the command prompt. It will start a WEBrick server up on your local machine on port 8808. Therefore, if you browse to http://localhost:8808/, you'll see a list of documentation of the gems on your machine.

Updated:
It's incorporated into the gem command now, so just do "gem server"

A short Net::SFTP tutorial and freezing gems

FTP itself is not very secure, since it sends a user's login and password over cleartext. So while Net::FTP in Ruby is pretty handy, I'm hoping to wean off of it soon.

That's when, after poking around for a couple minutes that Net::SFTP exists under the Net::SSH project. Huzzah! Yet, shared hosts don't have the ability for you to just install anything though. So it was then I found:

gem list --remote net-sftp
gem install net-sftp

So that way, I can install it as a gem on shared hosts. Also, I had forgotten how to freeze gems in rails. After lots of futile searching, I did come across a more automatic way. I didn't like the way it copied everything in the ./lib, because ./lib is suppose to be for in-house libraries, and ./vendor is for 3rd party libraries. I'd like to keep them separate.

Update:
So I remembered there was a manual way to do it....Ends up is that all you have to do is copy your gems into the vendor directory. use:

gem unpack gem_name

And it'll copy the gem into the current directory for you. However, in order to be able to include it as if it were a library, you'll need to change the environment.rb file found in your config directory in your application root directory.

Under the Rails::Initializer.run do |config| block, you'll see "config.load_paths". Uncomment that line and add the various gems in the vendor directory. Note that you don't put commas inbetween every path.

config.load_paths += %W(#{RAILS_ROOT}/vendor/needle-1.3.0/lib/
#{RAILS_ROOT}/vendor/net-sftp-1.1.0/lib/
#{RAILS_ROOT}/vendor/net-ssh-1.0.9/lib/ )

So now, you'll be able to do "require "net/sftp" even if the gem isn't installed.
Update:
So how do you use the Net::SSH and Net::SFTP libraries? Just looking at the APIs, I thought I could piece it together, but it's not as simple as it sounds. It took a bit of poking around to find this manual for Net::SSH. There is no manual for Net::SFTP--only a Net::SFTP FAQ. And after looking at the manuals and FAQs, it is as simple as it looks. I wonder why I didn't get it...

Here's a little tutorial on how to start an SFTP session.

require 'net/sftp'

Net::SFTP.start(host, user, password) do |sftp|
sftp.put_file "/path/to/local.file", "/path/to/remote.file"
end

Albeit the SFTP library is complicated and kinda hard to use, the coolest thing that I found out about is that you can do is actually upload a file from memory. I wasn't able to figure out how to do this with the native Net::FTP library in Ruby.

require 'net/sftp'

data = "This is the contents of my file"

Net::SFTP.start(host, user, password) do |sftp|
sftp.open_handle("/path/to/remote.file", "w") do |file_handle|
contents = sftp.write(file_handle, data)
puts contents.code
end
end

I don't know exactly how this is done, but my naive guess is that since you already have an SSH session open through SFTP, you're able to perform native commands outside of the FTP protocol? Either way, it's just what I needed, so I wouldn't have to create local copies, upload them, and then delete them.

Making Debian packages from self-extracting installs

I usually just installed tarballs or self-extracting files, because that's what the instructions said. And it's also kinda cool to be able to run make and watch it compile. However, it makes for a mess when you have to keep track of what you installed where, especially if the install isn't all in the same directory in linux.

RPM was always hard for me to use...I dunno why. Maybe it's because of all the flags, I could never remember what they were. That's why yum and apt-get for fedora and ubuntu have been godsends lately.

This article describes how to convert the java 5.0 sdk from the self-extracting file into a debian package so that you can install it in ubuntu.

According to my roommate, this way, if other packages that are installed need java, they'll know that it's there, and won't ask for it.

Good plan.

So I think I turned over a new leaf. From now on, I will always make packages from tarballs.

Friday, July 14, 2006

S5 slideshowing

S5 has gotten less attention than it should have, once I realized what S5 stood for. To start, you can say S5 is powerpoint done through the web. As long as you have an internet connection, you can make, edit, and share powerpoint presentations very easily.

I didn't think much of it at first, since a lot of people are simply taking desktop applications and putting them on the web. Writely is a word processor on the web. There's someone else doing a spreadsheet that I can't remember the name of.

But S5 = "Simple Standards-based Slide Show System" It basically uses XHTML, CSS, and javascript to make slideshows. The advantage is that to make new themes, you can just change the CSS. And you can also write scripts to generate slideshows. I once had to put together 200 slides of graphs in MS powerpoint. It sucked, and wished I could script it, since it was a very mechanical procedure.

And presentations would transfer easily from place to place...given that the network was available. I think it'd be useful when wireless internet connection is ubiquitous.

Wednesday, July 12, 2006

Remember in Ruby it's raise/rescue, not throw/catch

Yesterday, I spent hours debugging a stupid exception construct in ruby. Why wasn't it rescuin the thrown exception? Ends up that it's because you RAISE exception, not throw them. Throw/catch mean completely different things in ruby.

Raise/rescue! And another thing I forget often is that I have to raise an instance of a class, not just the class itself!

Online communities were never meant to supplant real life

At least with this article, it sounds like she really uses these services as opposed to someone that just heard about them and rags on it without ever really trying it out.

Online communities were never meant to supplant ones in your in-person life. It just adds another dimension to it. Sure, you'll get people that go overboard and cut off their in-person relationships, but they're the outliers. For certain types of interaction you'll probably find that most people would prefer face to face interactions. These types of interactions include friends that you already know and for finding mates. It's for that reason that friends still get together when they're in town and that people on match.com still meet first before committing.

For other types of interactions, like Brad Pitt fan club forums, World of warcraft (online game), and scientific google groups, your only interest in the other people is only within the confines of those contexts. And while that's what I imagine rubs people like the author of the NYTimes article the wrong way (having a cafeteria tray attitude to getting to know people). The people we interact with no longer has to fill every aspect of our social needs. It is acceptable now to have friends you only hang out with, friends you only tell secrets to, and friends you only go on naked streaking parties with. The same goes with people you interact with online.

Cars and suburbs have probably done more to keep people apart from each other than the internet has. Think about it. You use to have to walk to the local store, passing people in your neighborhood that you knew along the way. Now, you just drive on the highway. Suburbs rarely have sidewalks, and things are further apart, so people use their cars to drive, and not interact with each other.

And even if there were people around, you wouldn't necessarily want to talk to them. Out of all the times you've ridden the subway, when was the last time you struck up a conversation with a stranger sitting next to you? I'd venture to say, very few. Now if you lived on the West Coast (except LA)...maybe things would be different.

In addition, I've often discovered that some people didn't keep friends in a certain part of their life because, "We just hung out together, and did stuff. We didn't really get to know each other." Just because a relationship is face to face doesn't mean that you will have a deeper connection with each other. No matter what the medium, it takes effort on both sides. Besides, just because there are people around doesn't mean you're not lonely. I had always taken Nighthawks to illustrate that, and Edward Hopper was way before the internet.

Presence doesn't have to be physical anymore. It can be across different spaces, and even asynchronously across different times. While these forms of communications like cell, IM, email, blogs, wikis, forums, VoIP, etc are just facsimilies of face to face interactions, they're good enough for what we need to get done or enjoy just a snippet of each other. Between friends that can't meet face to face all the time, it's better than nothing.

And some forms of communication and interaction, while more limited to face to face, actually are beneficial in other ways. There'd be no way you'd be able to produce an encyclopedia from a room full of hundreds of people, as you do with Wikipedia. Online forums leave a trail of solutions to questions and problems others have encountered. I can't tell you how many times I've gotten help with configuring my linux box or rails when I've hit upon a wall from the dregs of people helping each other.

The current body of social network web applications, however, do have a problem. While novel at first, you quickly realize that they don't actually DO anything. If it helped people connect to not only their friends, but also connected you to like-minded strangers, or MOVED people to action, then that would really be something. But the current incarnation of social networks have much to be desired. Like all revolutions, it always takes a bit of tweaking, yet it's not going away. Developers are experimenting with other types of social networks, such as the recent Twttr and Dodgeball.

Online communications are here to stay, and like all things, it's good in moderation. No matter the medium, it takes effort and attention from both parties. It's the dual act of giving and receiving that makes a relationship between humans worthwhile. Online communications only provide the conduit, even if it's a facsimilie of real life. But it's up to you to do the rest and fill it up with meaningful content.

Introduction to Bindings in Ruby

When it comes to programming languages, software developers really are zealots--everyone has their favorites. Like Paul Graham says about himself, you shouldn't just listen to a person just because they have notoriety. But I think his article about how some programming languages are more powerful than others is convincing (can't find the link right now).

What I liked about Ruby over Java or C++ most are the different types of programming ideas that I've had to wrap my head around. Just yesterday, I was looking at Ruby's ERB (Embedded RuBy) library. It executes ruby embedded in text (plain text or html). Most commonly, Rails uses ERB as a way to translate view templates into html to be displayed to the browser.

I had the problem of trying to render templates outside of controllers, which was why I was looking at ERB. I couldn't get the ERB to read the variables I had defined in the function. I mean...that's the way it worked in the controllers!

@title = "The web and all that jazz"
template = "<html><body><%= @title %></body></html>"
erb = ERB.new(template)
html = erb.result

It didn't take. It ends up that you'd have to pass ERB the current binding as well, because it assumes TOPLEVEL_BINDING. I think ERB uses eval() heavily, which in turn uses binding.

html = erb.result(binding)

binding() is a kernel method that returns the binding--essentially the scope which code is being executed. Not only that, binding() returns the binding as an object, so you can store it for future use, and even pass it around. That means that you can request the scope of a block of code (the variables that are available to it) at that time in execution, and use it at another time, when that scope might have already expired.

So in the erb example, result() was assuming scope at the very top level of the application, rather than the local scope. And that's why it couldn't find @title.

I only found one extensive article on binding. It has great examples on binding.

Being able to pass around bindings seems odd to me. It's like being able to pass scope around, and I wonder if it violates encapsulation...or maybe it's ok to violate it once in a while? But then again, I remembered that closures and blocks in ruby also have bindings. The scope in which a block is define is remembered, and can be passed around; and it's part of their power. So every time you do an array each() and pass it a block, you're passing around bindings as well. It's so much easier than messing around with function pointers.

Saturday, July 08, 2006

BlogShares - Fantasy Blog Share Market

I knew that people trade all sorts of stuff besides stocks. Fantasy Sports is a form of trading...you make educated guesses based on how well you think the players are going to do. And if you think the player's not going to do well in the future, you try to trade it for someone else that another player is willing to part with.

People also trade weather! So it seemed brilliant to me when I saw Blogshares, a place where you do can fantasy trading on blogs.

It seems like any complex system on the edge of chaos are systems that people like to trade. Because if something was completely predictable, it would be trivial. Everyone would know which the best pieces were, and wouldn't want to trade once they had it. If it was a system that was completely random, I argue that people wouldn't trade either, because the only heuristic that would work with minimal effort is to choose and trade randomly. I'm not sure why, but it's my experience that people don't like that, especially if something's at stake.

Wednesday, July 05, 2006

Cellophane as a cheap skin

This article from ZDNet via Smart Mobs talks about how cellophane is a pizoelectric. Pizos are materials that can bend if an electric field is applied to them.

Pizos are important as both sensors and actuators. If you apply an electric field to pizos, they bend, and hence they are actuators. If you bend a pizo, it should generate an electric field.

To make a pizo with cellophane and a thin layer of gold is a pretty shocking development, because they are cheap materials (a thin layer of gold is not too pricey). It opens up the door to lightweight and cheap pizos.

Rollable keyboards are now possible to be cheaper to make, in addition to surface skin tables for user interactive screens. Wouldn't it be possible to use something of the equivalent of Surface Acoustic Waves, to detect where something was touched?

Friday, June 30, 2006

Voting and the tyranny of the masses

College startup askes:

What if the New York Times let users vote on stories on their webpage the way Digg lets users vote? Wouldn’t it be more interesting to visit the website and see what real people found interesting? Wouldn’t that help the editors figure out which authors were most interesting to the public?


The internet has changed a lot in just the last two years. Despite social pundits predictions of saying that the internet separates people, we find that more and more internet applications are social, and brings them together in different ways. There isn't just IRC, homepages, newsgroups, forums, and eBay anymore; but now there are blogs, digg, and del.icio.us.

And where we find ourselves right now are social web applications--things that connect people to each other through some medium. I too am excited by the democratization of mediums, such as keyword tagging in flickr and del.icio.us, and the voting by members of digg. It allows fridges and innovations not normally seen in mainstream to rise meteorically to the attention of the masses.

The concept of decentralized thinking is alluring in that it is the anti-thesis of traditional centralized mediums, such as radio and TV. Also, it allows the individual more power, especially individuals on the outside of established paths.

The current political climate also allows such decentralizations, as opposed to the red-scare in America 40 some odd years ago.

However, despite the good movement towards democratization (used in the sense of giving more power to individuals not in established institutions), I don't believe it's applicable to all mediums.

There's a reason why the American founding fathers did NOT make a democracy; rather they deliberately made a republic. The distinction is that it respects the rights of minorities, and hence the existance of the electoral college.

Currently, Digg is a direct democracy--a dictatorship of the majority. While this is good for any type of fringe news, I don't think it is good for the type of news that the New York Times intends to deliver, which is informative in the public interest.

If the New York Times gave a direct democracy for all its news, then only the "fun" and "quirky" stories will rise to the top. You'd probably see more stories about Hollywood than about police corruption in the city.

There would need to be some type of segmentation for categories, so you can see the most voted for a particular category. Or, there would be a need for some type of electoral college for the New York Times.

Decentralization of new mediums is exciting and enables new things to happen, new innovations, and new ways to communicate. However, it would be a mistake to think that the new transplants everything old. The old is sometimes that way through intent, not by limitations.

Try Ruby in Second Life

Secondlife really amazes me more in the fact that the company had enough foresight to make secondlife a platform more than it is just a playground or game. The fact that you can try out ruby in-game is pretty amazing to me, and should draw more builders (developers) into the game. I should really try it out (been meaning to since college) to see what it's all about.

Oh, here we go. Teach your avatar Ruby and double the population of Rubyists at once. If you want to toy with it, contact Jesse Malthus.


I wish ther were more companies that would provide new platforms for developers to create on. The traditional car and home industries has been really slow on the uptake with this one.

Tuesday, June 27, 2006

Internet pizza ordering should make sense like everything else

My roommates and I ordered pizza over the web yesterday, just to try it out. It was not as easy as calling yet. Besides not being able to find a couple links as to how to pick up instead of deliver, there were two things that struck out at me.

One, when selecting toppings, the interface was a pulldown menu. If this was in beta, I'd forgive it. But I don't think they're going to improve on it any time soon. What they should have used was an ajax "shopping cart" where you can drag and drop. But instead of "items and cart", you'd call it "toppings and dough".

That interface would make much more sense.

Second, there was no time estimate as to when the pizza would be done. Even if it said in hardcoded text, "about 45 minutes", it would be better than nothing. But ideally, it would be able to communicate back and forth to the pizza place's oven, to know approximately how much time is left in making the pizza.

Monday, June 26, 2006

Basic concepts goes a long way with SVN

bash$ svn commit . -m "delete feed_tool tests"
Authentication realm: xxxxxx.com
Password for 'xxx':
Sending .
svn: Commit failed (details follow):
svn: Your file or directory '' is probably out-of-date
svn:
The version resource does not correspond to the resource within the transaction. Either the requested version resource is out of date (needs to be updated), orthe requested version resource is newer than the transaction root (restart the commit).

I was wondering why it wasn't committing, and honestly, it's pretty easy once you figure out what subversion's concept is...and I for one, had never read it.

Simply update your version with

svn update

And it should work. The version that the repository had just wasn't the version you had.

Friday, June 23, 2006

protect?() doesn't work for salted login generator

For rail's salted login generator, the protect?() method didn't work for me. So for those of you that can't get it to work, instead of messing around with it, use the other syntax instead.
before_filter :login_required, :except => ["login", "logout", "signup", "index",
"welcome", "change_password", "forgot_password"]

Friday, June 16, 2006

Medallia Blog: SmackBook Pro Archives

Medallia Blog: SmackBook Pro Archives

This is pretty cool. The guy took the accelerometer in hard drives and used it as a sensor to detect slaps on the laptop. Then, he hooked it up to a desktop manager so that he can change virtual desktops by slapping his laptop on the left or on the right.



This is pretty cool by the sheer fact that he combined things that weren't meant to be used together for something novel. And most of all, the user interface MAKES SENSE.

I too want the capability, but I'd have to build my own accelerometer from the USB drive. Do you think people will want them?

Thursday, June 08, 2006

Wired News: A Sixth Sense for a Wired World

Wired had an article on added a magnetic sense to your touch. It's interesting to see another way to add senses that isn't technologically prohibitive. However, getting surgery done, however small, for it is a little insane. I can't imagine a knife to my finger tips. That's gotta hurt.

It reminds me of the article in BBC that I read about using the tongue as an interface conduit for spatial information. They fed sonar information to a tongue actuator so that people can find their way through a maze with sonar information. It's actually kinda neat, though it's still in its preliminary phases.

I wonder if remote-sensing and remote-controlling augmentations of humans would combine as tools for specialized human workers.

I'm sure the military is interested in something like this, though I can imagine it being a fad or fashion.

Friday, June 02, 2006

Second Life and breaking out of the mold

Second Life - Wikipedia, the free encyclopedia

Second life is a MMORPG that's not so much focused on killing and owning, but creating and interacting with others and the environment created by others.

One of the things that was surprising to me was that people seemingly easily scripted complex behaviors into the objects that existed in the second life world. I had often thought that it would be neat to incorporate that into an MMORPG so that people can be blacksmiths or at least spellcrafters.

However, I would wonder if it was possible for people to use the in-game programming language to invoke computation and behaviors on the machine that's running the virtual world.

In every sense, it is very much like asking how secure is a virtual machine running virtual code on a machine? Is there a branch of computer science that studies this?

Thursday, June 01, 2006

Designing Flash mobs

Joi Ito's Web: Leadership in World of Warcraft

I had talked earlier about a new medium that intermixes reality and the internet.

What concerned me was the level of organization that was needed in order to 'get stuff done'. Even if you did get a bunch of people somewhere, would they be able to accomplish tasks without an inherent hierarchical organization, like most of our governments and companies?

Sure, a bunch of people can point to a rug, or stage pillow fights, but would they be able to fix a house or clean up the neighborhood?

I understand that not all complex behavior of a bunch of people necessarily need a 'leader'. Systems can be emergent in order to accomplish complex tasks. Ants and termites can build complex structures and societies with solely local interactions, rather than top-down hierarchical. But can these systems do everything a hierarchical system can do? And if so, how would you design them so that they evolve themselves?

Has any one done studies on how to design mob systems so that they can do things that companies can do? Are there ways to structure an organization so that people can be thrown together and something comes out of it?

It was that question that lead me to wonder how raids and groups work in the World of Warcraft. It was no coincidence that this article on leaderships in WoW got me thinking about it. According to the description, however, even the raids and groups there are hierarchical, and require quite a bit of planning and leadership.

Perhaps a little mix of both would be effective for flash mob organizations that want to be functional.

Before they can be designed or evolved, there needs to be a measure of how well a organization can accomplish a task, and a way to parameterize different characteristics of the organization. Then you can start exploring that parameter space to see which areas in this parameter space will be best at handling certain types of tasks at the system level.

UK firm to unveil wall-socket PC - ZDNet UK News

UK firm to unveil wall-socket PC - ZDNet UK News

The Jack PC would almost be considered by some to be embedded hardware, though it seems to be a fairly full fledged PC. Unused computation cycles will be more ubiqutous. Now, if only those cycles could be used for something...

A new medium for first adopters.

But back to the point: a long time ago I used to write online to a ton (like 30) of faceless, nameless people who used to laugh and possibly email me about how funny they thought it was. I was just goofing off, I wasn't too concerned about offending anyone if I could make something funny.
I think a lot of first adopters really rallied around blogs. It was like a second home to people. Everyone likes to have communities and places where everyone is respectful, interesting, and "where everyone knows your name." It was kinda like your own secret special place, and a twinge of 'coolness' because it was esoteric.

But inevitably, once a community gets so popular that there becomes an influx of newbies that have no respect for the painstaking community and culture for the medium that had built up over time. The general disrespectfulness of these newbies ends up chasing away the very people that made it special in the first place. Same thing happened on IRC and Usenet that happened in the blogosphere.
Vox is a return to that early time I don't think most people had a chance to experience. The commercialization of blogs has, I think, skewed people's perception of what they can be. To many, if you're not doing 50,000 unique visitors a day you should just throw in the towel, you're a failure. If your funny story about shopping at the Apple store can't be Digg'd or Boingboing'd then what good is it?
I wonder where the next playground of the first adopters will be? Somewhere where they can coalesce, create connections, and encourage each other to dream and to make. Likely, it will be through the introduction of a new media, as demonstrated by historical patterns.

First BBSes, then Usenet, and IRC. Then forums, and then blogs.

What will the new medium be like? I can imagine a couple things (though by no means accurate).

One might be the lowered barrier of making things, something like open source design. People with shared passion of making and creating things will be able to make connections and communicate with each other through making things.

Second might mix the internet and reality, where strangers gather for some cause, whether this cause is deliberate or emergent from the groups' decisions. These decisions might come from people that aren't even there, whose names they don't know.

I'm imagining something like people are able to view the positions of all those that are participating, on a map. Then they're able to vote and come to agree to where to gather, and what the goal is. Then those that are by the site get notified, and can spontaneously partcipate if they wish. Much like flashmobbing, but less deliberate.

Then, the ability for strangers to discuss or exchange what they did might build a community.

However, I can see how something like this could be used for evil, like sending a mob to various sections of streets in guise, where it is meant to block off roads to help a bank robbery or heist.

And yet, it's a neat idea. Emergent cooperation organized by the net that mixes with reality. It's another way for people to interact outside of their defined roles and places in society.