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

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Dernier (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
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
 
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
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

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>