Wednesday, September 21, 2011


Image sizing and scraping with JQuery and Rails

I know, I know, long time no type. Not my fault, I swear! First I went travelling, then I had a buncha work to do, then I went to San Francisco TechCrunch Disrupt, all of which occupied my time. Well, I suppose, on reflection, all those things were my fault, but, um ... look, I'm back now, OK?

Back with a li'l discussion of image sizing and scraping with Rails and JQuery, for a project I can't really talk about yet. Suffice to say that sometimes I want to calculate the size of various remote images - quite a lot of them, in fact, making performance important - and sometimes I want to scrape all the images from a set of web pages.

I thought the first task was going to be tricky. And maybe it is. But fortunately, someone has solved it for me, via the totally awesome FastImage Ruby gem, for which praise should be heaped upon one sdsykes. It works exactly like advertised, which is to say, like this:

  def self.picture_info_for(url)
    return nil if url.blank?
      size = FastImage.size(url)
      return size  #[width, height]
    rescue "Error getting info for picture at "+url.to_s
      return Array[0,0]  #this makes sense for my app, but maybe not yours

So, hurrah! This meant the scraping bit was actually tricker. Sure, I could have done it all in Rails, but it's user-facing, and I didn't want the user to have to wait for a bunch of potentially sequential http requests to complete without seeing any results. I could have done it all on the client side, but parsing HTML with Javascript, even with JQuery, sounded painful and fraught with difficulties, compared to using the dead-easy Hpricot gem. So I came up with a compromise I quite like:

1. On the client side: (written using HAML, which I mostly adore)
- @image_urls.each_with_index do |url,idx|
  = link_to url, url
  %div{:id => 'page_'+idx.to_s}     

  $(function() {
  - @image_urls.each_with_index do |url,idx|
    url: '/stories/scrape_images?url=#{CGI::escape(url)}',
    success: function(msg){ $('#page_#{idx}').html(msg); },
    error: function(msg){ $('#page_#idx}').html(msg); }

2. On the server, to first create and then respond to that client page:
  def popup_scraped_images
    start_time =
    @image_urls = []
    @seed = Seed.find(params[:seed_id])
    @seed.active_signals.each do |signal|
      next if signal.main_url.blank?
      @image_urls << signal.main_url

  def scrape_images
    url = params[:url]
    slash = url =~ /[^\/]\/[^\/]/
    host = slash.nil? ? "" : url[0,slash+1]
    html = ''

    page = HTTParty.get(url, :timeout => 5)
    Hpricot(page).search("//img").each do |element|
      img_src = element.attributes["src"]
      img_src = host+img_src if img_src.match(/^\//)
      html += '<img src="'+img_src+'" />' if img_src.match(/^http/)

Hopefully how they all interact is self-explanatory. Et voila - semi-asynchronous Rails/JQuery image scraping, handled on the server side for easy caching if need be later on.

Labels: , , , , , , ,

Nice Information Your first-class knowledge of this great job can become a suitable foundation for these people. I did some research on the subject and found that almost everyone will agree with your blog.
Cyber Security Course in Bangalore

Writing in style and getting good compliments on the article is hard enough, to be honest, but you did it so calmly and with such a great feeling and got the job done. This item is owned with style and I give it a nice compliment. Better!
Cyber Security Training in Bangalore
Top quality blog with unique content and found valuable looking forward for next updated thank you
Ethical Hacking Course in Bangalore
Excellent blog with valuable information and just added your blog to my bookmarking sites thank for sharing.
Data Science Course in Bangalore
Nice Blog. Thanks for sharing with us. Such amazing information.

Only Blog

Guest Blogger

Guest Blogging Site

Guest Blogging Website

Guest Posting Site
Find the steps to download, install and activate the Norton product.

McAfee software has several features like protection against viruses and malware, permanently delete the damaged data, protection for many devices, etc.

Reach and download Webroot antivirus for securing your data. Install the setup and visit to activate your subscription.

Online Assignment Help affiliations award students to score boundless etchings in their undertaking comfort and help them with refreshing their game-plan. Submitting persuading schoolwork each time is astounding contemplating some unavoidable conditions.
Assignment Writing Service
London Assignment help
do my assignment
write my assignment
Priya Chaudhary Label is online designer clothing store to buy Kurti/Kurta, tops, shirts, dresses, pants, palazzos, dupattas, pajama, kaftans & mask for Women .Designer Kurtis
Allied Paralegal Services is a licensed paralegal with the Law Society of Ontario, offering a wide range of legal assistance to our clients. Backed by years of experience and exhaustive knowledge, we provide the favorable results you come looking for.
lawyers near me
paralegal advisors
court near me
court near me
Expert Paralegal Service
lawyer licensing process
Human Rights Violation
find legal advisors
Laws consultants near me

lawyers near me
Paralegal Services Ontario
Paralegal Services Toronto
Paralegal Services Near me
paralegal services near me
justice of the peace Ontario
lawyers near me

I am social worker & Ex-Councillor Candidate in Khanpur Ward 81-S & true believer that one can change this nation for better by inspiring others .

Omprakash Chaudhary Delhi
Professional essay writer are available for students all over the world. Allassignmenthelp provide assistance in creating all types of academic assignments such as essays, term papers, research papers, and other tasks. Our experts have college degrees, writing experience, the desire to help students. If you are willing to hire essay writer feel free to contact us to get assignment help from professional essay writer.
Here you will find qualified and experienced experts for do my homework so that you need not worry about the quality of work. At we know that meeting deadlines is an important part of earning a excellent grades. We have several high quality writers who can meet deadlines without any problem at all. If the first draft of the Assignment does not meet your needs, we offer free revisions so that will help you get the best grade from your teacher.
Thanks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.

Agile team facilitation

Thanks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.

Team facilitator Agile

Agile facilitator
Thanks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.
Team facilitator in Agile

Our Assignment Help Singapore is one of the most established service providers in the market for assistance for students. We have been providing online guidance for quite a time and as now one of the most reliable companies.
If you're looking for research help, find a service like ours; We have been in the academic writing business for over five years. Writing coursework is especially challenging for novices, but you can get online coursework help from writers.
Nice Post...
Hey There, I am Sofia Carter. Sometimes the printer suffers connection issues which is not a concern as long as you can fix it on your own. If your HP printer not connecting to the WiFi, then you must try restarting all your devices first.

Very good article thanks for sharing me.
alternative investment, What is The Black Diamond on a Measuring Tape for
Nice article thanks for sharing me.
How much does Twitch Streamers Make, Traunch

Learn crucial factors to unlock cash app account:

Inclusion of the crucial factor can help cash app customers. They can Unlock cash app account by implementing the valid steps carefully. Cash app locks the account when any kind of malicious element is noticed. Therefore, customers should not take it as a big deal; instead, they should ask the tech assistance from the experienced cash app service team to get immediate solution services.
Opt for the right strategy to get money off cash app without bank account:

Opting for the right strategy is essential to get money off cash app without card. Various kinds of the reason might be responsible for troubles with the Cash app customers. But they can decide to stick to the one solution strategy. Apart from these, they can connect to the cash app service executives to manage their requirements. The service team guidance their cash app customers as well and enable them to complete the withdrawal process of money from the cash app.
Students need to gain relevant ideas about the courses after 12th. The changing time has provided various career segments through which they can see their future. However, a substantial decision can be taken by evaluating one's own likings towards the career field. Students can select the courses after completing their 12th as per the subject they had taken in the 12th itself from a career point of view.
Hi, friends. I am Sofia Carter. I am working as a technical support executive in a company. I am also associated with an independent company. And I am an expert in dealing with all HP printer-related issues, such as printer not printing in color. are facing such problems that you can connect to me to resolve this in a single phone call.
Game Build poin Luo Yi ini akan memberinya dampak burning dengan poin Glowind Wand. Lantas Holy Crystal akan tingkatkan Magis Power secara berarti, dan poin Divine Glaive untuk tembus Defense hero musuh. Kemampuan Luo Yi akan membuat mark Yin dan Yang sepanjang 6 detik. mobile legends Reaksi Yin dan Yang bakal terjadi saat dua pemegang mark sama-sama merapat, memberinya 420(+14*level)(+140% keseluruhan magis power) magis damage dan dampak stun sepanjang 1 detik.
Excellent content ,Thanks for sharing this .,
CSPO certification

Excellent content ,Thanks for sharing this .,
Product owner certification
Certified scrum product owner
Excellent content ,Thanks for sharing this .,
Scrum master certification online
CSM certification online

Excellent content ,Thanks for sharing this .,
Scrum master certification
csm certification

Excellent content ,Thanks for sharing this .,

Thanks .,Turient is an All-in-one platform for all our teaching needs. If Teaching is your passion ,enabling is ours
Read the Informative blog - 11 Free Teaching Tools for Online Teachers
11 Free Teaching Tools for Online Teachers
Free Teaching Tools


Necessary Things To Keep In Mind While Trying To Cash App Delete Account
You can’t access your transaction history, payment details, and other essential information from the Cash App account if you Cash App Delete Account. Besides, if you have decided to do the same, you have to simply take necessary actions that you can find it out from the official help page of the Cash App.
Understand How To Activate The Cash App Card With And Without A QR Code
Do you want to be acquainted with the complete information about How to Activate the Cash App Card with and without a QR Code? For that, referring to the official Cash App help page will surely assist you toget your Cash App card activated either manually or automatically by scanning the QR code.
Thank you! I really enjoyed your post I want to share with you all a useful source Having antivirus software is necessary to keep your PC or device away from malware. Trade flock is the full list of Top antivirus software 2021 - Stay Protected Always. Visit our website

Informative blog! We are offering the most conscientious support for the issue that has led your Printer In Error State.
What To Do If Can’t Get My Money Back From Cash App
To Get My Money Back From Cash App, you have to log in to your account. Further more , you have to open the activity section where you can see all the transaction made by you on your Cash App account. here, you have to choose the refund option by tapping on the three dots on the payment you would like to apply for a refund.
Implement appropriate steps for Cash App Dispute:
The implementation of the appropriate steps is essential for Cash App Disputes. Numerous cash app users are there who could not understand the tips for initiating the process for dispute. In that situation, they should take the guidance of the qualified cash app team. In addition to these, they also provide the required services if needed to reduce the complexities during the process related to the cash app dispute.

If you want someone to Edit my paper within the shortest period of time, then get our assistance from experts who are available for support. We make sure that every content is of the best quality and is composed according to your requirements and necessities. You can also get additional deals and discounts on special occasions throughout the year.
How Much Can You Send On Cash App Account That Is A Verified Profile?
If you want to send and receive a huge amount of money from your Cash App card, you have to make proper utilization of Cash App verified account. Besides, if you are one of those who are looking to be aware of How Much Can You Send On Cash App, take aid from the experts.

How To Activate Cash App Card Without QR Code After Getting It Physically?
Are you a new Cash App user and unable to activate your Cash App Visa Debit card automatically? If yes, no need to worry as the way to do the same manually is also very simple and straightforward. In case, you don’t know How to Activate Cash App Card without QR Code, take help!

Where To Go To Fetch Details About How To Add Money To Cash App Card?
To understand How To Add Money To Cash App Card in a hassle-free manner ,you will need to go to the help and support section of Cash App where you can find out the genuine procedure in a step by step manner. Moreover, you can also take assistance from the professionals who will let you add money to your account.

How Can I Get My Money Back From Cash App With Optimum Ease?
The best mode to Get My Money Back From Cash App is to apply for a Cash App refund. As quickly as you apply for a refund to the payment to be refunded, you will be able to get your money credited to your Cash App account wallet in a hassle-free manner.

Find Out Major Reasons Behind Why Cash App Won't Let Me Send Money
Do you want to make yourself aware of every possible reason behind why Cash App Won't Let Me Send Money? As you have landed on the right place, you can find out the best way to deal with such problems. However, if you are still unable to get it fixed, you should directly contact the Cash App support executives.
How Do I Recover My Cash App Account Using The Registered Phone Number?
In the absence of the email account linked with your Cash App account, you should either use your phone number or you can contact the Cash App customer support service provider. Here, the available troubleshooting members will let know everything about How Do I Recover My Cash App Account
Adopt suitable tips to fix Cash app transfer failed problems:

Issues are not of the serious matter if individuals realize the best approach to oversee them adequately. Aside from this, the online application for transferring money is essential to clients. Therefore, each cash app client ought to know about the fitting tips to handle the Cash app transfer failed circumstance. Later, they are reliant upon the cash app account. Cash app users may speak to the cash app service team for mentorship.
Take Necessary Help From Cash App Support To Activate Cash App Card
At the official help and support page of Cash App, you will find out the right channel through which you will be able to
Activate Cash App Cardin no time. Besides, if you are not able to do it on your own, you will need to take aid from the Cash App support engineers who will help you out in no time.

I am really feel glad to read out published post on this blog. Apart from this, I am still waiting other post for escalating my knowledge power. In the time scarcity situation, you can leverage from Assignment Help in USA to secure highest grade.
We know how to help you get ahead in school and we're here for all your assignments. All it takes is a simple please " Write my Assignment," plus some details about what type of work needs doing, so our team will do the rest! writemyassignmentus has professional writers who are knowledgeable across many subjects -- no matter if its English or history (or whatever), they can handle any task set before them with ease. And don't worry: not only will they improve their grades through us but also have plenty left over at semester's end as well Assignment Help.
Thank you! I really enjoyed your post I want to share with you all a useful source If you are planning a short one day trip the gandikota is the best place to visit with amazing sightseeing. Gandikota is a small town in India that can be explored in one day. But don’t judge this place by its size.

Every woman loves to wear and flaunt Diamonds. Be it Marilyn Moore or Sushmita Sen, they all have worn big Diamonds in their fingers. But beyond craving to wear a beautiful diamond ring or necklace, a few people are curious to know the facts about Diamond company in India that articulate them beautifully in contemporary designs.
Nice Post...
Hey There, I am Sofia carter. Installing printer drivers for your HP Printers is easy. You can do so simply without needing any help. But before you do anything, make sure you have an internet connection with good speed and enough storage on your computer. visit


Get assistance on How to Check Cash App Balance
Want to know How to Check Cash App Balance?
Don’t know to check the balance on the cash card?
For all these things, get in touch with the cash app experts that offer quick solutions. You’ll be given guidance and precise technical support from professionals.
Ring on helpline number for talking to the experts.

How To Activate Cash App Card Without QR Code To Unlock Its Features?
If you are not getting the proper assistance to understand How to Activate Cash App Card without QR Code, you have to approach the Cash App technical support professionals.Here, they will provide you with the proper aid along with the solution to do the same in a trouble-free manner.


Post a Comment

Subscribe to Post Comments [Atom]

<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]