SlideShare une entreprise Scribd logo
1  sur  36
Ultra fastwebdevelopmentwith Classyhatrequired.
Ultra fastwebdevelopmentwith featuring Pedro "Frank" Gaspar Sérgio "Sinatra" Santos
WhatisSinatra?
ThisisSinatra!
A smallwebframework for server-sideapplications inruby sinatrarb.com
Setup
Windows One-ClickInstaller – go to ruby-lang.org Mac OSX (pre-installed, draw a hatinstead) Linux (Ubuntu) sudoapt-getinstallrubyrubygems
InstallSinatra sudogeminstallsinatra Installlibs sudogeminstallerbdm-core dm-sqlite-adapterdm-migrations dm-serializerdm-validationsserialport
HelloNew York
hello.rb: require 'sinatra' get '/' do    "New York, New York" end
ruby–rubygemshello.rb go to http://localhost:4567
Ruby 101
Variables hungry = true answer = 42 cost =  0.99 PI = 3.14 name = "Sérgio Santos" fruit = ['apple', 'banana', 'grape']  # fruit[1] -> 'banana' mix = ['door', 37, 15.2, false] names = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' } names['Sérgio']
Conditions if grade >= 10 puts "Yey!" else puts "humpf" end case minutes_late when 0..5      thenputs "ontime" when 5..15     thenputs "fair" when 15..30  thenputs "late" elseputs "doorclosed" end
Cycles whilenothungry puts "work" end puts "work" whilenothungry 1.upto(10)  {  |n|puts n  } ['ruby', 'python', 'php'].each do |language| puts "I cancode " + language end
Functions defgreetings(names) names.each do |first, last| puts "Hello " + first + " " + last end end names = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' } greetings(names)
Controllers
get '/moon' do      "Fly me to themoon…" end post '/destroy-world' do      "Boom" end get '/hello/:name' do     "Hello " + params[:name] end
Sessions enable :sessions get '/visit' do session[:visits] = 0 unlesssession[:visits]  session[:visits] += 1      "Youvisitedthispage #{session[:visits]} times." end
Filters before do putsrequest.ip end get '/hello' do "Hi!" end get '/bye' do "Bye!" end after do puts "Alldone" end
Templates
Publicfolder All files insidethefolder 'public' are shared Great for static files like javascript, css, images…
get '/hello/:name' do     "Hello " + params[:name] end
get '/hello/:name' do      @name = params[:name] erb :hello end template :hello do       "Hello <%= @name %>" end
get '/hello/:name' do      @name = params[:name] erb :hello end views/hello.erb: Hello <%= @name %>
get '/show' do      @names = ['Sérgio', 'Pedro'] erb :show end views/show.erb: <% if @names.empty? %>     This place is empty. <% else %>    We got:     <% for name in @names %>  <%= name %>  <% end %> <% end %>
views/layout.erb: <html>     <head>         <title>My Sinatra App</title>     </head>     <body>          <%= yield %>     </body> </html>
Database
require 'sinatra' require 'dm-core' require 'dm-migrations' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/event.sqlite3") class Person   include DataMapper::Resource   property :id,        Serial   property :name, String   property :email, String   property :date,    Time,   :default => Time.now end DataMapper.auto_upgrade!
Types Boolean String Text Float Integer Decimal DateTime, Date, Time http://datamapper.org/docs/properties
Operations person = Person.create(:name => 'Sérgio‘, :email => 'me@sergiosantos.info') person = Person.new person.name = 'Sérgio' person.email = 'me@sergiosantos.info' person.save person.update(:name => 'Pedro') person.destroy http://datamapper.org/docs/create_and_destroy
Operations Person.get(5) Person.first( :name => 'Sérgio' ) Person.last Person.all( :name.like => 'Sérgio' ) Person.all( :date.gt => Time.now – 1 * 60 * 60 ) # Last hour http://datamapper.org/docs/find
Serializer require 'dm-serializer' Person.all.to_xml Person.all.to_json Person.all.to_csv Person.all.to_yaml
Validations require 'dm-validations' class Person     include DataMapper::Resource     property :id,        Serial     property :name, String     property :email, String     property :date,    Time,   :default => Time.now validates_length_of :name, :within => 3..100 validates_uniqueness_of :email end http://datamapper.org/docs/validations
Validations get '/' do erb :index end post '/registration' do     @person = Person.create(:name => params['name'], :email => params['email'])     if @person.saved? erb :thanks     else erb :index     end end views/index: <p style="color: red;">     <% for error in @person.errors %>         <%= error %><br/>     <% end %> </p>
Projects

Contenu connexe

Tendances

Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Ryosuke IWANAGA
 
konfigurasi freeradius + daloradius in debian 9
konfigurasi freeradius + daloradius in debian 9konfigurasi freeradius + daloradius in debian 9
konfigurasi freeradius + daloradius in debian 9Walid Umar
 
Presentation of JSConf.eu
Presentation of JSConf.euPresentation of JSConf.eu
Presentation of JSConf.euFredrik Wendt
 
What the web platform (and your app!) can learn from Node.js
What the web platform (and your app!) can learn from Node.jsWhat the web platform (and your app!) can learn from Node.js
What the web platform (and your app!) can learn from Node.jswbinnssmith
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End WorkflowDimitris Tsironis
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesSpin Lai
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPMarc Gear
 
Оптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчикОптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчикAgnislav Onufrijchuk
 
Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Fabio Akita
 
"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TE"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TERyosuke IWANAGA
 
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyPeter Keung
 
Deploying Django with Ansible
Deploying Django with AnsibleDeploying Django with Ansible
Deploying Django with Ansibleandrewmirskynet
 
HTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionHTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionXavier Mertens
 
Puppet Module Reusability - What I Learned from Shipping to the Forge
Puppet Module Reusability - What I Learned from Shipping to the ForgePuppet Module Reusability - What I Learned from Shipping to the Forge
Puppet Module Reusability - What I Learned from Shipping to the ForgePuppet
 
PLOG - Modern Javascripting with Plone
PLOG - Modern Javascripting with PlonePLOG - Modern Javascripting with Plone
PLOG - Modern Javascripting with PloneRok Garbas
 

Tendances (20)

Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意Devsumi2012 攻めの運用の極意
Devsumi2012 攻めの運用の極意
 
konfigurasi freeradius + daloradius in debian 9
konfigurasi freeradius + daloradius in debian 9konfigurasi freeradius + daloradius in debian 9
konfigurasi freeradius + daloradius in debian 9
 
Ruby Postgres
Ruby PostgresRuby Postgres
Ruby Postgres
 
Presentation of JSConf.eu
Presentation of JSConf.euPresentation of JSConf.eu
Presentation of JSConf.eu
 
What the web platform (and your app!) can learn from Node.js
What the web platform (and your app!) can learn from Node.jsWhat the web platform (and your app!) can learn from Node.js
What the web platform (and your app!) can learn from Node.js
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
Puppet Camp 2012
Puppet Camp 2012Puppet Camp 2012
Puppet Camp 2012
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best Practices
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
Оптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчикОптимизация MySQL. Что должен знать каждый разработчик
Оптимизация MySQL. Что должен знать каждый разработчик
 
Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013Ecossistema Ruby - versão SCTI UNF 2013
Ecossistema Ruby - versão SCTI UNF 2013
 
"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TE"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TE
 
Varnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites flyVarnish: Making eZ Publish sites fly
Varnish: Making eZ Publish sites fly
 
Deploying Django with Ansible
Deploying Django with AnsibleDeploying Django with Ansible
Deploying Django with Ansible
 
HTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC EditionHTTP For the Good or the Bad - FSEC Edition
HTTP For the Good or the Bad - FSEC Edition
 
Puppet Module Reusability - What I Learned from Shipping to the Forge
Puppet Module Reusability - What I Learned from Shipping to the ForgePuppet Module Reusability - What I Learned from Shipping to the Forge
Puppet Module Reusability - What I Learned from Shipping to the Forge
 
PLOG - Modern Javascripting with Plone
PLOG - Modern Javascripting with PlonePLOG - Modern Javascripting with Plone
PLOG - Modern Javascripting with Plone
 
Front End Development Tool Chain
Front End Development Tool ChainFront End Development Tool Chain
Front End Development Tool Chain
 
EC2
EC2EC2
EC2
 

En vedette

Cross-lingual ontology lexicalisation, translation and information extraction...
Cross-lingual ontology lexicalisation, translation and information extraction...Cross-lingual ontology lexicalisation, translation and information extraction...
Cross-lingual ontology lexicalisation, translation and information extraction...Tobias Wunner
 
Neo4j And The Benefits Of Graph Dbs 3
Neo4j And The Benefits Of Graph Dbs 3Neo4j And The Benefits Of Graph Dbs 3
Neo4j And The Benefits Of Graph Dbs 3Directi Group
 
kageyama-2550-0728.pptx
kageyama-2550-0728.pptxkageyama-2550-0728.pptx
kageyama-2550-0728.pptxgrssieee
 
Java on Windows Azure
Java on Windows AzureJava on Windows Azure
Java on Windows AzureDavid Chou
 
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows AzureCloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows AzureDavid Chou
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0Sun-Jin Jang
 
NYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
NYC Hadoop Meetup - MapR, Architecture, Philosophy and ApplicationsNYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
NYC Hadoop Meetup - MapR, Architecture, Philosophy and ApplicationsJason Shao
 

En vedette (8)

Cross-lingual ontology lexicalisation, translation and information extraction...
Cross-lingual ontology lexicalisation, translation and information extraction...Cross-lingual ontology lexicalisation, translation and information extraction...
Cross-lingual ontology lexicalisation, translation and information extraction...
 
Cut psd to xthml
Cut psd to xthmlCut psd to xthml
Cut psd to xthml
 
Neo4j And The Benefits Of Graph Dbs 3
Neo4j And The Benefits Of Graph Dbs 3Neo4j And The Benefits Of Graph Dbs 3
Neo4j And The Benefits Of Graph Dbs 3
 
kageyama-2550-0728.pptx
kageyama-2550-0728.pptxkageyama-2550-0728.pptx
kageyama-2550-0728.pptx
 
Java on Windows Azure
Java on Windows AzureJava on Windows Azure
Java on Windows Azure
 
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows AzureCloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0
 
NYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
NYC Hadoop Meetup - MapR, Architecture, Philosophy and ApplicationsNYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
NYC Hadoop Meetup - MapR, Architecture, Philosophy and Applications
 

Similaire à Ultra fast web development with sinatra

Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsMarian Marinov
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleGeoffrey De Smet
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteSriram Natarajan
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909Yusuke Wada
 
Padrino is agnostic
Padrino is agnosticPadrino is agnostic
Padrino is agnosticTakeshi Yabe
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Librariesjeresig
 
Ten modules I haven't yet talked about
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked aboutacme
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Railsdosire
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterCodeIgniter Conference
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeAndrea Cardinale
 
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]Chris Toohey
 
Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesAsao Kamei
 

Similaire à Ultra fast web development with sinatra (20)

Sinatra
SinatraSinatra
Sinatra
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Exploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your pluginsExploiting the newer perl to improve your plugins
Exploiting the newer perl to improve your plugins
 
Web::Scraper
Web::ScraperWeb::Scraper
Web::Scraper
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
 
Capistrano2
Capistrano2Capistrano2
Capistrano2
 
Dynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web siteDynamic Tracing of your AMP web site
Dynamic Tracing of your AMP web site
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 
yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909yusukebe in Yokohama.pm 090909
yusukebe in Yokohama.pm 090909
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Smarty
SmartySmarty
Smarty
 
Padrino is agnostic
Padrino is agnosticPadrino is agnostic
Padrino is agnostic
 
More Secrets of JavaScript Libraries
More Secrets of JavaScript LibrariesMore Secrets of JavaScript Libraries
More Secrets of JavaScript Libraries
 
Ten modules I haven't yet talked about
Ten modules I haven't yet talked aboutTen modules I haven't yet talked about
Ten modules I haven't yet talked about
 
When To Use Ruby On Rails
When To Use Ruby On RailsWhen To Use Ruby On Rails
When To Use Ruby On Rails
 
Writing Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniterWriting Friendly libraries for CodeIgniter
Writing Friendly libraries for CodeIgniter
 
Logstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtimeLogstash for SEO: come monitorare i Log del Web Server in realtime
Logstash for SEO: come monitorare i Log del Web Server in realtime
 
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
10 Things You're Not Doing [IBM Lotus Notes Domino Application Development]
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Cena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 SlidesCena-DTA PHP Conference 2011 Slides
Cena-DTA PHP Conference 2011 Slides
 

Plus de Sérgio Santos

Plus de Sérgio Santos (9)

Launching tech products
Launching tech productsLaunching tech products
Launching tech products
 
Simple MongoDB design for Rails apps
Simple MongoDB design for Rails appsSimple MongoDB design for Rails apps
Simple MongoDB design for Rails apps
 
Rails + mongo db
Rails + mongo dbRails + mongo db
Rails + mongo db
 
Agoge - produtividade & multitasking
Agoge - produtividade & multitaskingAgoge - produtividade & multitasking
Agoge - produtividade & multitasking
 
Ontologias
OntologiasOntologias
Ontologias
 
Workshop Django
Workshop DjangoWorkshop Django
Workshop Django
 
Gestão De Projectos
Gestão De ProjectosGestão De Projectos
Gestão De Projectos
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
Gestor - Casos De Uso
Gestor - Casos De UsoGestor - Casos De Uso
Gestor - Casos De Uso
 

Dernier

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Ultra fast web development with sinatra

  • 2. Ultra fastwebdevelopmentwith featuring Pedro "Frank" Gaspar Sérgio "Sinatra" Santos
  • 5. A smallwebframework for server-sideapplications inruby sinatrarb.com
  • 7. Windows One-ClickInstaller – go to ruby-lang.org Mac OSX (pre-installed, draw a hatinstead) Linux (Ubuntu) sudoapt-getinstallrubyrubygems
  • 8. InstallSinatra sudogeminstallsinatra Installlibs sudogeminstallerbdm-core dm-sqlite-adapterdm-migrations dm-serializerdm-validationsserialport
  • 10. hello.rb: require 'sinatra' get '/' do "New York, New York" end
  • 11. ruby–rubygemshello.rb go to http://localhost:4567
  • 13. Variables hungry = true answer = 42 cost = 0.99 PI = 3.14 name = "Sérgio Santos" fruit = ['apple', 'banana', 'grape'] # fruit[1] -> 'banana' mix = ['door', 37, 15.2, false] names = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' } names['Sérgio']
  • 14. Conditions if grade >= 10 puts "Yey!" else puts "humpf" end case minutes_late when 0..5 thenputs "ontime" when 5..15 thenputs "fair" when 15..30 thenputs "late" elseputs "doorclosed" end
  • 15. Cycles whilenothungry puts "work" end puts "work" whilenothungry 1.upto(10) { |n|puts n } ['ruby', 'python', 'php'].each do |language| puts "I cancode " + language end
  • 16. Functions defgreetings(names) names.each do |first, last| puts "Hello " + first + " " + last end end names = { 'Sérgio' => 'Santos', 'Pedro' => 'Gaspar' } greetings(names)
  • 18. get '/moon' do "Fly me to themoon…" end post '/destroy-world' do "Boom" end get '/hello/:name' do "Hello " + params[:name] end
  • 19. Sessions enable :sessions get '/visit' do session[:visits] = 0 unlesssession[:visits] session[:visits] += 1 "Youvisitedthispage #{session[:visits]} times." end
  • 20. Filters before do putsrequest.ip end get '/hello' do "Hi!" end get '/bye' do "Bye!" end after do puts "Alldone" end
  • 22. Publicfolder All files insidethefolder 'public' are shared Great for static files like javascript, css, images…
  • 23. get '/hello/:name' do "Hello " + params[:name] end
  • 24. get '/hello/:name' do @name = params[:name] erb :hello end template :hello do "Hello <%= @name %>" end
  • 25. get '/hello/:name' do @name = params[:name] erb :hello end views/hello.erb: Hello <%= @name %>
  • 26. get '/show' do @names = ['Sérgio', 'Pedro'] erb :show end views/show.erb: <% if @names.empty? %> This place is empty. <% else %> We got: <% for name in @names %> <%= name %> <% end %> <% end %>
  • 27. views/layout.erb: <html> <head> <title>My Sinatra App</title> </head> <body> <%= yield %> </body> </html>
  • 29. require 'sinatra' require 'dm-core' require 'dm-migrations' DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/event.sqlite3") class Person include DataMapper::Resource property :id, Serial property :name, String property :email, String property :date, Time, :default => Time.now end DataMapper.auto_upgrade!
  • 30. Types Boolean String Text Float Integer Decimal DateTime, Date, Time http://datamapper.org/docs/properties
  • 31. Operations person = Person.create(:name => 'Sérgio‘, :email => 'me@sergiosantos.info') person = Person.new person.name = 'Sérgio' person.email = 'me@sergiosantos.info' person.save person.update(:name => 'Pedro') person.destroy http://datamapper.org/docs/create_and_destroy
  • 32. Operations Person.get(5) Person.first( :name => 'Sérgio' ) Person.last Person.all( :name.like => 'Sérgio' ) Person.all( :date.gt => Time.now – 1 * 60 * 60 ) # Last hour http://datamapper.org/docs/find
  • 33. Serializer require 'dm-serializer' Person.all.to_xml Person.all.to_json Person.all.to_csv Person.all.to_yaml
  • 34. Validations require 'dm-validations' class Person include DataMapper::Resource property :id, Serial property :name, String property :email, String property :date, Time, :default => Time.now validates_length_of :name, :within => 3..100 validates_uniqueness_of :email end http://datamapper.org/docs/validations
  • 35. Validations get '/' do erb :index end post '/registration' do @person = Person.create(:name => params['name'], :email => params['email']) if @person.saved? erb :thanks else erb :index end end views/index: <p style="color: red;"> <% for error in @person.errors %> <%= error %><br/> <% end %> </p>