Skip to content

Instantly share code, notes, and snippets.

@mthadley
Created March 29, 2020 01:24
Show Gist options
  • Save mthadley/ea20aa453f1544be0dac118156bb2b58 to your computer and use it in GitHub Desktop.
Save mthadley/ea20aa453f1544be0dac118156bb2b58 to your computer and use it in GitHub Desktop.
The Randomizer™️
#! /usr/bin/env nix-shell
#! nix-shell -i ruby -p ruby bundler --pure
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-20.03.tar.gz
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem 'sinatra'
gem 'thin'
gem 'haml'
end
get '/' do
haml :index
end
post '/' do
@choices = params[:choices]
@choice = params[:choices].
strip.
split(/\n+/).
sample
haml :index
end
Sinatra::Application.run!
__END__
@@ index
:css
textarea {
min-height: 400px;
}
.alert-success {
color: green;
}
- if @choice
%h2.alert-success
= "The winner is \"#{@choice}\"!"
%form{action: "/", method: "POST"}
%label
Choices
%div
%textarea{name: "choices",
required: true}
= @choices
%button{type: "submit"}= "Randomize!"
@@ layout
%html
%head
%title= "Randomizer"
%body
%h1
The Randomizer
%p
Enter some choices below, separating each one with a newline.
= yield
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment