quinta-feira, 31 de outubro de 2013

Apache Begins

- Apache
                Installation
                               - Download
                               - Remove conflicts
                                               - Uncked 80 port of skype
                                               - goes to "activate resources" from windows.
                               - run http://localhost  -> It will appear "It Works!"
                               - Enabling/Disabling Service
                                               Control Panel -> Services
                               - Changing Port, ServerName and Email
                                               - httpd: Listen 81, ServerName localhost:80 , ServerAdmin romalopes@yahoo.com.br
                               - How to change from localhost to another name/configuring host
                                               http://complete-concrete-concise.com/web-tools/how-to-change-localhost-to-a-domain-name
                                               - C:\Windows\System32\drivers\etc\hosts
                                                               add:
                                                                              127.0.0.1       romalopes.dev
                                                                              ::1             romalopes.dev
                - HTTPS / SSL(Secure Sockets Layer)
                               - What is HTTPS
                                              
                                               Uses port:443. It uses another layer of criptografy SSL/TLS to protect traffic against atacks
                                               Creates a secure channel in a insecure net.  This trust is in "certification authority"
                                              
                               - http://rubayathasan.com/tutorial/apache-ssl-on-windows/
                               - Download httpd-2.2.25-win32-x86-openssl-0.9.8y
                               - Creating a self-signed SSL Certificate using OpenSSL
                                               in %APACHE%/bin: set OPENSSL_CONF=C:\workspace\linguagens\java\servers\apache2.2\conf\openssl.cnf
                                               - openssl req -new -out server.csr
                                                               - Creates a certificate signing request and a private key.
                                                               - PEM pass phrase: The password ex: anderson1
                                                               - Common Name: fully qualified domain associated with this certificate : romalopes.dev
                                               - openssl rsa -in privkey.pem -out server.key
                                                               - To remove the pass phase from the private key.
                                               - openssl x509 -in server.csr -out server.crt -req -signkey server.key -days 365
                                                               - Set up an expiry date.  Temporary certificate
                                               - copy
                                                               server.crt and server.key to %APACHE%/conf
                                               - in httpd.conf
                                                               Uncoment
                                                                              - LoadModule ssl_module modules/mod_ssl.so
                                                                              - Include conf/extra/httpd-ssl.conf
                                               - Modify \conf\extra\httpd-ssl.conf
                                                              
                                                                              ServerAdmin some@email.com
                                                                              DocumentRoot "Your Root folder location"
                                                                              ServerName www.domain.com:443
                                                                              ServerAlias domain.com:443
                                                                              ErrorLog "logs/anyFile-error.log"
                                                                              CustomLog "logs/anyFile-access.log" common
                                                                              SSLEngine on

                                                                              SSLCertificateFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.cert"

                                                                              SSLCertificateKeyFile "C:/Program Files/Apache Software Foundation/Apache2.2/conf/server.key"
                                                              
                - With o Tomcat
                               http://www.ramkitech.com/2012/10/tomcat-clustering-series-simple-load.html
                               http://www.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html
                               http://www.ntu.edu.sg/home/ehchua/programming/howto/images/ApachePlusTomcat.png
                               http://www.ntu.edu.sg/home/ehchua/programming/howto/images/HTTP_ClientServerSystem.png
                               - Why integrate Tomcat with Apache?
                                               - Clustering: With Apache you can use multiple tomcats
                                               - Security
                                               - Speed for static content
                               - To run
                                               - Apache needs to load a adpter module which uses  Apache JServ Protocol (AJP) to comunicate with Tomcat via another TCP port (8009)
                                               - When Apache receives an HTTP request:
                                                               - Apache checkes if the request belongs to Apache, Tomcat, PHP, etc
                                                               - If Tomcat, Adapter takes the request and forwards it to Tomcat.
                               - Steps
                                               - Install Apache HTTP Server
                                               - Install Tomcat
                                               - tomcat.apache.org (-> Download -> Tomcat Connectors -> JK 1.2 -> Binary Releases -> windows ->  tomcat-connectors-1.2.37-windows-i386-httpd-2.4.x.zip .
                                               - rename it to mod_jk and copy to %APACHE%/modules
                                               - create a file mod_jk.conf in %APACHE%/conf
                                                               # Load mod_jk module
                                                               # Update this path to match your modules location
                                                               LoadModule jk_module modules/mod_jk.so

                                                               # Where to find workers.properties
                                                               # Update this path to match your conf directory location
                                                               JkWorkersFile C:/workspace/linguagens/java/servers/apache-tomcat-7.0.16/conf/workers.properties

                                                               # Where to put jk logs
                                                               # Update this path to match your logs directory location
                                                               JkLogFile C:/workspace/linguagens/java/servers/apache-tomcat-7.0.16/logs/mod_jk.log

                                                               # Set the jk log level [debug/error/info]
                                                               JkLogLevel info

                                                               # Select the log format
                                                               JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

                                                               # JkOptions indicate to send SSL KEY SIZE,
                                                               JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

                                                               # JkRequestLogFormat set the request format
                                                               JkRequestLogFormat "%w %V %T"

                                                               # Send everything for context /ws to worker ajp13
                                                               JkMount /ws ajp13
                                                               JkMount /ws/* ajp13

                                                               # Send everything for context /examples to worker ajp13
                                                               JkMount /examples ajp13
                                                               JkMount /examples/* ajp13
                                               - Include this file in httpd.conf
                                                               include C:/workspace/linguagens/java/servers/apache-tomcat-7.0.16/conf/mod_jk.conf
                                               - Create the C:/workspace/linguagens/java/servers/apache-tomcat-7.0.16/conf/workers.properties
                                                               # Define 1 real worker named ajp13
                                                               worker.list=ajp13

                                                               # Set properties for worker named ajp13 to use ajp13 protocol,
                                                               # and run on port 8009
                                                               worker.ajp13.type=ajp13
                                                               worker.ajp13.host=localhost
                                                               worker.ajp13.port=8009
                                                               worker.ajp13.lbfactor=50
                                                               worker.ajp13.cachesize=10
                                                               worker.ajp13.cache_timeout=600
                                                               worker.ajp13.socket_keepalive=1
                                                               worker.ajp13.socket_timeout=300
                                               - Configure Tomcat

                                                               conf/server.xml to start the AJP1.3 service on TCP port 8009

References of Git

$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
$ git init
OR
$ git clone https://github.com//APPLICATION_NAME.git  //When the project already exists

$ git add .
OR
$ git add file1 file2 file3
$ git commit -m "Initial commit"
$ git remote add origin https://github.com//APPLICATION_NAME.git
                origin is a name of a remote repository(or branch) to be pushed in master
$ git remote -v  //To see if this remove repository was created
git status
$ git pull origin master  //Before push you should give a pull to ensure the your master is equals to origin

$ git push -u origin master
               
                .gitignore contains all file and directories that should be ignored

With a Branch
$ git checkout -b BRANCH_NAME   //switch to a new branch
$ git add src/test/com/roma/MethodTest.groovy
OR
$ git commit -m "Added tests for new one functionality"
- git push origin BRANCH_NAME
- go to github.commit
                - see if the branched was pulled
                               - click in Pull Request                    
                              


- GitHub Commands
                git init
                Create a .gitignore file in include all files and directories that you don't want to commit
                git add . //add all files to local git
                git status -a / show all files that are modified or added
                git remote add origin git@github.com:USER/REPO.git
                git push -u origin master
               

                               

terça-feira, 29 de outubro de 2013

Introduction to Ruby on Rails - In progress

Ruby on Rails
===============
To read about the language Ruby, go to Introduction to Ruby.

Definitions
            Web Application development Framework written in Ruby. Aims to make web develpment easier.
            Principles(philosophy)
                        DRY - "Don't Repeat Yourself"
                        Convention over configuration: If everybody does in a way, it should be a pattern, then for basic operations, just follow the convention.
Install:
            http://railsinstaller.org/
            This tool installs many applications:
                        Ruby 1.9.3 : The language and its compiler.
                        Rails 3.2: The framework Rails
                        Bundler: To manage dependencies(like Maven, Gradle)  http://bundler.io/
                                   Tracks the application code and its rubygems it needs to run.
                                   Specify your dependencies in a Gemfile in your project's root:
                                   automates the intalation and matainance of gems in gemsets.
                                   source 'https://rubygems.org'
                                   gem 'nokogiri'
                                   gem 'rack', '~>1.1'
                                   gem 'rspec', :require => 'spec'
                        Git: To access the github and so on.
                        Sqlite: Simple and local database.  Everything is saved in a file.
                        TinyTDS:  Simple FreeTDS(Tabular Data Stream) for ruby.  Library that can includes a ODBC to access SQL Sever or Sybase.
                                   FreeTDS is very used by UNIX/Linux developers.
                        Suporte do SQL Server
                        DevKit Development Kit for C++ and Ruby.
            Other links     
                        Good to use Sinatra.  Auto web container.  It is like spark or springboot.
                        Another good IDE
                                   http://www.sublimetext.com/2
                        And another famous IDE (SubMine) from jet brains.
                                   http://www.jetbrains.com/ruby/
                        http://rubygems.org/
                                   Tool that goes to a community's gems host for ruby. 
                                   RubyGems is a package management framework for Ruby
                                   A GEM seems to be a kind a plugin or a package.
                                  
                                   To install: ruby setup.rb
                                   After:
                                               gem update --system  //Update to the latest RubyGems version
                                               gem build foo.gemspec //Build your gem
                                               gem push foo-1.0.0.gem //Deploy your gem instantly
                        https://rvm.io/ (Ruby Version Manager)
                                   RVM is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
                                               Switches between different Rubies and GEM environments
                                               Seems the blunder can be integrated with RVM
                                               http://rvm.io/integration/bundler
                                               http://www.ginzametrics.com/blog/rvm-bundler-in-five-seconds/
            - Steps
                        1 - Installs railsInstallar(in root)
                        2 - Install rubygems
                                   Unzip and call ruby setup.rb
Creating a new application called gestbook
            - rails new gestbook
                        Creates a application and install all the dependencies(gems).
            - cd gestbook
                        Many directories and files are created, the most imprtant for developer is app/, because in this directory we find all files of controller, model, views, helpers.
            - bundle install
            -if there is a error: gem install uglifier
           
            - To run the rails: rails server.
            - Server is running, then, go to http://localhost:3000
                        The result is the following page:



            My small project, guestbook will have this configuration:
                        User -> name, email, webpage, title, aboutme
                        Comment -> String comment, User user. belongsTo feedback
                        Feedback -> title, feedback, User user, hasmany comments


To be continued......

Introduction to Ruby - In progress

Ruby on Rails
===============

Ruby
Introduction
Ruby is a general script and dynamic language, but is mostly known as a web language.
Very similar to python and groovy and C++.
It is possible to create classe, methods, but it is possible to develop directly in file.
ex:
file hi.rb
class Test
def initialize(a, b) #constructor
      @a, @b = a, b
    end
def hello (name="aa")
array = [  "Hi", "Anderson", "PI is =", 3.14 ]
array.each do |i|
puts i
end
result = "Hi, #{name}"
return 1,2,3 # a list of returns
end
end
a = Test.new
a.hello()
BEGIN {
puts "BEGIN executes before everything"
}
END {
    puts "END executes at the ende of the program"
}
-call: ruby hi.rb
Types
Ruby has:
array = [ 1, "aaa"]
values = Array.new(4, "anderson ")
puts "#{values}"
hash = { "NYC" => 5000, "Rio" => 1908 }
hash.keys / hash.values
cars = Hash.new( "car" )

range (1..10)
(1..10) === 5 -> true
(1..10) === 3.14 -> true

String
Comparation
if s1 == s2
s1.eql?(s2)
%w --> tokenizer
IO
gets
put "enter a value:"
value = get
puts value
File
file = File.new("filename", "mode")
file.close
File.open("filename", "mode") do |aFile|
end
Variable Types:
$global_variable
@@class_variable
@instance_variable
[OtherClass::]CONSTANT
local_variable
Classes
Defining a Class
class ClassName [< superclass ](optional)
ex: class B < A
def initialize(a, b) #constructor
      @a, @b = a, b
    end
#{self.type}
#{self.name}
Creating instance
b = B.new(1,4) # calls the initialize
b2 = B.allocate # does not call the initializze
Overloading

Access
public, protected and private
Main classes:
http://upload.wikimedia.org/wikipedia/commons/4/43/Ruby_data_classes.jpg

Open Classes
closures
Dynamic method that can be used/passed as variable/parameter
def method(a_closure)
a_closure.callClosure
end

closure1 = callClosure {
puts "Testing"
}
method(closure1)    # Testing
Exceptions
begin
....
raise 'If an error occors'  # like throws
raise "Missing name" if name.nil?
if name.lenght < 8
raise ArgumentError, "Short name", caller
end
rescue SyntaxError, NameError => boom # Specify multiple exception to be catch
....
rescue # Gets all types of exception
....
retry # run again the begin
else  # if it runs without exception.
....
ensure # like finally from java
....
end
Goto(Catch and Throw)
throw :goto_name if a == 1
..... jump to goto_name catch
catch :goto_name do
.... execute the catch
end
Directives
if
if a < b #then is optional
elseif
else
end

conditions? satisfied : not_satisfied
loop
while condition do (do is optional)
...
end
begin
....
end while a <= b
until i<= 10 do
...
end
begin
...
end until i<10 p="">
for i in 1..10
if ...
redo or break
end
...
end
5.times do |y|
 x = y
 puts "value of x is: #{x}"
end
Modules
They are like a class, but can't be instantiated nor inherit. Can be included in class.  Good to group methods, classes and constants - Provide namespace
- Implement mixin
Ex:
module ModuleDoSomeThing
ConstantA = 1111
def ModuleDoSomeThing.methodA      OR def methodA
...
end
Load, Require and include, extend
load
The load method includes the named Ruby source file every time the method is executed:
Sintaxe: load 'filename.rb'
require:
similar to "include" in C++ or "import" in Java.  It doesn't load the file.
Just to use a module, rather than extend it or do a mix-in.
Ex: require 'filename'
- in Ruby 1.9, there is require_relative
The locations is relative.
include:
To embed a module in a class. Take the moethods from another module and embed them into the module.
It is to use INSTANCE methods
extend:
Similar to include, but to use CLASS methods.
Ex:
module Foo
 def foo
   puts 'heyyyyoooo!'
 end
end

class Bar
 include Foo
end

Bar.new.foo # heyyyyoooo!
Bar.foo # NoMethodError: undefined method ‘foo’ for Bar:Class

class Baz
 extend Foo
end

Baz.foo # heyyyyoooo!
Baz.new.foo # NoMethodError: undefined method ‘foo’ for #
Mixin
Similar ao Groovy.  Multiple inheritance.  It is when a class inherit features from more than one parent class.
Mixin simulate the multiple sub-classes.  A class is mixed with a module.
Ex:
module Plane
def fly
puts 'fly'
end
def initPlane
puts 'it is a plane'
end
end
module Car
def run
puts 'run'
end
def initCar
puts 'it is a car'
end
end
class Hibrid
include plane   # Include two modules.
include Car
def work
initCar()
initPlane()
run()
fly()
end
end
hib = Hibrid.new
hib.work
hib.fly
hib.run










To be continued.....


http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
http://www.tutorialspoint.com/ruby/ruby_modules.htm
http://ruby-br.org/tutoriais/?t=4&p=7
http://rubylearning.com/satishtalim/writing_own_ruby_methods.html

http://railsapps.github.io/what-is-ruby-rails.html
http://phrogz.net/programmingruby/frameset.html