Your own (little) gem: building an online business with Ruby

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites

    Your own (little) gem: building an online business with Ruby - Presentation Transcript

    1. Your own gem (little) building an online business with Ruby Lindsay Holmwood <lindsay@holmwood.id.au>
    2. (.com)
    3. business development operations
    4. have an idea
    5. check that it’s profitable
    6. apples oranges are both fruit
    7. web store book shop are both businesses
    8. financials
    9. are important.
    10. do them!
    11. (conservative estimates are best)
    12. check your tech
    13. time is an expense
    14. halve your deliverables
    15. then halve them again
    16. 1-2 core features
    17. write ideas down
    18. development
    19. Merb (merbivore.com) development
    20. Merb (merbivore.com) DataMapper (datamapper.org) development
    21. Merb (merbivore.com) DataMapper (datamapper.org) MooTools (mootools.net) development
    22. development
    23. bootstrap
    24. $ sudo gem install merb-core merb-more bootstrap
    25. $ sudo gem install merb-core merb-more $ sudo gem install dm-core dm-more do_sqlite3 bootstrap
    26. $ sudo gem install merb-core merb-more $ sudo gem install dm-core dm-more do_sqlite3 $ merb-gen app schoonerwatch.com bootstrap
    27. $ sudo gem install merb-core merb-more $ sudo gem install dm-core dm-more do_sqlite3 $ merb-gen app schoonerwatch.com $ cd schoonerwatch.com bootstrap
    28. $ sudo gem install merb-core merb-more $ sudo gem install dm-core dm-more do_sqlite3 $ merb-gen app schoonerwatch.com $ cd schoonerwatch.com $ bzr init ; bzr add $ bzr commit -m \"initial commit\" bootstrap
    29. $ sudo gem install merb-core merb-more $ sudo gem install dm-core dm-more do_sqlite3 $ merb-gen app schoonerwatch.com $ cd schoonerwatch.com $ bzr init ; bzr add $ bzr commit -m \"initial commit\" s/bzr/git/g bootstrap
    30. merb-gen
    31. $ merb & merb-gen
    32. $ merb & $ merb-gen resource pub merb-gen
    33. $ merb & $ merb-gen resource pub $ bzr commit -m \"added merb-gen'd pub resource\" merb-gen
    34. $ merb & $ merb-gen resource pub $ bzr commit -m \"added merb-gen'd pub resource\" $ vim spec/spec.opts spec/spec_helper.rb merb-gen
    35. --colour --format profile spec/spec.opts
    36. ... Spec::Runner.configure do |config| config.include(Merb::Test::ViewHelper) config.include(Merb::Test::RouteHelper) config.include(Merb::Test::ControllerHelper) end DataMapper.auto_migrate! spec/spec_helper.rb
    37. run specs
    38. $ rake spec:request run specs
    39. $ rake spec:request .**...... Pending: resource(:pubs) GET contains a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:21 resource(:pubs) GET has a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:33 Finished in 0.322787 seconds 9 examples, 0 failures, 2 pending run specs
    40. request specs
    41. $ vim spec/requests/pubs_spec.rb request specs
    42. $ vim spec/requests/pubs_spec.rb ... it \"contains a sorted list of pubs\" do @response.should have_xpath(\"//h3[contains(.,'Cheapest')]\") @response.should have_xpath(\"//h3[contains(.,'Nearest')]\") end request specs
    43. run specs
    44. $ rake spec:request run specs
    45. $ rake spec:request Pending: resource(:pubs) GET has a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:33 1) 'resource(:pubs) GET contains a sorted list of pubs' FAILED expected following text to match xpath //h3[contains(.,'Cheapest')]’ ./spec/requests/pubs_spec.rb:21: Finished in 0.411139 seconds 9 examples, 1 failure, 1 pending run specs
    46. haml
    47. $ vim config/dependencies.rb haml
    48. $ vim config/dependencies.rb ... dependency \"merb-haml\", merb_gems_version haml
    49. $ vim config/dependencies.rb ... dependency \"merb-haml\", merb_gems_version $ vim config/init.rb haml
    50. $ vim config/dependencies.rb ... dependency \"merb-haml\", merb_gems_version $ vim config/init.rb ... use_template_engine :haml haml
    51. hamlise view
    52. $ bzr mv app/views/pubs/index.html.erb \\ app/views/pubs/index.html.haml hamlise view
    53. $ bzr mv app/views/pubs/index.html.erb \\ app/views/pubs/index.html.haml $ vim app/views/pubs/index.html.haml hamlise view
    54. $ bzr mv app/views/pubs/index.html.erb \\ app/views/pubs/index.html.haml $ vim app/views/pubs/index.html.haml %h3 Nearest %h3 Cheapest hamlise view
    55. $ bzr mv app/views/pubs/index.html.erb \\ app/views/pubs/index.html.haml $ vim app/views/pubs/index.html.haml %h3 Nearest %h3 Cheapest $ rake spec:request Pending: resource(:pubs) GET has a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:33 Finished in 0.389194 seconds 9 examples, 0 failures, 1 pending hamlise view tests pass!
    56. model specs
    57. $ vim spec/models/pubs_spec.rb model specs
    58. $ vim spec/models/pubs_spec.rb 1. model specs
    59. $ vim spec/models/pubs_spec.rb 1. it \"should have name, address, price\" do @pubs.each do |pub| pub.name.should_not be_nil pub.address.should_not be_nil pub.price.should_not be_nil end end model specs
    60. $ vim spec/models/pubs_spec.rb 2. it \"should handle different url formats\" do @pubs.each do |pub| pub.url = 'mygreatpub.com.au' pub.save.should be_true pub.url = 'http://mygreatpub.com.au/' pub.save.should be_true end end model specs
    61. $ vim spec/models/pubs_spec.rb 3. it \"should consistently format + store urls\" do @pubs.each do |pub| adjective = %w[great swanky awesome stylish][rand(4)] pub.url = \"#{adjective}pub.com.au\" pub.save.should be_true pub.url.should =~ /^http:\\/\\/.+\\/$/ end end model specs
    62. model specs
    63. $ vim spec/models/pubs_spec.rb before(:each) do @pubs = 10.of { Pub.generate } end model specs
    64. $ vim spec/models/pubs_spec.rb before(:each) do @pubs = 10.of { Pub.generate } end $ vim spec/spec_fixtures.rb require 'dm-sweatshop' Pub.fixture do { :name => ( name = %w[John Jane Jerry Justin][rand(4)] + \"'s Pub\"), :price => (1..30).to_a[rand(30)], :address => \"#{(40..166).to_a[rand(126)]} Spring \" + %w[Street Road Avenue][rand(3)], :url => \"http://#{name.gsub(/\\W/, '').downcase}.com/\" } end model specs
    65. run specs
    66. $ rake spec:models run specs
    67. $ rake spec:models 1) NameError in 'Pub should have name, address, price' address= is not a public property 2) NameError in 'Pub should handle different url formats' address= is not a public property 3) NameError in 'Pub should consistently format + store urls' address= is not a public property Finished in 0.252169 seconds 3 examples, 3 failures run specs
    68. define properties
    69. $ vim app/models/pub.rb define properties
    70. $ vim app/models/pub.rb class Pub include DataMapper::Resource property :id, Serial property :name, String, :nullable => false property :address, String, :nullable => false property :price, BigDecimal, :nullable => false property :url, String define properties
    71. $ vim app/models/pub.rb ... def url=(string) string = \"http://#{string}\" unless string =~ /^http:\\/\\/.+\\// string += '/' unless string =~ /\\/$/ @url = string end end custom setter
    72. run specs
    73. $ rake spec:models run specs
    74. $ rake spec:models Finished in 0.488351 seconds 3 examples, 0 failures run specs win!
    75. request specs
    76. $ vim spec/requests/pubs_spec.rb request specs
    77. $ vim spec/requests/pubs_spec.rb ... it \"contains a list of cheapest pubs\" do @response.should have_xpath(\"//div[@id=’cheapest’]\") @response.should have_xpath(\"//div[@id=’cheapest’]//table//tr//td[@class='name']\") @response.should have_xpath(\"//div[@id=’cheapest’]//table//tr//td[@class='address']\") @response.should have_xpath(\"//div[@id=’cheapest’]//table//tr//td[contains(@class,'price')]\") end request specs
    78. run specs
    79. $ rake spec:request run specs
    80. $ rake spec:request Pending: resource(:pubs) GET has a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:37 1) 'resource(:pubs) GET contains a list cheapest pubs' FAILED expected following text to match xpath //div[@id='cheapest'] ./spec/requests/pubs_spec.rb:26: Finished in 0.411139 seconds 10 examples, 1 failure, 1 pending run specs
    81. build partial
    82. $ vim app/views/pubs/index.html.haml build partial
    83. $ vim app/views/pubs/index.html.haml %h3 Nearest %h3 Cheapest %div#cheapest = partial \"cheapest\" build partial
    84. $ vim app/views/pubs/index.html.haml %h3 Nearest %h3 Cheapest %div#cheapest = partial \"cheapest\" $ vim app/views/pubs/_cheapest.html.haml build partial
    85. $ vim app/views/pubs/index.html.haml %h3 Nearest %h3 Cheapest %div#cheapest = partial \"cheapest\" $ vim app/views/pubs/_cheapest.html.haml %table - @pubs.each_with_index do |pub, index| %tr %td.name= link_to pub.name, pub.url %td.address= pub.address %td{:class => \"price cheapest-#{index}\"} = '$' + sprintf(\"%.2f\", pub.price) build partial
    86. run specs
    87. $ rake spec:request run specs
    88. $ rake spec:request Pending: resource(:pubs) GET has a list of pubs (TODO) Called from ./spec/requests/pubs_spec.rb:37 Finished in 0.854704 seconds 10 examples, 0 failures, 1 pending run specs
    89. nearest
    90. $ vim app/views/pubs/index.html.haml nearest
    91. $ vim app/views/pubs/index.html.haml %h3 Nearest %div#nearest = partial \"nearest\" %h3 Cheapest %div#cheapest = partial \"cheapest\" nearest
    92. $ vim app/views/pubs/index.html.haml %h3 Nearest %div#nearest = partial \"nearest\" %h3 Cheapest %div#cheapest = partial \"cheapest\" $ vim app/views/pubs/_nearest.html.haml nearest
    93. $ vim app/views/pubs/index.html.haml %h3 Nearest %div#nearest = partial \"nearest\" %h3 Cheapest %div#cheapest = partial \"cheapest\" $ vim app/views/pubs/_nearest.html.haml %div#map{:style => \"width: 800px; height: 600px; margin: auto;\"} nearest
    94. global layout
    95. $ vim app/views/layout/application.html.erb global layout
    96. $ vim app/views/layout/application.html.erb <%= js_include_tag 'mootools' %> <%= js_include_tag 'SimpleTabs' %> <%= js_include_tag 'application' %> <script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key= <%= Merb.config.gmaps_api_key %>\" type=\"text/javascript\"></script> global layout
    97. $ vim app/views/layout/application.html.erb <%= js_include_tag 'mootools' %> <%= js_include_tag 'SimpleTabs' %> <%= js_include_tag 'application' %> <script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key= <%= Merb.config.gmaps_api_key %>\" type=\"text/javascript\"></script> $ vim config/environments/development.rb c[:gmaps_api_key] = \"foo\" api key
    98. $ vim app/views/layout/application.html.erb <%= js_include_tag 'mootools' %> <%= js_include_tag 'SimpleTabs' %> <%= js_include_tag 'application' %> <script src=\"http://maps.google.com/maps?file=api&amp;v=2&amp;key= <%= Merb.config.gmaps_api_key %>\" type=\"text/javascript\"></script> $ vim config/environments/production.rb c[:gmaps_api_key] = \"bar\" production api key
    99. $ vim public/javascripts/application.js window.addEvent('domready', function() { }); nearest
    100. $ vim public/javascripts/application.js window.addEvent('domready', function() { if (GBrowserIsCompatible()) { var map = new GMap2($(\"map\")); map.enableScrollWheelZoom(); map.setCenter(new GLatLng(-33.86336, 151.207151), 12); var geocoder = new GClientGeocoder(); /* geocode top-ten addresses */ $$('div#cheapest tr').each( function(element) { showAddress(map, geocoder, element); }); } }); dash o’ javascript
    101. $ vim public/javascripts/application.js function showAddress(map, geocoder, element) { var name = element.getElements('td.name a').get('html'); var address = element.getChildren('td.address').get('html'); var price = element.getElements('td.price').get('html'); var link = element.getElements('td.name a').get('href'); geocoder.getLatLng(address, function(point) { if (point) { var marker = new GMarker(point); marker.bindInfoWindowHtml(\"<h4>\" + name + \"</h4>\" + ... ); map.addOverlay(marker); } }); } custom geocoder
    102. some stylesheet foo
    103. slices freezing param-protection action-args
    104. operations
    105. monitoring
    106. collectd
    107. lightweight statistics collection daemon
    108. lightweight statistics collection daemon
    109. LoadPlugin cpu LoadPlugin df LoadPlugin disk LoadPlugin interface LoadPlugin load LoadPlugin memory LoadPlugin network LoadPlugin processes LoadPlugin rrdtool LoadPlugin socket LoadPlugin swap LoadPlugin users ...
    110. <Plugin df> MountPoint \"/\" </Plugin> <Plugin interface> Interface \"eth0\" Interface \"eth1\" </Plugin> ...
    111. <Plugin rrdtool> DataDir \"/var/lib/collectd/rrd\" CacheTimeout 180 CacheFlush 7200 </Plugin> <Plugin network> Server \"my.monitoring.server.net\" # Port 25826 </Plugin> ...
    112. <Plugin processes> Process \"ruby\" # Process \"mysqld\" </Plugin> ...
    113. eek!
    114. collectd-nagios
    115. $ /usr/bin/collectd-nagios \\ -s /var/run/collectd/socket \\ -n cpu-0/cpu-idle \\ -H my.server.com \\ -w 40: -c 10: 0 critical, 1 warning, 0 okay | value=34.000000;;;; $ /usr/bin/collectd-nagios \\ -s /var/run/collectd/socket \\ -n df/df-root -H my.server.com \\ -d free -c 314572800: -w 524288000: 0 critical, 0 warning, 1 okay |free=924288000.0;;;;
    116. 0 good 1 bad 2 ugly
    117. $ ls /var/lib/collectd/rrd/my.server.com cpu-0 cpu-1 df disk-sda disk-sda1 interface load memory swap users
    118. apache apcups apple sensors ascent battery cpu cpufreq csv df disk dns email entropy exec filecount hddtemp interface iptables ipmi ipvs irqs libvirt load logfile mbmon memcached memory multimeter mysql netlink network nfs nginx notify_desktop notify_email ntpd nut onewire perl ping postgresql powerdns processes rrdtool sensors serial snmp swap syslog tail tape tcpconns teamspeak2 thermal unixsock users uuid vmem vserver wireless
    119. apache apcups apple sensors ascent battery cpu cpufreq csv df disk dns email entropy exec filecount hddtemp interface iptables ipmi ipvs irqs libvirt load logfile mbmon memcached memory multimeter mysql netlink network nfs nginx notify_desktop notify_email ntpd nut onewire perl ping postgresql powerdns processes rrdtool sensors serial snmp swap syslog tail tape tcpconns teamspeak2 thermal unixsock users uuid vmem vserver wireless
    120. configuration management
    121. Puppet language => client/server => library
    122. manifests types classes nodes
    123. manifests => describe types classes nodes
    124. manifests types => manage classes nodes
    125. package { apache2: ensure => present }
    126. package { apache2: ensure => present } file { \"/etc/apache2/apache2.conf\", content => template(\"/etc/puppet/ config/classes/httpd_server/ httpd.conf.erb\"), mode => 644 }
    127. package { apache2: ensure => present } file { \"/etc/apache2/apache2.conf\", content => template(\"/etc/puppet/ config/classes/httpd_server/ httpd.conf.erb\"), mode => 644 } service { apache2: ensure => running, subscribe => File[\"/etc/apache2/ apache2.conf\"] }
    128. manifests types => manage classes nodes
    129. manifests types classes => group nodes
    130. package { apache2: ensure => present } # ...
    131. class apache2 { package { apache2: ensure => present } # ... }
    132. class passenger inherits apache2 { package { libapache2-mod-passenger: ensure => present } # ... }
    133. define apache2 ($port) { package { apache2: ensure => present } # ... }
    134. manifests types classes => group nodes
    135. manifests types classes nodes => apply
    136. node \"srv01.skippy.com\" { include passenger }
    137. node \"srv01.skippy.com\" { include passenger }
    138. node \"srv01.skippy.com\" { include passenger } node \"server02.skippy.com\" { include passenger } node \"server03.skippy.com\" { include passenger }
    139. node \"merbnode\" { include passenger } node \"server01.skippy.com\" inherits passenger {} node \"server02.skippy.com\" inherits passenger {} node \"server03.skippy.com\" { include customisation }
    140. versionable infrastructure
    141. versionable infrastructure (for free)
    142. $ cd skippy.puppet.lindsay $ git init # puppet magic happens $ git push
    143. # puppetd --test --debug
    144. resources
    145. getting real seth godin wiki.merbivore.com
    146. Thank you! (and questions)

    + Lindsay HolmwoodLindsay Holmwood, 11 months ago

    custom

    1104 views, 2 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1104
      • 1104 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 41
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories