Publishing Tweets to a WordPress blog

With IFTTT losing Twitter triggers I figured I better do something if I want to keep reposting my tweets to this blog. So with the help of the inestimable Steve Morris I whipped up a little Ruby script that is meant to be run as a cron job; the results are visible as the previous seven posts here.

Requirements for using this script:

  • A Gmail account from which to send emails.
  • A Twitter developer account with an application set up so you have the necessary keys and tokens to use in the script.
  • OSX and will probably work on Linux as well, but as for Windows I have no idea nor do I have an interest in finding out (if you port it, feel free to tweet it to me and if it seems reasonable I’ll post it here). Note that OSX and Linux come with a sufficient Ruby to run this, though you may need to tailor the first line shebang to your installation.

I used two gems to power the script: Chris Kowalik’s gmail and Erik Michaels-Ober’s twitter. It’s possible I could’ve used Erik’s t Twitter command line gem and had an even simpler script but this seems fine for now.

The script has three main parts:

  • Configure Twitter and grab the most recent 20 tweets (the default is 20, which for me is more than sufficient).
  • Loop through the tweets in reverse order (to go from oldest to newest) and for the tweets made since midnight today mail them to WordPress.
  • Send an email (through Gmail) to your blog’s secret email address with a body containing the tweet short code plus the category, comments, and publicize shortcodes to properly configure the resulting post.

Next thing I’m going to work on is adding favorites to the script.

Update: Now does favorites too.

Advertisements

Recent Programming Finds: JavaScript

While watching the 49ers absolutely destroy the Bucs this afternoon I went spelunking in the Most Watched JavaScript repos on Github. Here are some nice ones which, admittedly, may also fit with my current needs at Zuberance. (Oh yeah, we’re hiring so ping me if you do or want to do Scala with MongoDB or manage the quality of same.)

SmallCommunities and J2: My New Rails Projects

I’m happy to tell you that we recently launched J2, a new version of JHTC.org, and that I’ve spun the core code off into an open source project called SmallCommunities. SmallCommunities is available on GitHub and I would love to see some other folks join in and help me move it forward.

The purpose of SmallCommunities is to provide a self-hosted subset of Meetup.com’s capabilities that allows complete customization of the site’s visual design while avoiding the, er, difficult to control quantity of emails sent by the Meetup service. Also, the current code expects events to be monthly, plus occasional extras, and membership to be paid while Meetup of course does not, though I think this could be easily altered.

The next version of JHTC.org will be an instance of SmallCommunities. If you think SmallCommunities might be of use to your group I’d be happy to work with your web team to get you up and running!

The code is written in Ruby on Rails 3.0.x and uses Devise for authentication, Compass, Haml and Sass for views and styling, RailsAdmin for managing most content and jQuery for active interfaces; SmallCommunities has a modest test base, mainly rSpec.

There are three key open features:

  • A flexible non-event page templating system
  • Photo uploads for events, members and non-event pages
  • Multi-level navigation menu support

While SmallCommunities isn’t a CMS it does need to support some static-ish pages such as About, Memberships and so on. I plan to adapt the sample code from Jose Valim’s excellent new Rails book, Crafting Rails Applications, so that these pages can easily reuse existing components without the person maintaining the site content to know Rails (and not require the site admin to do this work).

J2 is hosted on Heroku. I really like their service and was very happy to see them acquired by Salesforce.com last year because of the added resources and stability, and our site’s traffic is low enough to fit on the free service tier. However one drawback is that Heroku doesn’t allow apps to upload files to the server; instead one must use an alternative such as S3 and those are paid services and for now we hope to avoid hosting costs to the extent possible.

Accordingly any images must be included in the application when deployed to the server and uploaded separately to, say, Picasa (Google Images). I expect there’s a suitable free service, at least for the less that 2GB worth of images we might need, just need to do some research and then loop in the appropriate Ruby gem or jQuery plugin.

There are a number of good multi-level menu solutions available, this isn’t a new requirement by any means, but the first couple I’ve tried ran into issue with some of the existing Sass/Compass CSS and I’ve just not had a need to solve it.

Note: PayPal is the only payment mechanism currently supported, to avoid the need for–and substantial hosting costs of–SSL, though I’m open to patches that add, say, ActiveMerchant, and the database schema is mostly prepared for such a change.

Three Months at Glam

First, I want to thank my friend Joel for making this opportunity possible and for his support over the last decade-plus. He is an awesomely creative developer and if you need consulting you’ll be happy I made this recommendation.

Overall, I am just really happy these days. Being a Rails developer and being at Glam Media are both very rewarding and fulfilling. Over the last decade I’ve done a lot of coding but always as a small part of my responsibilities or for my own edification but I think DHH was right when he put fun as a priority for Rails. Ruby and this framework are strong matches for my mental model; I’ve looked at most of the major programming languages over the course of the last two decades and not since Clipper, way back in the prehistoric (well, pre-Windows) days have I had such a strong fit. I can see how others get the same from, say, Python or Scala–this kind of fit is a combination of emotions, personal experience and context, not science.

Another big positive about Rails for me is the community. The number of people involved who do things to benefit the community is outstanding, and by things I mean writing blog articles and (often free) books, publishing FOSS libraries (so many great ones but a couple of current faves include Compass, Devise and MetaWhere) and tools (rvm, Git), and simply being helpful on IRC, Twitter and other fora (Elad, I’m looking at you).

Glam as a place to work really suits me. The company is big enough–strong products, revenues and market presence–but still operates nimbly and with staff given freedom to for the most part choose how their work gets done. Of course they started off on the right foot with me just by having a fresh MacBook Pro and oversized, arm-mounted monitor waiting for me my first morning. Also, the team I’m on, which builds GlamAdapt Automate, has mostly developers who are stronger than me and willing to share their expertise and a leader who spends most of his time coding (at least for now).

I tend to like organization. Whether we’re talking about code or my desk I’m always more comfortable when its neat, clean and simple. In code this often leads me to writing components or modules and twice now I’ve done that in our app. Last week, for example, I wrote a Rails plugin because the one we had been using was no longer maintained or compatible and I couldn’t find a good replacement on Github. The plugin is not too complex but it enables us to have the options of one select box on a form change in response to changing the value of another and does it without the server roundtrip of an AJAX implementation. Functionally it meets our requirements though there are some enhancements we can see clearly for a next rev.

The key point, though, is that I was allowed to do this. I’ve never even tried to write a Rails plugin before but that was never even a question; I’m simply trusted to deliver the required functionality in the allotted time.

I’ve worked with smart people on products I was proud of before, Kachingle being the most recent example. But I’m truly happy today as a Rails dev at Glam.

FIFA: Consider the open source model

In this World Cup, as in past tournaments, referees have made numerous, game-changing poor decisions on goals and possible goals. Tevez scoring from offside against Mexico, Dempsey ruled offside against Algeria, Lampard’s tying goal against Germany not being over the line are just three examples from this time around.

Just as in the past calls have come in again for technical assistance to be adopted and just as in the past FIFA are saying no. FIFA decided in March that technical solutions will disrupt the flow of play or cost too much to be deployed at all levels of competition and using them only at the national team and professional competitions will rupture the universality of play. After the round of 16, with the disallowed English goal, the possibility of using two goal line assistant referees, as trialled in this past season’s Europa League, was allowed as a future change.

Let’s separate technical assistance into two options: instant replay and sensors. Instant replay has not worked well in the NFL but somewhat better in the NHL. Regardless of the quality of the decisions in both leagues the decisions simply take too long but since the broadcasts can go to commercials, which would otherwise require TV timeouts, there’s some relief. I agree with FIFA leadership, though, that with currently available systems instant replay would be too disruptive to play in soccer.

Sensors are another story and I think FIFA are missing an opportunity here. I’m sure the cost of the recent systems with which they did experiments are quite high but their mistake was going to the big sports equipment makers for the solutions. Instead, FIFA should open an X Prize-like competition to spur development of inexpensive, open source hardware and software.

The software, especially, should be open source, not only to get a lower price tag but also to ensure against tampering and other malicious interference. One has only to look at the recent troubles with electronic voting software for a good comparable.

Additionally, the software system can be strengthened by running a master copy server and requiring a fresh copy be downloaded to the game server just prior to kickoff. The download can be validated by a one time key or biometrics.

Given the near universal appeal of soccer even among geeks I think this prize competition would be enormously popular and in fact drive improvement in sensor software and results processing for many uses beyond sport as well.

So Sepp, what do you say?

Compass/SASS User Meetup at Hacker Dojo, Mountain View, June 29

Nothing fancy but if you’re interested in a powerful, labor-saving Ruby/Ruby on Rails view building and CSS programming tools you should join us Tuesday, June 29, at 7:00 for the first Compass/SASS User Meetup at Hacker Dojo in Mountain View.

SASS maintainer Nathan Weizenbaum will be in town for the week and Compass maintainer Chris Eppstein will also bend space and time to be present.

http://compass-style.org
http://sass-lang.com

RSVP (yeah its free): http://www.eventbrite.com/event/696863337

We hope to have pizza and snacks, so registering will help us know how much to plan on getting.

Post-Mortem: Writing a WordPress Plugin

Very happy to say I’ve just released the first WordPress plugin I coded start to finish by myself (albeit standing on the shoulders of those who came before), Kachingle Medallion for WordPress. As the name suggests, the plugin simplifies using Kachingle on self-hosted WordPress blogs. You can see an example of the result on the right side of this page.

Of course we hope this plugin will speed adoption of Kachingle and be the first of several platform plugins we can offer.

Most of the process is reasonably well documented and straightforward. As with many open source projects, WordPress plugin development documentation is a bit of a mess and disjointed; for example, the page explaining how to have options for a plugin covers the older version info first and only after one’s read through that will you get to a heading saying info for newer versions starts here. Some important info, like using a single serialized option store versus one row in the options table per option, is not explained at all and the one decent linked external article didn’t explain it so I understood.

One difficulty I had was dealing with a boolean option, which I wanted to control through a checkbox on the options page. None of the docs I found dealt with this at all but fortunately I could look at the code of another plugin. Basically I wrote a custom validator that gets called on update which tests the value submitted by the form and if the value is “on” I return true.

The submission process is weaker. You go to a form that asks for a title, description and URL and no explanation of those fields or how they’ll be used. Nor can your submission be edited afterwords. There’s a README validator tool but the Markdown it expects is NOT the Markdown on John Gruber’s official Markdown page and the differences are nowhere explained.

I will try to get some time soon to go in and rectify some of these shortcomings, that’s what one does in open source projects after all.

Some important notes I want to pass along:

  • Wrap all your visible strings in either __() or _e() functions so later on localizations are easier.
  • Use define() to set up constants for names and default values of your options, and do define default values even if they’re empty strings or 0.
  • Be a good team player and hook the uninstall filter, where you can unregister your settings to clean up the options table.
  • If your plugin inserts content, decide what combination of widget, custom template tag and shortcode will be the best way to surface your content; for this plugin I wrote all three–but I refactored the code so all three call a single function that builds the content to display.

WordPress has greatly improved the tools available for plugin developers over the last few years. Recently for instance they added functions to much more easily include JavaScript and CSS files on both the public-facing and admin pages. And the community is very active and responsive.

Love to hear your comments on the Kachingle Medallion plugin!

At WordCamp SF 2010

I had the pleasure of attending WordCamp SF 2010 with over 770 WordPeeps at the new Mission Bay Campus in San Francisco yesterday as I’m working on a WordPress plugin for Kachingle that will be available (very) soon (Tweets, Flickrs, more Flickrs).

Photo of Rinat Tuhvatshin of Kloop by Eva Blue Photo of Beau Lebens by tellyworth
Overall a good day:

  • My pal Beau Lebens gave a good lightning talk on Gravatar.
  • Matt Mullenweg, who is a terrific speaker, gave us an overview of the nearly-ready WP 3.0 (which this site already runs on) and the State of the Wordiverse.
  • Rinat Tuhvatshin, co-founder and executive director of the WPMU-based Kloop.kg portal (English), the largest blog hosting platform in Kyrgyzstan, gave an inspirational talk about how Kloop was the only serious news organization in the country to report on the initial actions in the recent uprising that overthrew the national government.
  • Richard Stallman is a passionate and thoughtful man but why he was given a major speaking slot at this event is a bit beyond me. Dude should get past the whole GNU ‘plus’ Linux thing already.
  • Niall Kennedy (VideoPress lead) and Joseph Scott gave separate but terrific presentations on WordPress plugins.

Quibbles: The lunch was kind of blah. I mean, no salad, just some nasty barbecued squash, no fruit and no tables to sit at while eating? And the parking was supposed to be $5 but I got charged $24–and getting out of the garage took over 10 minutes.

Question I did not get answered, though: When will WordPress.org get better search?

Playing with Python

As part of the Events team at Hacker Dojo (where I’m more or less happily spending most weekdays now), I’m helping to write a new events application. Jeff Lindsay started the app before any of the rest of us got involved and he chose to write in Python for deployment on Google App Engine.

Never having worked with Python before (eww, indentation denotes code sections) has been a bit of a challenge. But the app is straightforward in functionality and I can often copy Jeff’s original code as a starting point. Also there are a bunch of Python devs here at the Dojo who I’ve bugged for help.

Can’t say as I’m inspired to jump ship from Ruby on Rails, at least not yet, but learning a new language appeals to me.