SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Sérgio Santos

Mehr von 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
 

Kürzlich hochgeladen

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Kürzlich hochgeladen (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

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>