ExtJS4 Combobox 'value' config

In ExtJS4 when you create a combobox you get access to several configuration options, one of which is called 'value'. The 'value' config option sets the initial value of the combobox, this works without issue when you setup a local (non remote) store. You need to make sure that the value you're trying to set is part of the store (local or remote) if you're specifying 'forceSelection: true' in the combobox's config.

I ran into an issue today where my value wasn't being applied to the combobox (using a remote store) even though I knew the value I was trying to set was part of the returned data from the remote store (a list of years).

The problem turned out being that in the stores config, you can't use 'autoLoad: false' and try to set a default value for the combobox. The value will be applied only after you click the drop down on the combobox and the store loads. If you want your formfield to have the value you supply before clicking the combobox, you need to set 'autoLoad: true' in the stores config. 

Autoload makes the ajax call when your form is loaded so you'll notice in the dev tools network tab that the call to load those items is being made before the combobox is clicked. This is a tradeoff so make a decision about whether it's useful enough to the user or not.

Here is the code powering my store and combobox:

Open Graph? Open Your Eyes.

I've been reading about the recent additions to Facebook, things like the Open Graph and it's a bit worrysome. Whether you agree or disagree with the graph and "frictionless sharing" is outside the scope of this article. If you want to read about the open graph you can try these links, this post may make more sense afterwords:

Open Graph

App Discovery

Walled Gardens

Remember back when AOL was popular as an ISP? AOL had what was referred to as a "walled garden". They provided you with email and instant messaging as well as news, you may never find a need to visit a site outside of AOL's control.

Does this sound familiar? With Open Graph coming in you can now install a reader application for the Washington Post and read the newspaper right within Facebook. You've been able to play a ton of games on the platform for the last several years, do you see what's happening?

Maybe this is the first cycle of social media, perhaps we're destined to the same future as the Phoenix? Are we just to continually build ourselves up only to crash down in flames every few years? What started as a walled garden that eventually collapsed has come back around to a similar situation. One can only guess that this walled garden will eventually fall and give to way to a...

Federated Social Web

There's an idea or drive that exists on the web known as the Federated Social Web. You might've heard of Diaspora, hailed as the killer of Facebook. Killing Facebook was not Diaspora's mission at any point. Talk to any of them and they'll tell you that they have set out to change the way we use social media. You might ask "What's wrong with social media?" Let me explain.

You probably have a Facebook or Twitter account and very possibly, both. Ask yourself a few questions:

  • Who owns the information I post on Facebook/Twitter?
  • Who is it shared with?
  • How do you delete it?

Can you answer any of those? If you don't care about the answer to any of those three questions then stop reading, this post isn't for you. What I will tell you if you're still reading is that Facebook and Twitter own any content you post on those sites. Facebook holds the right for example, should you decide to delete your account, to keep all photos you uploaded for marketing purposes.

So what is Federated Social Web? Let's call it consortium of folks / companies doing everything they can to lay the groundwork upon which the future of social media can exist. The current idea about the future of social media is that users should be responsible for the content they share.

If you're talking about Diaspora you could run your own node or join an open group of nodes hosted online. By federation we simply mean that you should be able to connect with your friends on any network, thanks to the underlaying protocol that all the applications/networks are built on top of, such as...

OStatus

Evan Prodromou at Status.net has put together some introductory text that covers OStatus. You can check it out here. OStatus is a protocol upon which his site, Status.net, is build as well a great microblogging site Rstatus (full disclosure, i'm a contributer)  along with dozens of other sites. OStatus seeks to provide the foundation for the future of social media by providing a protocol that is agreed upon, open, and allows for federation. You can't open a browser tab right now and go look at the Facebook codebase or else we wouldn't be in this situation.

Challenges

So the federated web sounds all rainbows and unicorns doesn't it? Well, not exactly. There are some really hard problems to solve before we make large inroads towards a thriving open social web. Firstly, getting started on a site has to be dead simple. If we're expecting people to install software so they can share with their 82 year mother what they had for lunch it can't be the slightest bit hard.

Secondly, federation has to be second nature and so simple that a child could do it. Look at the friend codes on Wii, those are too hard. Although there might be some merit in having a unique code for each game you want to play with friends I think it's a barrier that doesn't need to exist. How do you connect with friends and family is just one question to answer.

Thirdly, identity and trust. Identity is very important, we have to have a way to make sure John Smith, living at 123 Main St in Kansas City, Mo is unique and we must make it easy to find John. There are already a few options in the identity space, OpenID and Webfinger.

Outside of the hard problems I'm sure there are problems hard and simple that I've left out (messaging, groups, etc). This article was written to get you thinking about how the current architecture is suboptimal and that there are numerous barriers to making improvements. It seems like there is so much to do before we can really start...

Moving On

Whether we eventually settle on OStatus paired with Webfinger or some yet to be created protocols, social media sites such as Facebook and Twitter will either adapt and change or die like so many before them. 

If you don't like the the idea that Facebook and Twitter own things that you post/upload, do something about it. You don't have to be a whizbang computer science major to make a difference, I'm sure not.

One thing is for sure, if you choose to stick with Facebook at least make sure from here on out that you authorize applications intelligently, for my sake, and yours.

VIM Function to 'dotcloud push'

I've been spending a lot of time lately working with DotCloud and recently I opened my .gvimrc file to add a few things and while I was there I found an entry that was added by Janus. It installs a plug-in called ConqueTerm that lets you run a shell inside a vim buffer. 

I got to thinking about it and wondered if I could create a function that would execute my dotcloud push. The following function works to do just that.

Let me know if you have improvements or there are other ways to do this! It will attempt to do a dotcloud push foldername where foldername is the name of the folder you're currently in within vim/macvim. I always open a terminal and cd to the working directory of my app and then mvim . to open macvim up pointed at the correct directory and now pressing Command+Shift+P will push my app to dotcloud!

I won the Twilio/Dotcloud development contest!

This sums up my experiences using Rails, Twilio, and DotCloud hosting with a git repo, if you're trying to do the same, maybe this will help.

This post is a bit overdue, I had planned to get to it a day or two after the contest ended which was at 11:59p pacific on Sunday night which is 1:59am central for me. I recently took part in a dev contest sponsored by Twilio and Dotcloud and wanted to sum up my experiences. Twilio provides a REST api with wrappers in several major languages (php, python, ruby, c#, and recently coldfusion). Their API makes telephony dead simple, really I'm not sure you could make it any easier. DotCloud is a cloud PaaS provider with a different idea about how a PaaS should work. You're probably familiar with some of the popular cloud hosting companies such as Heroku for Ruby/Clojure/Node.js, AppHarbor for .NET, or Orchestra for PHP but DotCloud is unique here, they let you build your own stack.

I'll let that sink in for a second. What do I mean by they you build your own stack? Ever want to do some PHP but use a NoSQL solution such as MongoDB for persistence? That's easy on DotCloud. Need to scale it out and throw up a Memcached instance? No problem, the gents at DotCloud have you covered. So enough with sounding like a car salesman and on to the reason for this post.

Humble Beginnings

When Twilio announced the DotCloud contest SOSMS was just a skeleton Sinatra app and an idea. I started on Monday and was working on getting DataMapper going for ORM. I had never used DataMapper but got it going after reading a few StackOverflow questions regarding some configuration. I wasn't able to put much into it on Tuesday but had the ability to add contacts and was storing them out to the database. The next step was to be able to have user accounts so I could associate them with contacts.

Sinatra => Rails

User accounts are a little more difficult to do in Sinatra than in Rails where you have things like Devise and CanCan. Given the limited amount of time I had considering both the fact that the contest ends Sunday night and that I was going out of state Friday and Saturday I decided to migrate from Sinatra to Rails 3. I was already using models and controllers in Sinatra (although not MVC out of the box it can support it) so moving over code was really simple. I had the migration complete in about an hour.

After moving to rails I quickly established the ability to have user accounts and then associate contacts with them so by the end of Wednesday I was OK with where I was at. On Thursday evening I started working on the design of the site as well as getting it deployed to DotCloud since I knew there might be a few things to workout there. After getting some basic design done and a logo from a friend I started to deploy to DotCloud.

Databases

I almost forgot to add this part. You need to setup your database.yml config to include the username and password as well as the URL and port for your dotcloud data instance. I'll cover how to get this information after we get the app deployed.

Deployment to DotCloud

DotCloud provides you with a CLI that I believe is written in Python. Installing the CLI is pretty simple, they just have you use easy_install to install PIP and then you can pip install dotcloud. If you don't have easy_install available just google around for python easy setup and you should come across it. I've worked with python/django a little before so I already had everything available.

Once you have the CLI installed you will want to create an account on their site so you have access to the key the CLI will want. After signing up just type in dotcloud in the terminal and then paste in the key listed in your account on the website. Creating an app on dotcloud is simple just do: dotcloud create appname

DotCloud used a YAML build file for building your stack so let's create that. You need to create dotcloud.yml to describe the stack you want, mine looks like this:

That build file sets up an environment for my Rails app to use Mysql. You don't need to use the exclude_bundler_groups statement but I have no need for my dev and test gems in the production app and it saves a second or two on the build time. The www and data sections are what are going to be your "services" so when you're using the CLI to ssh in for example you would want to say: dotcloud ssh sosms.www or dotcloud ssh sosms.data

Once you've got your build file setup you can run: dotcloud push appname to push your app. In my rails app it grabs my latest git commit and then runs bundler to setup my dependencies after initializing the database. I haven't mentioned git yet but you don't have to be using git to take advantage of DotCloud, they support Mercurial too. I can't speak to how the flow goes with using hg so your mileage may vary. Their docs cover using mercurial, it's not much different from using git from the dotcloud perspective though.

After doing your initial push you'll want to run: dotcloud info appname.dbservice (where dbservice is the name of your database service, in my case: dotcloud info sosms.data). 

Databases (cont)

Once you run the info command it will tell you the URL and port you need to setup in your database.yml file. You may also want to ssh into your mysql instance and setup a new user and password. You can do this by doing (in my example) dotcloud ssh sosms.data and then typing mysql to launch the interface to your mysql instance. Once you have your URL/Port and username information you'll want to define them database.yml and then do another push to dotcloud. If you want to avoid having to deploy your app and then come back around and grab the info you could create a build file with just a data/db service, push it, and then ssh in and have that information ready when you start your app development.

Raking

After you get your database.yml configured if you need to run rake commands you'll want to ssh into your www service and then CD to the current/ directory. Current should look like your localhost unless you have uncommitted stuff. From here you can rake db:migrate or db:seed if you need to.

Accesing Your App

Once the build process completes it tells you that your app is available and gives you a URL to visit. If you missed it or forget you can do: dotcloud url appname and it will spit out the URL to your app. Dotcloud supports doing custom domains by adding an alias but they don't yet support doing naked domains since it presents a few technical details they aren't ready for yet (namely customers having to keep their A records updated). The forum thread for naked domains lists a few ways in which it is possible but it's a bit of a hack.

Closing Thoughts

After setting up a method on my contact model and putting the finishing touches on my app late Sunday night (i didn't get to work on it Friday or Saturday) I was pretty confident it would do well. I submitted my entry about 20 minutes before the deadline so I was cutting it close. I was excited to have it up in a barebones state and get it submitted to the contest it was a fantastic experience.

Twilio does a new contest every week and I'd highly recommend trying to build something for the contest since it forces you to get something created and deployed on a deadline. I've got a ton of work left to do on SOSMS to get it to where I'm comfortable with it but I'm glad its out there and usable right now. You can find SOSMS on the web and over at github.

Lewt (aka prizes)

For winning I got some great stuff. The prizes include:

  • $100 in twilio credit
  • 12 months of DotCloud pro ($99/mo)
  • Swag from twilio and dotcloud
  • An arduino gadget pack

Press

Dotcloud blog post

Twilio blog post

Twilio on Twitter

DotCloud on Twitter

Issue with Devise and bcrypt-ruby on rake db:migrate

Recently while trying to run rake db:migrate after doing a rails g devise user (to generate a devise user model) I ran into a WALL OF TEXT error. Here's the screenshot

Screen_shot_2011-07-20_at_11

I did some quick googling and found a reference of uninstalling bcrypt-ruby (since that's what the error points to). I removed both versions of bcrypt-ruby that I found using gem uninstall bcrypt-ruby. You can search your installed gems by using gem list -d bcrypt. After removing these 2 versions of bcrypt and then bundle installing (which reinstalls bcrypt since it's a dependency of devise which is included in your gemfile) I was able to succesfully run rake db:migrate.

Hope you have the same luck.

 

Update: I tweeted coda hale about it on twitter just to let him know I'd had an issue and what fixed it. And he replied back with a link to this article.

Which Card Is The Ace?

I stumbled across this book on Amazon tonight and did some searching online and found a google books preview of it. The first puzzle it asks is the following:

 

3 card monte:

There are 3 cards face down on the table; each one is either red or black (no joker). At most one of them is red. Also, one and only one of them is an ace, but whether a red ace or black ace is not given. On the back of each card is written a sentence, and if the card is red, the sentence is true, but if the card is black, the sentence is false. Here are what the backs say:

Card 1: This card is not the ace.

Card 2: This card is the ace.

Card 3: Card 1 is not the ace.

 

 

So which one is the ace and what color is it?

Announcing SOSMS

It's not live yet, nor is it near finished but I feel like I might finally be to some point along my journey of teaching my self to develop websites that I can create something that others find useful. I've created a repo and pushed a skeleton of my app, SOSMS, up to Github.

SOSMS

SOSMS is an application that was inspired by the recent (22/5/2011) tornado that ravaged Joplin, Missouri. With SOSMS your family can submit your phone number along with theirs in the event of an emergency. You then text "SAFE" to the SOSMS phone number and your family will immediately be notified that a phone number matching the one they're searching for has checked in.

SOSMS is, and will remain, open source. It wouldn't feel right to lock something that has the potential to help so many people. I have seen the confusion that arises when disaster strikes and the uncertainty and fear felt by those families searching for loved ones and maybe, just maybe, SOSMS can help some people out.

Listing a Table's Columns in MySQL, PostgreSQL, and SQL Server

This post really has nothing to do with Ruby or Rails but I'm keen on databases and SQL so what do you expect? Let's say you need to quickly list the columns in your table without the need to fire up MySQL workbench or SQL Server Mgmt Studio. If you already are using either of those GUI programs that's fine, this will keep you out of 'design' mode where you could accidentely make a mistake.

This query will return back each of the columns in the table followed by the data type for your quick review. You could easily throw this into a stored procedure or even into a quick plugin for VIM where you provide the schema and table name.

Easy custom titles for your rails app

So titles are sort of a sore subject for me. I think they add a small bit of polish to your site but in plain HTML typing out <title>Your Title Here</title> for each page is too tedious (unless you have a junior web dev on staff...)

In rails there are several ways you can handle custom titles, that is, changing the title based on where the user is on your site or in your app. I'm going to cover my favorite way that I've found so far using content_for and yield.

The first thing you want to do is to open your view where you want to have a custom title. I'm going to start off with the index.html.erb (sorry i'm not on HAML yet) in /views/home. I want the title of this page to be "Caley Woods - Home" so at the top of the file we add the following:

<% content_for :title do %>Home<% end %>

I know what you're thinking: Hey! You said you wanted it to say "Caley Woods - Home" but you only typed in "Home". Yeah I know.. we're getting there. The thing to remember here is that this view is going to be passed into your application.html.erb layout file by default. Since I want all of my pages to say "Caley Woods - <custom title>" I'm only specifying the name of my pages I want to appear after the dash in the title.

In application.html.erb you want to add the following so that the title is properly displayed:

<title>Caley Woods - <%= yield :title %></title>

Now when you want a custom title you just need to add the content_for line at the top of your views and your layout will allow :title to be shown as your pages title.

Screen_shot_2011-02-09_at_1