Skip to main content

Posts

Qurky features of HTML and CSS

1. spaces between inline-block and inline element a. you can use zero font-size to eliminate the white space. Then reset back the font-size in the inner element to 1 rem. b. comments out the white space between the inline-block element. 2. methods to clear float. Method One .group:after {      display: block      content: ""      clear: both } Method Two add a empty div element after the floated element, then add a "clear: both" property. Method Three Use "overflow: hidden" within the parent container element. This creates a block formatting context that will cause the parent to expand to contain the width and height of the floated child element. 3. static, relative, absolute, fixed positioning Static element is the default position. All element are in the document flow. Relative position element are in the document flow. But accept offset property to move against its parent container. Absolute position is taken out...

Summary of Peak by Anders Ericsson

Naive Practice You stop improving when the thing you do becomes automated and you repeat mindlessly for years. Purposeful Practice - specific , well-defined goal , targeting some aspect of the skill. - focused , paying full attention - feedback, you know when you are right / wrong in a timely manner. - stetching out of comfort zone, not too much . If you are stuck, generally , the solution is try differently instead of try harder. It is natural when you are stuck . But it is temporary. - hard work and not fun. Mental Representation -mental structure that represents your understanding of something. Something that we just 'know' like riding a bicycle. -domain specific . No such thing as developing a general skill. - it bypass short-term memory limitation and allow processing of large amount of information quickly Deliberate Practice -requires a field that is well established. - requires a teacher who can provide specialize training.

Study Guide 170

HTTP Describe what HTTP is and the role of the request and the response. HTTP is just a text sent over the internet with a set of rules that governs how computer communicates with each other. It follows a model whereby a client makes a request and then wait for a response from a server. HTTP itself doesn't transmit data, it depends on TCP/IP protocol to get request/response from one machine to another.  What are the components of an HTTP request and an HTTP response? HTTP request and response has a header and body.  HTTP response will contain status code ( 200 OK)  and headers which is a metadata that contain information for content-type (text/html),  Content-Encoding:gzip (type of file compression), server (name of the server), Location (new resource location for redirects) and a HTTP body  HTTP request header contain information on HTTP method (GET/POST) , path and parameter to allow server to know how to find information, along with optional hea...

The overall process of having user sign in and sign out

you store your username and password in the YAML file --- username: password Then we load the yaml file using YAML.load_file(file_path) This will create a hash of { 'username' => 'password' } Once we have the details, then request user to type in username and password. They are accessible via params[:username] and params[:password] if hash.key('username') return true && hash['username'] return the matching password then it is a match then we save the username into the session like so session[username] = username If we want to sign out , then we delete the username from the session via session.delete(username) If certain process you do not want user to do anything, just check if session[:username] is there or not, if not, then user is not log in, then you want to redirect them to homepage.

Building the sign in system

--- developer: letmein maintain a yaml file that look like above where developer is the username and letmein is the password Signin Create a form that generate a parameter called username, store the username in the session[:username] if the username and password are valid. Signout session.delete(:username) To determine whether to allow user to perform certain action, create a method def require_signed_in_user     unless session.key?(:username)   # which means whether there is a key name after 'username'        session[:message] = "You must be logged in to do that."        redirect "/"     end end Then put into whichever path that requires user login .

Using file system in Sinatra

You need to create a separate /data folder to store all the files. You need to have a root to current folder file by calling this file_path = File.expand_path("..", __FILE__) This will create a file path from root until one level above current file, which is the folder that contains your file. When reading text file, you need to specify headers['Content-Type'] = 'text/plain' File.read(file_path) To edit an existing file or to create a new file, need to File.write(file_path , "content here") To delete a file, File.delete(file_path) To determine whether a file exist or not File.exist?(file_path) File.file?(file_path) To list down all file within a certain directory. The Dir.glob will create an array list of the matching file. File.basename will cut off the last part of the file name. Dir.glob(root + "/data/*").map do |path|     File.basename(path) end As you can see, most File class takes in the file_path as argument....