Skip to content

Instantly share code, notes, and snippets.

@zorbash
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save zorbash/9198362 to your computer and use it in GitHub Desktop.

Select an option

Save zorbash/9198362 to your computer and use it in GitHub Desktop.
experiment with sinatra
require 'sinatra'
require 'json'
require 'sqlite3'
get '/songs/random' do
db = SQLite3::Database.new '/var/www/apps/shared/songs.db'
row = db.execute('SELECT * FROM songs ORDER BY RANDOM() LIMIT 1;')[0]
song = {
id: row[0],
artist: row[1],
title: row[2],
listen_url: row[3],
post_url: row[4],
tags: row[5],
created_at: row[6]
}
JSON::generate song
end
get '/words/random' do
JSON::generate word: `shuf /usr/share/dict/words | head -1`.chomp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment