Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

FIS Day6

Programmer of the Day

_Why the Lucky Stiff

  • Tesla: 1909 predicted the internet and wireless communication

Scraping

Stuff I read

One page script - Difference between map and collect

CSS selectors are hard - need to keep this handy

DB prepare: If the same statement is going to be executed repeatedly, you can speed things up a bit by preparing the statement.

<<HEREDOC This one has some tricks in it

xpath: for very specific selectors

Multi Assignment
1
first_name, last_name = doc.css('h1').text.split
Symbol to proc
1
2
3
.map(&:text)
# equal to
.map { |e| e.text }
.try
1
.try("attr", "href")

In rails, but not in the ruby library.

SQL sanitation:

.try
1
"INSERT INTO students (tagline, bio) VALUES (?, ?)", "I'm the ruby guy", "I'm awesome")

DB drivers in SQLite3 does the sanitation.

Delete DB if it exists
1
FileUtils.rm("database.db") if File.exists("database.db")

Avi’s code

nokogiri supports a “/div li.a” syntax, which is more common than the doc.css(‘div li.a’)

Mark Up Languages

SGML -> standard generalized markup language XML -> extensible markup language HTML is an extension of XML.

dtd - document type definition html5 is a new dtd published standards committee

Ternary Operator

logical expression (true or false) this is good for the pattern:

Delete DB if it exists
1
2
3
if true (do this)
else (that)
end

reg ex are pretty much patterns– all languages implement them the same Remember rubular for regular expressions (regex).

if you have email1 and email2 and phone1 and phone2, it’s time to break out another table. Store vertically, not horizontally.

If you see an each block with a push in it, you should be using a collect

CSS Selector

  • element1~element2
    • (e.g. p~ul)
    • Selects every
        element that are preceded by a

        element

    Homework

    nice case statement reference

Comments