Testing Out A Garden Gadget

We had some issues with groundhogs eating our tomatoes so I attempted to create a little gadget that would help with that. The following stands in the garden and alerts any motion via SMS. Along with motion detection, it also sends the temperature, light intensity and soil moisture over WIFI.



Trinity As Seen By A Programmer

Any thoughts on the following: Trinity As Seen By A Programmer?

class God
  # John 1:3
  def can_know_everything?

  # Matthew 19:26
  def can_do_everything?

  # Isaiah 55:8
  def is_like_a_human?

class Father < God

class Son < God
  # Mark 13:32
  def can_know_everything?

  # Hebrews 2:18
  def is_like_a_human?

class HolySpirit < God

TeleSMS gem released

The TeleSMS gem was recently released. This gem helps with sending and receiving SMS messages using emails. For example, Verizon has an email-to-sms gateway that allows users to send SMS messages by sending an email to NUMBER@vtext.com.

TeleSMS also encapsulates the logic for receiving SMS messages. Since there are many cases of incorrectly formatted messages, TeleSMS will attempt to return a nicely formatted message along with its metadata.

To send a message, you can do the following:

Telesms::Outgoing.deliver('john@example.com', '555555555', 'Verizon', 'Message body')

To receive a message, do the following:

# => { from: '555555555', to: 'john@example.com', body: 'Message body', provider: 'Verizon' }

If you have any suggestions or improvements, please let me know or create a pull request on Github.

Telefio uses the TeleSMS gem.

Proof that God is a programmer

Joke of the day: Proof that God is a programmer

“So shall my word be that goeth forth out of my mouth: it shall not return unto me void, but it shall accomplish that which I please, and it shall prosper in the thing whereto I sent it.” – Isaiah 55:11

void a_void_function() {}

Youtube Live & JW Player – Custom Playlist

Youtube recently allowed regular users to create live events using Youtube Live. It seems like a great service if you are looking for an affordable (Youtube is currently free) streaming service for church or whatever else you want to do.

I couldn’t find anything that would fit my needs so I decided to try Youtube Live and create a custom playlist for JW Player. The playlist displays an upcoming event (the next one in sequence) at the top and recorded videos in a playlist under that.

Here is the JW Player config:

<div id="player">Player</div>

<script src="http://jwpsrv.com/library/YOUR_JW_KEY.js"></script>
        primary: "flash",
        aspectratio: "16:9",
        height: 354,
        width: 860,
        listbar: {
           position: "right",
           size: 230,
           layout: "extended"
        playlist: "playlist.php"

And the playlist that is being generated in playlist.php:

$youtube_user_id = "" // Can be found in your youtube account settings;
$youtube_playlist_id = "" // View the playlist in the browser and get the ID (starts with PL);

header('Content-type: application/xml');
echo "<rss version=\"2.0\" xmlns:jwplayer=\"http://rss.jwpcdn.com/\">";

$live_event_ids = array();

function sort_by_date( $a, $b ) {
    return $a["date"] - $b["date"];

function upcoming_live_event() {
  global $live_event_ids;

  $feed = "http://gdata.youtube.com/feeds/api/users/" . $GLOBALS['youtube_user_id'] . "/live/events?v=2";
  $feed = file_get_contents($feed);
  $feed = str_replace('<yt:when', '<ytwhen', $feed);

  $rss = simplexml_load_string($feed);

  $live_events = array();

  foreach ($rss->entry as $item) {
    preg_match("/live\/videos\/(.*)\?v/", $item->content['src'], $matches);
    $start_time = $item->ytwhen['start'];
    $end_time = $item->ytwhen['end'];
    if (strtotime($end_time) > time()) {
      $live_events[] = array(
        'id' => $matches[1],
        'title' => $item->title,
        'date' => strtotime($start_time)
      $live_event_ids[] = $matches[1];

  usort($live_events, "sort_by_date");
  return $live_events[0];

function recorded_videos() {
  global $live_event_ids;
  $feed = "http://gdata.youtube.com/feeds/api/playlists/" . $GLOBALS['youtube_playlist_id'] . "?alt=rss";
  $feed = file_get_contents($feed);

  $rss = simplexml_load_string($feed);
  $videos = array();
  foreach ($rss->channel->item as $item) {
    $link = str_replace('&feature=youtube_gdata', '', $item->link);
    preg_match("/\?v\=(.*)$/", $link, $matched);

    if (in_array($matched[1], $live_event_ids)) {
    $videos[]= array(
      'id' => $matched[1],
      'title' => $item->title,
      'date' => strtotime($item->pubDate),
      'description' => $item->description,
      'date' => ''
  usort($videos, "sort_by_date");
  return array_reverse($videos);

echo "<channel>";

$live_event = upcoming_live_event();

if (isset($live_event)) {
  echo "<item>";
  echo "<title>Live Video</title>";
  echo "<description><![CDATA[" . date("l, M jS", $live_event['date']) . "
" . date("g A", $live_event['date']) . " EST]]></description>"; echo "<jwplayer:image>YOUR_IMAGE.JPG</jwplayer:image>"; echo "<jwplayer:source type=\"youtube\" file=\"http://youtube.com/watch?v=" . $live_event['id'] . "\"/>"; echo "</item>"; } foreach (recorded_videos() as $video) { echo "<item>"; echo "<title>" . $video['title'] . "</title>"; echo "<description>" . $video['description'] . "</description>"; echo "<jwplayer:source type=\"youtube\" file=\"http://youtube.com/watch?v=" . $video['id'] . "\"/>"; echo "</item>"; } echo "</channel>"; echo "</rss>"; ?>

Hope this helps someone.

Passing custom attributes to mail observer

I was trying to figure out how to pass custom attributes to a Ruby on Rails mail observer (should be the same for an interceptor) and couldn’t find any documentation about it. Since the observer only receives the Mail object as a parameter in


method, we will need to pass the custom attributes through the mail object. One way to do is as follows:

  :to =>'email@sample.com',
  :custom_attr_1 => 'This is my custom string'

And you can receive it in the observer with the following:

def self.delivered_email(mail)
  puts mail.header[:custom_attr_1].value

If you have an interceptor, use the following:

def self.delivering_email(mail)
  puts mail.header[:custom_attr_1].value

I hope this helps someone.

Strong Parameters – Restricting Collection

Recently I was trying to find a way for strong parameters to restrict a collection to the items a user owns but I could not find anything so I decided to do something myself.

I want a Category to accept an array of member_ids but I want them to be only the members the user owns (preventing a user from assigning someone else’s members).

In the controller we expose the members and the category and only use the organization’s members:

class CategoriesController < ApplicationController

  expose(:members) { organization.members }

  expose(:category, attributes: :category_params)

  def new

  def create
    category.members &= members
    if category.save
      redirect_to category_path
      render :new


  def category_params
    params.require(:category).permit(:name, {:member_ids => []})

And now the category will only contain members that the organization (or user) owns. It may not be the most efficient way of doing this so if you have any suggestions please leave a comment.

LiteShops – Create a Shop in 30 Seconds

Over the weekend four of us worked on a Rails Rumble application for the annual Ruby on Rails competition. We decided to create an application that would help with selling things online easily. It is called Lite Shops.

To post a product online, simply:

  1. Take a picture(s) of your item.
  2. Email the picture(s) to sell@liteshops.com with the name as the subject (add a price with a dollar symbol, e.g. $20) and description as the body.
  3. LiteShops will do the rest: Create a shop for you and post your item on LiteShops.com.

Give it a try and tell us what you think. Also, don’t forget to vote/favorite this application at Rails Rumble.