Skip to content

Instantly share code, notes, and snippets.

unless params[:name].empty? and params[:msg].empty?
if params[:msg].length <= 140 and params[:name]. length <= 10
$msgs << [params[:name],params[:msg]]
"Send success!<a href=\"/\">Go to home!</a>"
else
"Error! Big message or name: #{params[:name]} say \"#{params[:msg]}\"<br/><a href=\"/\">Go to home!</a>}"
end
else
"Empty!<a href=\"/\">Go to home!</a>"
end
@AlexTalker
AlexTalker / app.rb
Created February 2, 2014 15:01
Don't added a link to next/previous page ( string 35
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
# TODO: rewrite it to class
form = <<TEXT
<form action="/post" method="POST">
Name: <input name="name" value="" size="10"><br>
Message: <input name="msg" value="" size="140"><br>
<center><input type="submit"></center>
@AlexTalker
AlexTalker / example.erb
Created February 3, 2014 11:00
How to right used this feathure erb?
<%5.times do |n|%>
<a href='/ads'>Pay <%=n%> ads for you site here!</a>
<%end>
@AlexTalker
AlexTalker / example.rb
Created February 4, 2014 00:37
this code pasted template :user in :admin_layout, and resilt in :main_layout?
erb :main_layout, :layout => false do
erb :admin_layout do
erb :user
end
end
@AlexTalker
AlexTalker / 404.rb
Created February 4, 2014 02:27
Hmmm, server crashed with error: TypeError at /stream/1000000.25 exception class/object expected file: app.rb location: raise line: 35
#!/usr/bin/env ruby
require 'rubygems'
require 'erb'
require 'sinatra'
enable :sessions
$msgs = Array.new
# added a explot guard
@AlexTalker
AlexTalker / form.erb
Created February 4, 2014 17:09
why this code crashed?
<form action='/post' method='POST'>
Name: <input name='name' value='<%unless session[:name].empty? do%><%=session[:name]%><%end%>' size='10'><br/>
Message: <input name='msg' value='<%unless session[:msg].empty? do%><%=session[:msg]%><%end%>' size='140'><br/>
<input type='submit'>
</form>
<br/>
require 'sequel'
DB = "sqlite://application.db"
def added_message(name, msg)
# added a message in posts database
Sequel.connect(DB) do |db|
posts = db[:posts]
posts.insert(:time => Time.now.to_s, :name => name, :msg => msg)
end
end
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
{
"translator": "NCase",
"app": {
"name": "Nothing To Hide",
"subtitle": "an anti-stealth game where you are your own watchdog.",
"longtitle": "Nothing To Hide: an anti-stealth game where you are your own watchdog."
},
"menu": {
"play": "PLAY",
"support": "SUPPORT & SHARE",