Skip to content

Instantly share code, notes, and snippets.

@judithhinlung
Last active January 10, 2017 06:30
Show Gist options
  • Save judithhinlung/fd628e332dd59e088cecbad5b18d4e31 to your computer and use it in GitHub Desktop.
Save judithhinlung/fd628e332dd59e088cecbad5b18d4e31 to your computer and use it in GitHub Desktop.
simple sinatra server

Run these commands:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable
. ~/.rvm/scripts/rvm 
rvm install 2.1.0
gem install bundler
bundle
bundle exec ruby hi.rb
source 'https://rubygems.org'
gem 'sinatra'
gem 'octokit'
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.8)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
multipart-post (2.0.0)
octokit (4.2.0)
sawyer (~> 0.6.0, >= 0.5.3)
rack (1.6.4)
rack-protection (1.5.3)
rack
sawyer (0.6.0)
addressable (~> 2.3.5)
faraday (~> 0.8, < 0.10)
sinatra (1.4.7)
rack (~> 1.5)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
tilt (2.0.2)
PLATFORMS
ruby
DEPENDENCIES
octokit
sinatra
BUNDLED WITH
1.11.2
$ gist --help
Gist (v4.2.0) lets you upload to https://gist.github.com/
The content to be uploaded can be passed as a list of files, if none are
specified STDIN will be read. The default filename for STDIN is "a.rb", and all
filenames can be overridden by repeating the "-f" flag. The most useful reason
to do this is to change the syntax highlighting.
If you'd like your gists to be associated with your GitHub account, so that you
can edit them and find them in future, first use `gist --login` to obtain an
Oauth2 access token. This is stored and used by gist in the future.
Private gists do not have guessable URLs and can be created with "-p", you can
also set the description at the top of the gist by passing "-d".
Anonymous gists are not associated with your GitHub account, they can be created
with "-a" even after you have used "gist --login".
If you would like to shorten the resulting gist URL, use the -s flag. This will
use GitHub's URL shortener, git.io. You can also use -R to get the link to the
raw gist.
To copy the resulting URL to your clipboard you can use the -c option, or to
just open it directly in your browser, use -o. Using the -e option will copy the
embeddable URL to the clipboard. You can add `alias gist='gist -c'` to your
shell's rc file to configure this behaviour by default.
Instead of creating a new gist, you can update an existing one by passing its ID
or URL with "-u". For this to work, you must be logged in, and have created the
original gist with the same GitHub account.
Usage: gist [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
gist --login
--login Authenticate gist on this computer.
-f, --filename [NAME.EXTENSION] Sets the filename and syntax type.
-t, --type [EXTENSION] Sets the file extension and syntax type.
-p, --private Makes your gist private.
--no-private
-d, --description DESCRIPTION Adds a description to your gist.
-s, --shorten Shorten the gist URL using git.io.
-u, --update [ URL | ID ] Update an existing gist.
-a, --anonymous Create an anonymous gist.
-c, --copy Copy the resulting URL to the clipboard
-e, --embed Copy the embed code for the gist to the clipboard
-o, --open Open the resulting URL in a browser
--no-open
-P, --paste Paste from the clipboard to gist
-R, --raw Raw url of the new gist
-h, --help Show this message.
-v, --version Print the version.
require 'sinatra'
require 'octokit'
set :bind, '0.0.0.0'
set :views, "."
helpers do
def h(text)
Rack::Utils.escape_html(text)
end
end
get '/:username' do |username|
gists = Octokit.gists username, :per_page => 5
tuples = []
gists.each do |g|
g[:files].fields.each do |f|
data = g[:files][f].rels[:raw].get.data
tuples << [ f, data ]
end
end
erb :index, locals: { :tuples => tuples, username: username }
end
get '/' do
"Try adding a GitHub username to the URL..."
end
get "/favicon.ico" do
end
<html>
<body>
<h2>User <%= username %>'s last five gists</h2>
<% tuples.each do |t| %>
<div>
<span><b><%= t[0] %></b>:</span>
<span><%= h t[1] %></span>
</div>
<% end %>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment