Skip to content

Instantly share code, notes, and snippets.

@cheald
Last active December 15, 2015 09:59
Show Gist options
  • Save cheald/5242227 to your computer and use it in GitHub Desktop.
Save cheald/5242227 to your computer and use it in GitHub Desktop.
require 'rack'
require 'erb'
def normalize(token)
token.strip.upcase.gsub(/[^\w]/, '')
end
def nurble_token(token)
NOUNS[normalize token] && token || NURBLE
end
NURBLE = '<span class="nurble">nurble</span>'
NOUNS = Hash[open('nouns.txt').lines.map {|line| [normalize(line), 1] }]
TEMPLATE = ERB.new open("template.erb").read
def nurble(text)
text.split(/(\s+)/).map {|w| w.strip.length > 0 ? nurble_token(w) : w }.join(" ").gsub(/\n/, '<br>')
end
app = proc {|rack|
request = Rack::Request.new(rack)
@text = nurble request["text"] if request["text"]
[ 200, {'Content-Type' => 'text/html'}, [TEMPLATE.result(binding)] ]
}
run app
<html>
<head>
<title>Nurblizer</title>
<link href='/style.css' rel='stylesheet' type='text/css' />
</head>
<body>
<div class='ad'>
<script type='text/javascript'>
//<![CDATA[
google_ad_client = "ca-pub-6075374749119067";
/* Nurblizer */
google_ad_slot = "7853244668";
google_ad_width = 728;
google_ad_height = 90;
//]]>
</script>
<script src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></script>
</div>
<div class='container'>
<h1>Nurblizer</h1>
<form action='/nurble' method='post'>
<fieldset>
<ul>
<li>
<label>Text to nurblize:</label>
<textarea name='text'></textarea>
</li>
<li>
<input type='submit' value='Nurblize Away!' />
</li>
</ul>
</fieldset>
</form>
<p>
<a href='http://www.smbc-comics.com/?id=2779'>wtf?</a>
</p>
<h1>Your Nurbled Text</h1>
<div><%=Rack::Utils.h @text %></div>
<p>
<a href='/'>&lt;&lt; Back</a>
</p>
<div class='ad'>
</div>
<script type='text/javascript'>
//<![CDATA[
google_ad_client = "ca-pub-6075374749119067";
/* Nurblizer */
google_ad_slot = "7853244668";
google_ad_width = 728;
google_ad_height = 90;
//]]>
</script>
<script src='http://pagead2.googlesyndication.com/pagead/show_ads.js'></script>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment