Skip to main content

Posts

Explain how functions in Jquery works

$(document).ready( function() {     $('div').click( function() {         $('div').effect('explode');        });    }); - This simply means when the HTML document is ready, call the function click when <div> tag is clicked. - Once <div> tag is click, call the function effect on the <dig> tag - The function effect will be acted upon <div> tag with a parameter of 'explode'.

Explaining HTML

HTML is simply a language that allow you to categorize the information in a web page. It provide the information with meaning and structure. <head> </head> has the meaning of header information. <p><a href="www.google.com"> Link! </a></p>, this provides structure that the link is inside the <p> tag and hence it is a paragraph.. <html> <head>     <title>Hello World</title> </head> <body>      <h1> Kiss you Goodbye</h1> </body> </html> The code above wrap the text/data/information "Hello World" into the <head> tag and <title> tag so the computer know what this information is about. <tag> is the start of the tag, </tag> is the end of the tag. We need those special syntax because there is a need for the computer to know when certain item start and when it stops. *If you want to assign attribute to a tag, use this syntax <a...

Explain templating eRuby (ERB)

ERB is simply a language that allow HTML and pure Ruby code to co-exist together. <% #any ruby code %> This is the syntax that will allow you to build a ruby code, but will not display it. <%= #any ruby code %> This will display the ruby code. ERB will have access to any instance variable that is given by the sinatra code.

Explain sinatra route

* Sinatra is simply a Ruby Gem that is build specifically for easy web development. Its syntax is generally build around blocks like one below. get '/' do     @value = 'abc'     erb :layout end -sinatra route derived its name from HTTP method like GET, POST, or PUT. - here, '/' means a route for the web application like www.yourapp.com/ , it just specify the last character '/' for brevity. - any instance variable like @value will be accessible inside the templating language , in this case, erb file. - The last line 'erb :layout' will ask Sinatra to execute the template :layout * There are two important variable in Sinatra, namely params and session - session is instructing Sinatra to build a cookie that holds important information/build states that will last between multiple HTTP request, since HTTP is a stateless communication (ie. it forgets after each HTTP request). - You can push any information any information into session bec...

Explain a method

A method is simply a sequence of instruction that the computer will execute from start to finish. Eg: a = 10 def shout( a )     puts "hello!"     a = 15     puts a end shout(a) puts a # hello! # 15 # return nil # 10 - The method will take one or more input and output something after the sequence of instruction. - here, a is passed into the method shout , then assigned to a new variable 'a' and printed out as 15. - the original local var outside is still 10. - the method here has 3 lines of instruction. First one is output hello, second is assignment to number 15 to variable a , third one is output variable a. - The last line in the method's instruction will be returned . If we print what the value of the method's returned , it is nil puts shout(a) # nil

Observation on jQuery

$() is used a lot $(document) is used to point to the HTML document $('p') is used to point to <p> tag in the HTML document. $(this) is used to point to the current HTML element. Example:: $(document).ready( function() {   # function takes a block that will execute a sequence of code. }); - when you want to apply action to a class , you do not need the syntax $('.class') . Instead , $('class') is sufficed.

Explaining Params

Params is just a hash. Params will not persist across different sinatra route. The params created in the first route, won't exist in the second route: get '/*/*/:first/love' do end get "/got" do end if you set the sinatra route like so, then params is going to look like that get '/:first' do end http://apps.com/awesome {"splat"=>[], "captures"=>["awesome"], "first"=>"awesome"} The "splat" is to fill in the gap that the sinatra creator do not know what to name the key of the params hash get '/*' do end http://apps.com/awesome {"splat"=>["awesome"], "captures"=>["awesome"]} The "captures" will capture everything that is entered into the URL that is not a parameter. get '/*/*/:first/love' do   binding.pry end # here love is just a normal link name, not a params http://apps.com/awe...