Ruby

Mostafa Menessy & Hesham shabana
Outline
- Ruby Building Blocks
Bot Network
- Code Samples
Ruby On Rails
PE Packer
- Advantages/Disadvantages Of Ruby
- Rub...
Ruby Building Blocks - Data types
- Built-in data types aren’t declared
x=5 ; y = “10” ; z = [] , f = { "a" => 100, :b => ...
Ruby Building Blocks - Control Flow
CONDITIONS :
:
if tall < 150
puts "You can’t be a pilot"
elsif tall > 220
puts "You’re...
Ruby Building Blocks-LOOPS/BLOCKS
5.times do ...code to loop here... end
5.times { ...code to loop here... }
1.upto(5) { ....
Ruby Building Blocks -

OOP

- All of the constructs of the language are
treated as objects. Checking the data types is
do...
Packets through a Bot

Primitive C&C Network
Cont’d -- Payload
Who hates Vodafone ?
What is Rails
- Open source web application framework
written in Ruby language
- Built using the MVC pattern
Rails Application
- Convention over configuration
- DRY
- save time
- reuse code
- maintain

rails [app_name] -d mysql
Folder structure
app/

Contains the controllers, models, views, helpers, mailers and assets for your application.

app/con...
The MVC pattern
The Model View Controller principle divides the
work of an application into three separate but
closely coo...
The MVC pattern
MVC - Model
Rails Active Record
- Rails Active Record is the Object/Relational Mapping
(ORM) layer: tables map to classes,...
MVC - Model: Implementation
rails generate model book
Associations: (one-to-one, one-to-many)
class Book < ActiveRecord::B...
MVC - Controller
- Separates business
logic from the presentation.
- rails generate controller book

class BookController ...
MVC - Controller: Implementation
Implementing the list Method:
def list
@books = Book.find(:all)
end

Implementing the sho...
MVC - View
- A Rails View shares data
with controllers through
accessible variables.

<% … %>

Execute a ruby code

<%=…%>...
Routes
Route:
match ':controller(/:action(/:id))(.:format)'
http://mysite/user/get/5
http://mysite/article/ruby-on-rails.h...
All together
Portable executable Encryption
Primitive PE Protector

- Encrypt the .text section data
- Append a new stub section for de...
[(Disa)|A]dvantages Of Ruby
- Senior Ruby on Rails engineer: One of the top 5 jobs in Silicon Valley
- Perfectly suits the...
Cont’d
- Original MRI is relatively slow
- Errors don’t help so much in fixing problems

Different Implementations: Does i...
Ruby Internals ( Extra )
Is it really an interpreter ? 1.8 <= Ruby version

- Its own custom tokenization code
- LALR Biso...
Cont’d

Extract from Ruby Under A microscope
Questions

?
Upcoming SlideShare
Loading in …5
×

Ruby On Rails

839 views

Published on

Ruby On Rails

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
839
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
11
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Ruby On Rails

  1. 1. Ruby Mostafa Menessy & Hesham shabana
  2. 2. Outline - Ruby Building Blocks Bot Network - Code Samples Ruby On Rails PE Packer - Advantages/Disadvantages Of Ruby - Ruby Internals ( if there is enough time )
  3. 3. Ruby Building Blocks - Data types - Built-in data types aren’t declared x=5 ; y = “10” ; z = [] , f = { "a" => 100, :b => 5 } x = Array.new ; x = [] ; x << "Word" ; puts x.pop ; puts x.length - Data types can dynamically change during runtime execution. - Constants are defined by Capitalizing the first letter
  4. 4. Ruby Building Blocks - Control Flow CONDITIONS : : if tall < 150 puts "You can’t be a pilot" elsif tall > 220 puts "You’re unique" end puts "You're a teenager" if age > 12 && age < 20 puts"You're NOT a teenager" unless age > 12 && age < 20 x=20,y=12 puts "You're NOT a teenager" if x <=> y == 1 EXCEPTION: if y == 0 raise ZeroDivisionError else x=x/y end begin ... code here ... rescue ZeroDivisionError ... code to rescue the zero division exception here ... rescue YourOwnException ... code to rescue a different type of exception here ... rescue ... code that rescues all other types of exception here … retry end
  5. 5. Ruby Building Blocks-LOOPS/BLOCKS 5.times do ...code to loop here... end 5.times { ...code to loop here... } 1.upto(5) { ...code to loop here... } 10.downto(5) { ...code to loop here... } 0.step(50, 5) { ...code to loop here... } "xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else redo } "xyz".scan(/./) { |letter| puts letter if letter == ‘x’ else retry } [1, "test", 2, 3, 4].each { |element| puts element.to_s } i=1 i = i * 2 until i > 1000 while (i < a.length) puts a[i].to_s + "X" i += 1 end for i in 5..9 puts i end for i in 5...9 puts i end class Array def reverse_iterate if block_given? current_index = self.size-1 while current_index >= 0 yield self[current_index] current_index -= 1 end else print self.reverse end end end [2,4,6,8].reverse_iterate 8642 [2,4,6,8].reverse_iterate { |x| puts x } 8 6 4 2
  6. 6. Ruby Building Blocks - OOP - All of the constructs of the language are treated as objects. Checking the data types is done through *.class $global_var = “” class the_class class Document attr_accessor: magic_word attr_accessor :length attr_reader : getter_only def name @name end def name=(name) @name = name end end example = the_class.new def initialize w, h @width, @height = w, h end def [](index) words[index] end def ==(other) return magic_word == other.magic_word end end class Example < SuperExample @@counter = 0 @instance_counter = 0 def initialize @@counter += 1 @instance_counter = @@counter super end end
  7. 7. Packets through a Bot Primitive C&C Network
  8. 8. Cont’d -- Payload Who hates Vodafone ?
  9. 9. What is Rails - Open source web application framework written in Ruby language - Built using the MVC pattern
  10. 10. Rails Application - Convention over configuration - DRY - save time - reuse code - maintain rails [app_name] -d mysql
  11. 11. Folder structure app/ Contains the controllers, models, views, helpers, mailers and assets for your application. app/controller The controllers subdirectory. app/view The models subdirectory. app/model The views subdirectory. config/ Configure your application's runtime rules, routes, database, and more. db/ Contains your current database schema, as well as the database migrations. public/ The only folder seen to the world as-is. Contains the static files and compiled assets. assest/ Contains the images, style sheets, javascript. test/ Unit tests, fixtures, and other test apparatus. mailers/ Contains the email, templates.
  12. 12. The MVC pattern The Model View Controller principle divides the work of an application into three separate but closely cooperative subsystems.
  13. 13. The MVC pattern
  14. 14. MVC - Model Rails Active Record - Rails Active Record is the Object/Relational Mapping (ORM) layer: tables map to classes,rows map to objects and columns map to object attributes - Each Active Record object has CRUD (Create, Read, Update, and Delete) methods for database access.
  15. 15. MVC - Model: Implementation rails generate model book Associations: (one-to-one, one-to-many) class Book < ActiveRecord::Base belongs_to :subject end class Subject < ActiveRecord::Base has_many :books end
  16. 16. MVC - Controller - Separates business logic from the presentation. - rails generate controller book class BookController < ApplicationController def list end def show end def new end def create end def edit end def update end def delete end end
  17. 17. MVC - Controller: Implementation Implementing the list Method: def list @books = Book.find(:all) end Implementing the show Method: def show @book = Book.find(params[:id]) end Implementing the create Method: def create @book = Book.new(params[:book]) if @book.save redirect_to :action => 'list' else render :action => 'new' end end
  18. 18. MVC - View - A Rails View shares data with controllers through accessible variables. <% … %> Execute a ruby code <%=…%> Execute and output the result Create Action: <h1>Add new book</h1> <%= start_form_tag :action => 'create' %> <p><label for="book_title">Title</label>: <%= text_field 'book', 'title' %></p> <p><label for="book_price">Price</label>: <%= text_field 'book', 'price' %></p> <%= submit_tag "Create" %> <%= end_form_tag %> <%= link_to 'Back', {:action => 'list'} %> Submit Action: <form action="/book/create" method="post"> Back Action: <form action="/book/list" method="post">
  19. 19. Routes Route: match ':controller(/:action(/:id))(.:format)' http://mysite/user/get/5 http://mysite/article/ruby-on-rails.html Custome: get 'signup', to: 'users#new', as: 'signup' http://mysite/signup
  20. 20. All together
  21. 21. Portable executable Encryption Primitive PE Protector - Encrypt the .text section data - Append a new stub section for decrypting the data during runtime - Adjust the PE Header ( AddressOfEntryPoint ) Ruby PE PACKER
  22. 22. [(Disa)|A]dvantages Of Ruby - Senior Ruby on Rails engineer: One of the top 5 jobs in Silicon Valley - Perfectly suits the startup environment - Good Contribution by the community: over 4k rubygems, and a wide range of built -in modules - For learning how to implement a new language
  23. 23. Cont’d - Original MRI is relatively slow - Errors don’t help so much in fixing problems Different Implementations: Does it sound good or bad ?
  24. 24. Ruby Internals ( Extra ) Is it really an interpreter ? 1.8 <= Ruby version - Its own custom tokenization code - LALR Bison parser generator Involved , Parse.y and Parse.c in the ruby source folders YARV is Another Ruby VM
  25. 25. Cont’d Extract from Ruby Under A microscope
  26. 26. Questions ?

×