This document contains code for modeling different animals like dogs and sheep as objects in Ruby. It defines an Animal class with attributes like name and position and methods like walk, run, feed. It then defines Dog and Sheep classes that inherit from Animal and override methods like talk to be animal-specific. The code creates a Dog object, sets its attributes, and calls methods to have it talk, fetch things. This provides a concise 3 sentence summary of the key aspects and purpose of the code sample.
Tobias Nyholm "Deep dive into Symfony 4 internals"Fwdays
Symfony is a request and response framework. But what about all that magic that happens around your code? How does security work? Why isn’t autowring slowing things down? And how is it that symfony components can be so decoupled but still play so well together?
I will show you the symfony internals
This talk will go over the architecture of Symfony. We will follow the request and the response paths throw the framework. We will do some stops at the components that are more awesome than others.
This talk is perfect for those who's worked with Symfony or Laravel before. But if you've never touched a framework before, don't worry. You will still learn a lot from this talk.
One criticism of opponents of Perl is that it is a "write-only" language meaning that once the code is written, it is extremely difficult to maintain because it is difficult to understand upon re-examination. As with many criticisms, this should be aimed at those undisciplined developers who are writing the code, and not their tool of choice.
Having said that, I think it is also fair to say that Perl makes it very easy to write difficult-to-decipher code. This is the doubleedged sword which is the shorthand Perl gives us to be very expressive in a small amount of space. A negative application of this is obfuscated Perl (where the author intentionally makes his code difficult to read), while a more positive application is the craft of creating Perl "oneliners" (trying to include a great deal of functionality in a single line of code). A oneliner can be a powerful weapon in the arsenal of a system administrator.
In this talk:
* We'll look at a line of code in a subroutine that is in desperate need of readability changes
* We'll make the code more readable by introducing:
* appropriate whitespace
* different ways of writing the same thing, for example: $array[$#array] vs. $array[-1]
* useful names for variables, versus $index, $j $k $l, etc
* breaking up one line of code into multiple lines
* exploring further improvements through Perl::Critic and by extension Perl::Tidy
This talk will be beginner-friendly.
Passionate programmers have discovered how coding in Perl Six can be playful, imaginative, pleasurable and exhilarating.
This talk includes tasteful illustrations for curious monoglot and polyglot programmers alike.
Discover the Joy of Six!
Arpad Ray's PHPNW08 slides:
Looking at websites from the perspective of potential attackers is a useful technique not only for security professionals.
This talk demonstrates how to use simple PHP scripts to exploit many common security holes in PHP applications, hopefully giving developers a deeper understanding of what it is they are protecting against.
* Getting around common precautions against SQL injection
* Free spam with SMTP injection
* Making a malicious website to exploit PHP sessions
* The holes every attacker hopes for
* Making use of a newly exploited website
Tobias Nyholm "Deep dive into Symfony 4 internals"Fwdays
Symfony is a request and response framework. But what about all that magic that happens around your code? How does security work? Why isn’t autowring slowing things down? And how is it that symfony components can be so decoupled but still play so well together?
I will show you the symfony internals
This talk will go over the architecture of Symfony. We will follow the request and the response paths throw the framework. We will do some stops at the components that are more awesome than others.
This talk is perfect for those who's worked with Symfony or Laravel before. But if you've never touched a framework before, don't worry. You will still learn a lot from this talk.
One criticism of opponents of Perl is that it is a "write-only" language meaning that once the code is written, it is extremely difficult to maintain because it is difficult to understand upon re-examination. As with many criticisms, this should be aimed at those undisciplined developers who are writing the code, and not their tool of choice.
Having said that, I think it is also fair to say that Perl makes it very easy to write difficult-to-decipher code. This is the doubleedged sword which is the shorthand Perl gives us to be very expressive in a small amount of space. A negative application of this is obfuscated Perl (where the author intentionally makes his code difficult to read), while a more positive application is the craft of creating Perl "oneliners" (trying to include a great deal of functionality in a single line of code). A oneliner can be a powerful weapon in the arsenal of a system administrator.
In this talk:
* We'll look at a line of code in a subroutine that is in desperate need of readability changes
* We'll make the code more readable by introducing:
* appropriate whitespace
* different ways of writing the same thing, for example: $array[$#array] vs. $array[-1]
* useful names for variables, versus $index, $j $k $l, etc
* breaking up one line of code into multiple lines
* exploring further improvements through Perl::Critic and by extension Perl::Tidy
This talk will be beginner-friendly.
Passionate programmers have discovered how coding in Perl Six can be playful, imaginative, pleasurable and exhilarating.
This talk includes tasteful illustrations for curious monoglot and polyglot programmers alike.
Discover the Joy of Six!
Arpad Ray's PHPNW08 slides:
Looking at websites from the perspective of potential attackers is a useful technique not only for security professionals.
This talk demonstrates how to use simple PHP scripts to exploit many common security holes in PHP applications, hopefully giving developers a deeper understanding of what it is they are protecting against.
* Getting around common precautions against SQL injection
* Free spam with SMTP injection
* Making a malicious website to exploit PHP sessions
* The holes every attacker hopes for
* Making use of a newly exploited website
How let your PHP application interact with phones through incoming and outgoing SMS and voice calls. This talk uses the Twilio platform and API to show how to send and receive text and voice calls to allow for different interactive options for you and your applications.
Review unknown code with static analysis Zend con 2017Damien Seguy
Code quality is not just for Christmas, it is a daily part of the job. So, what do you do when you're handed with a five feet long pole a million lines of code that must be vetted? You call static analysis to the rescue. During one hour, we'll be reviewing totally unknown code: no name, no usage, not a clue. We'll apply a wide range of tools, reaching for anything that helps us understand the code and form an opinion on it. Can we break this mystery and learn how everyone else is looking at our code?
Beyond php - it's not (just) about the codeWim Godden
Most PHP developers focus on writing code. But creating Web applications is about much more than just wrting PHP. Take a step outside the PHP cocoon and into the big PHP ecosphere to find out how small code changes can make a world of difference on servers and network. This talk is an eye-opener for developers who spend over 80% of their time coding, debugging and testing.
2019 Pune Data Conference
Software smoke testing is a preliminary level of testing. It makes certain that all of the primary components of a system are functioning correctly. For example, when installing a new secured Hadoop cluster, running a series of quick tests to make sure that things like HDFS and MapReduce are operational can save a lot of headache before enabling Kerberos. Smoke tests can also save you time and embarrassment by making sure that things work before you turn the cluster over to your customer.
In this talk, Michael Arnold will explain the utility of testing Hadoop components after cluster builds and software upgrades. Michael will present code examples that you can use to confirm functionality of Spark, Kudu, HBase, Kafka, MapReduce, etc on your cluster.
Phing is a build system that lets you do all sorts of neat things quickly and easily. If you find yourself manually running complicated processes or frequently having to look up command line parameters for your tools, Phing can help make you more efficient. If your deployments have many error-prone steps or you find yourself dealing with fragile procedures, Phing can help keep your sanity.
Using MySQL without Maatkit is like taking a photo without removing the camera's lens cap. Professional MySQL experts use this toolkit to help keep complex MySQL installations running smoothly and efficiently. This session will show you practical ways to use Maatkit every day.
Application Logging in the 21st century - 2014.keyTim Bunce
Slides for my talk at the Austrian Perl Workshop in Salzburg on October 10th.
A video of the talk can be found at https://www.youtube.com/watch?v=4Qj-_eimGuE
How let your PHP application interact with phones through incoming and outgoing SMS and voice calls. This talk uses the Twilio platform and API to show how to send and receive text and voice calls to allow for different interactive options for you and your applications.
Review unknown code with static analysis Zend con 2017Damien Seguy
Code quality is not just for Christmas, it is a daily part of the job. So, what do you do when you're handed with a five feet long pole a million lines of code that must be vetted? You call static analysis to the rescue. During one hour, we'll be reviewing totally unknown code: no name, no usage, not a clue. We'll apply a wide range of tools, reaching for anything that helps us understand the code and form an opinion on it. Can we break this mystery and learn how everyone else is looking at our code?
Beyond php - it's not (just) about the codeWim Godden
Most PHP developers focus on writing code. But creating Web applications is about much more than just wrting PHP. Take a step outside the PHP cocoon and into the big PHP ecosphere to find out how small code changes can make a world of difference on servers and network. This talk is an eye-opener for developers who spend over 80% of their time coding, debugging and testing.
2019 Pune Data Conference
Software smoke testing is a preliminary level of testing. It makes certain that all of the primary components of a system are functioning correctly. For example, when installing a new secured Hadoop cluster, running a series of quick tests to make sure that things like HDFS and MapReduce are operational can save a lot of headache before enabling Kerberos. Smoke tests can also save you time and embarrassment by making sure that things work before you turn the cluster over to your customer.
In this talk, Michael Arnold will explain the utility of testing Hadoop components after cluster builds and software upgrades. Michael will present code examples that you can use to confirm functionality of Spark, Kudu, HBase, Kafka, MapReduce, etc on your cluster.
Phing is a build system that lets you do all sorts of neat things quickly and easily. If you find yourself manually running complicated processes or frequently having to look up command line parameters for your tools, Phing can help make you more efficient. If your deployments have many error-prone steps or you find yourself dealing with fragile procedures, Phing can help keep your sanity.
Using MySQL without Maatkit is like taking a photo without removing the camera's lens cap. Professional MySQL experts use this toolkit to help keep complex MySQL installations running smoothly and efficiently. This session will show you practical ways to use Maatkit every day.
Application Logging in the 21st century - 2014.keyTim Bunce
Slides for my talk at the Austrian Perl Workshop in Salzburg on October 10th.
A video of the talk can be found at https://www.youtube.com/watch?v=4Qj-_eimGuE
A few techniques for everyday Ruby hacking
Touching on the following topics:
DRY Assignment
Ternary operator
Bang bang
Conditional assignment
Parallel assignment
Multiple return
Implied begin
Exception lists
Symbol to Proc
MapReduce
Regex captures
tap
sprintf
case equality
Splat Array
Splat args
blank?
present?
presence
truncate
try
in?
Delegation
delegate
Memoization
memoize
alias_method_chain
class_attribute
HashWithIndifferentAccess
This presentation is for those students and IT professionals who have basic programming knowledge and want to learn Perl basics for Pentesting.
We have explained minimal Perl basics which a pentester should know to write,read,modify Perl scripts for Pentesting like data type, comparison operator, loop controls, minimal CPAN modules related to web and networking, perl scripts in Kali and some demo
General introduction to Elasticsearch at the RubyShift 2013 conference.
Download the source code for demos:
* http://git.io/hello-elasticsearch-ruby
* http://git.io/stackexchange-elasticsearch
Realtime Analytics With Elasticsearch [New Media Inspiration 2013]Karel Minarik
A presentation from the New Media Inspiration 2013 conference (http://www.tuesday.cz/akce/new-media-inspiration-2013/) about using Elasticsearch's faceting features for realtime analytics of big data.
Shell's Kitchen: Infrastructure As Code (Webexpo 2012)Karel Minarik
Slides for the tutorial by Karel Minarik and Vojtech Hyza at the Webexpo 2012 conference.
Please see the GitHub repositories for the code:
* http://git.io/chef-solo-hello-world
* http://git.io/chef-hello-cloud
Interaktivita, originalita a návrhové vzoryKarel Minarik
Přednáška na katedře Studia nových médií (FFUK, prosinec 2006) v rámci kursu "Principy interaktivní tvorby". Interaktivita na současném webu, návrhové vzory a pojetí originality.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Elevating Tactical DDD Patterns Through Object CalisthenicsDorra BARTAGUIZ
After immersing yourself in the blue book and its red counterpart, attending DDD-focused conferences, and applying tactical patterns, you're left with a crucial question: How do I ensure my design is effective? Tactical patterns within Domain-Driven Design (DDD) serve as guiding principles for creating clear and manageable domain models. However, achieving success with these patterns requires additional guidance. Interestingly, we've observed that a set of constraints initially designed for training purposes remarkably aligns with effective pattern implementation, offering a more ‘mechanical’ approach. Let's explore together how Object Calisthenics can elevate the design of your tactical DDD patterns, offering concrete help for those venturing into DDD for the first time!
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Accelerate your Kubernetes clusters with Varnish CachingThijs Feryn
A presentation about the usage and availability of Varnish on Kubernetes. This talk explores the capabilities of Varnish caching and shows how to use the Varnish Helm chart to deploy it to Kubernetes.
This presentation was delivered at K8SUG Singapore. See https://feryn.eu/presentations/accelerate-your-kubernetes-clusters-with-varnish-caching-k8sug-singapore-28-2024 for more details.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
3. ZÁKLADNÍ KONCEPTY
1. Datové typy: čísla, texty, pole, hashe; Přetypování
2. Proměnné a rozsah platnosti
3. Metody a funkce
4. Podmínky a logické operátory
5. Smyčky a iterátory
6. Výjimky — ošetření chyb
7. Vstup
8. Výstup
Úvod do programování Přednáška 5
4. vyjimky.rb
require 'net/http'
server = 'www.lidovky.cz' # vs. www.neexistuje.cz nebo vytazeny sitovy kabel...
begin
response, data = Net::HTTP.new(server).get('/')
rescue Exception
puts quot;Nemohu se připojit na server #{server}quot;
# ...načteme data uložená na disku...
# data = ...
end
puts data.to_s.scan(
/<div class=quot;art openerquot;><h3><a href=quot;.+quot;>(.*)</a></h3>/).to_s
) if data
Úvod do programování Přednáška 5
5. parsovani_html.rb
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'iconv'
server = 'http://www.lidovky.cz' # vs. www.neexistuje.cz nebo vytazeny sitovy kabel...
begin
html = Hpricot( open(server) )
rescue Exception
puts quot;Nemohu se připojit na server #{server}...quot;
exit
end
html.search('div.art.opener h3 a').inner_html
titulek =
puts Iconv.iconv( 'utf-8', 'windows-1250', titulek )
Úvod do programování Přednáška 5
6. parsovani_html.rb
require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'iconv'
server = 'http://www.lidovky.cz' # vs. www.neexistuje.cz nebo vytazeny sitovy kabel...
begin
Hpricot(
html = open(server) )
rescue Exception
puts quot;Nemohu se připojit na server #{server}...quot;
exit
end
html.search('div.art.opener h3 a').inner_html
titulek =
puts Iconv.iconv( 'utf-8', 'windows-1250', titulek )
http://code.whytheluckystiff.net/hpricot/
www.igvita.com/blog/2007/02/04/ruby-screen-scraper-in-60-seconds/
Úvod do programování Přednáška 5
7. nejpouzivanejsi_slovo.rb
text = File.read 'kafka_promena.txt'
# ---> A ted neco trochu jineho... Najdeme nejpouzivanejsi slovo :)
words = text.tr('-,();'quot;', '').split(' ')
current_word = words.sort.first
word_counts = {}
word_counts[current_word] = {}
count = 0
words.sort.each do |word|
if word == current_word
count += 1
else
count = 1
current_word = word
end
word_counts[word] = {:word => word, :count => count}
Když se Řehoř Samsa
end
nejpouzivanejsi = word_counts.sort.first # quot;Nejvetsi = prvniquot; -- [quot;Aquot;, {:count=>37, :word=>quot;Aquot;}]
nepokojných snů, shle
puts quot;Začínáme s quot; + nejpouzivanejsi[1][:word].to_s + quot;.quot;
word_counts.sort.each do |word|
proměnil v jakýsi nestv
nejpouzivanejsi = word if word[1][:count] > nejpouzivanejsi[1][:count]
end
puts quot;Nejpoužívanější slovo je „quot; + nejpouzivanejsi[1][:word] + quot;“ s quot; + nejpouzivanejsi[1][:count].to_s + quot; výskyty.quot;
Úvod do programování Přednáška 5
8. seznam_nejpouzivanejsich_slov.rb
text = File.read 'kafka_promena.txt'
# ---> ... a co seznam slov podle frekvence pouziti?
puts quot;Seznam nejpoužívanějších slov v Kafkově ‚Proměně‘:quot;
most_frequent_words = word_counts.values.collect { |word| [word[:count], word
[:word]] }
most_frequent_words.sort.reverse.each_with_index do |word, i|
puts quot;#{i+1}. #{word[1]}ttt(#{word[0]} výskytů)quot;
end
Když se Řehoř Samsa
nepokojných snů, shle
proměnil v jakýsi nestv
Úvod do programování Přednáška 5
9. nejpouzivanejsi_slovo.rb
1 text = File.read 'kafka_promena.txt'
# ---> A ted neco trochu jineho... Najdeme nejpouzivanejsi slovo :)
words = text.tr('-,();'quot;', '').split(' ')
current_word = words.sort.first
2
word_counts = {}
word_counts[current_word] = {}
count = 0
words.sort.each do |word|
if word == current_word
count += 1
3 else
count = 1
current_word = word
end
word_counts[word] = {:word => word, :count => count}
Když se Řehoř Samsa
end
nejpouzivanejsi = word_counts.sort.first # quot;Nejvetsi = prvniquot; -- [quot;Aquot;, {:count=>37, :word=>quot;Aquot;}]
nepokojných snů, shle
puts quot;Začínáme s quot; + nejpouzivanejsi[1][:word].to_s + quot;.quot;
word_counts.sort.each do |word|
proměnil v jakýsi nestv
nejpouzivanejsi = word if word[1][:count] > nejpouzivanejsi[1][:count]
4
end
puts quot;Nejpoužívanější slovo je „quot; + nejpouzivanejsi[1][:word] + quot;“ s quot; + nejpouzivanejsi[1][:count].to_s + quot; výskyty.quot;
Úvod do programování Přednáška 5
20. Zvíře
Pes Ovce
Úvod do programování Přednáška 5
21. animals.rb
1 require 'pp'
2
3 # *** ANIMALS *****************************************************************
4
5 #-- file Animal.rb
6 class Animal
7
8 attr_accessor :name, :position, :color
9
10 def initialize(name)
11 @name = name
12 @position = 0
13 @stuff_in_belly = 0
14 @walk_increment = 1
15 @run_increment = 10
16 puts quot;Hello, I am a #{self.class.to_s.downcase} named #{self.name}!quot;
17 end
18
19 def talk
20 puts quot;#{self.class}: ...quot;
21
22 end
23
Úvod do programování Přednáška 5
22. animals.rb
24 def walk
25 @position += @walk_increment
26 end
27
28 def run
29 @position += @run_increment
30 end
31
32 def feed
33 @stuff_in_belly += 1
34 puts quot;[Chewing on some stuff and happy...]quot;
35 self.poop if @stuff_in_belly > 3
36 end
37
38 def hungry?
39 if @stuff_in_belly < 2
40 true
41 else
42 false
43 end
44 end
45
Úvod do programování Přednáška 5
23. animals.rb
46 protected
47
48 def poop
49 puts quot;[Too much stuff in belly... pooping...]quot;
50 @stuff_in_belly = 0
51 end
52
53 end
54
55
Úvod do programování Přednáška 5
24. animals.rb
56 #-- file Dog.rb
57 class Dog < Animal
58
59 def initialize(name, color)
60 super(name)
61 @color = color
62 @run_increment = 20
63
64 end
65
66 def talk
67 puts quot;#{self.name}: Woof! woof!quot;
68 end
69
70 def fetch(what='stick')
71 puts quot;[#{self.name} is fetching the #{what.downcase}...]quot;
72 end
73
74 end
75
76
Úvod do programování Přednáška 5
25. animals.rb
77 #-- file Sheep.rb
78 class Sheep < Animal
79
80 def talk
81 puts quot;#{self.name}: Beeeeee!quot;
82 end
83
84 end
85
Úvod do programování Přednáška 5
26. animals.rb
86 # === Dog =====================================================================
87
88 # --- Create a dog
89 dog = Dog.new('Bitzer', 'yellow')
90 pp dog
91
92 # --- Dog's properties (attributes)
93 puts quot;Our dog's name is '#{dog.name}'.quot;
94 puts quot;And his color is #{dog.color}.quot;
95
Úvod do programování Přednáška 5
27. animals.rb
96 # --- Make the dog do something
97 puts quot;> Talk, Bitzer!quot;
98 dog.talk
99
100 puts quot;> Fetch, Bitzer!quot;
101 dog.fetch
102 dog.fetch('Ball')
103
104 puts quot;> Walk, Bitzer!quot;
105 dog.walk
106 puts quot;Dog is at position: #{dog.position}.quot;
107 puts quot;> Run, Bitzer!quot;
108 dog.run
109 puts quot;Dog is at position: #{dog.position}.quot;
110
111 puts quot;> Have a snack, Bitzer!quot;
112 dog.feed
113 puts dog.hungry?
114
115 dog.feed
116 dog.feed
117 puts dog.hungry?
118
119 # dog.poop
120 dog.feed
121
122
Úvod do programování Přednáška 5
30. DOMÁCÍ ÚKOL
Navrhněte a naprogramujte třídu TextAnalyzer
TextAnalyzer:
text
•
• characters
• words
• pages
• unique_words
• most_frequent_words
• most_frequent_word
Úvod do programování Přednáška 5
32. PŘÍKLAD
Návrhový vzor ActiveRecord
tabulka people
ID Name Surname E-mail
1 John Smith smith@hotmail.com
2 Susanna Reddick susan@yahoo.com
INSERT INTO people (name, surname, email) VALUES( 'John', 'Smith', 'smith@hotmail.com' );
SELECT * FROM people;
SELECT * FROM people WHERE id = 1;
SELECT * FROM people WHERE surname = 'Smith';
# ActiveRecord::Base.establish_connection ..
Person.create(:name => 'John', :surname => 'Smith', :email => 'smith@hotmail.com')
Person.find(:all)
Person.find(1)
Person.find_by_name('Smith')
Úvod do programování Přednáška 5