Quote (carteblanche @ Apr 16 2016 06:02pm)
looks like ruby and python
I wish rubies HTTP library was that easy to use. Crystal by far has a much better/simpler syntax for using HTTP related stuff. If you compare the two side by side you will notice a different right away:
http://ruby-doc.org/stdlib-2.3.0/libdoc/net/http/rdoc/Net/HTTP.htmlhttp://crystal-lang.org/api/HTTP/Client.htmlA ruby implementation would be more like:
Code
require "net/http"
10000.times do |i|
Net::HTTP.get("http://www.#{i}.com", "/") do |response|
File.open("#{i}.source", "w") do |file|
file.puts response.body
end
end
end
Edit:: I've been using Crystal alot recently just because it performs a lot better than Ruby. I had to write a recursive function for transversing a JSON string:
Code
5 def collectComments(db, imageJson, parentComment = "")
6 imageJson.each do |parent|
7 if !parent["children"].as_a.empty?
8 collectComments(db, parent["children"], parent["comment"])
9 end
10
11 if parentComment != ""
12 childComment = parent["comment"]
13 db.execute("Insert Into Comments Values (?, ?)", parentComment.to_s, childComment.to_s)
14 end
15 end
16 end
If I would of tried to use Ruby for that it would take probably minutes to parse one JSON response rather than a few seconds because the JSON string has about 70 entries in the main array, then each entry has children which has children of their own sometimes up to 10 levels deep.
This post was edited by AbDuCt on Apr 16 2016 07:06pm