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: , , , , , , ,

Comments: «Oldest ‹Older 401 – 450 of 450
Our Products -
MBOX to PST Converter
NSF to PST Converter
PST File Converter

Users can take help from the DRS OLM to PST Converter software to convert OLM files into PST , OST, EML, PDF, MBOX, JSON, CSV, HTML, PNG, DOC, etc. Additionally , you can also convert OLM into multiple email clients like AOL, Gmail, Yahoo, iCloud, Yandex Mail, Live Exchange, Office 365, Zoho Mail, etc. It is an automated software that can be used by every common user without any difficulty. You can install its free demo version and check its functionality.

Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile Therefore let me rephrase that: Thank you for lunch. 메이저사이트

Cash App Won't Let Me Send Money If Unable To Get It Fixed?
If you are looking to get rid of Cash App Won't Let Me Send Money problems permanently from the root, you need to have a word with the professionals of the Cash App department. Here, you will receive the best treatment at the comfort of your home, in no time.
How to Borrow Money from Cash App immediately?
Users of cash applications should be familiar with the techniques they might take if they need more money. Cash app users must contact the cash app and follow the steps to complete the borrowing process. They have a query on Borrow Money from Cash App. Apart from all other tactics, users may opt for having the words with the support team.

A good SOP is the one that gets you noticed. It should be easy to read, concise and should contain all the relevant information about you. A well-written SOP can also get your dream job. There are several companies in India that offer professional SOP writing services to help students with their application process.
If you want to pay your bills but you are lacking behind some amount of money, you don’t need to worry at all. In such a case, you must understand How To Get Borrow Money From Cash App either by going the official help section or contact the Cash App support section right now.
I’m impressed, I have to admit. Truly rarely should i encounter a blog that’s both educative and entertaining, and without a doubt, you’ve hit the nail within the head. Your notion is outstanding; the pain is an issue that insufficient everyone is speaking intelligently about. I am very happy that we stumbled across this inside my try to find some thing relating to this. 메이저토토추천

Very Impressive content! I visit your website 1st time and I really impressed and enjoyed also. I appreciate your efforts for your work. We provide solutions to Recover Forgot Spectrum Password. If you also looking for this . Please contact us.
I'm so happy to finally find a post with what I want. 메이저토토사이트 You have inspired me a lot. If you are satisfied, please visit my website and leave your feedback.

Resolve cash app problems- Can I use cash app card for lyft
Right from changing the PIN to refund, users will encounter a lot of technical Cash app Problems. Can I use cash app card for lyft? To get rid of all these issues, you just need to avail cash app support for immediate technical help


Will Cash App Refund Stolen Money If Money Is Stolen?

Will Cash App Refund Stolen Money? To get your money back to your account, you need to first apply for a refund and you will be able to get your money deposited into your account. In case of any hassle, you have to simply take proper assistance from the experts right now.
Excellent blog here! Also your site loads up very fast! What host are you using? Can I get your affiliate link to your host?토토사이트

Hi there, I simply hopped over in your website by way of StumbleUpon. Now not one thing I’d typically learn, but I favored your emotions none the less. Thank you for making something worth reading. 먹튀검증업체

I like your post. Thanks for your sharing. Pocket friendly academic assistance from Experts
The academic experts at My assignment help online gives you academically superior finance Assignment help service. It doesn’t matter you are in which university or country. Our assignment providers are familiar with all the academic disciplines and gives you the best support at a sensible cost.

I’m writing on this topic these days, , but I have stopped writing because there is no reference material. Then I accidentally found your article. I can refer to a variety of materials, so I think the work I was preparing will work! Thank you for your efforts. 먹튀검증사이트

How to delete cash app transactions history easily?

It is usually crucial to explore How to delete cash app transactions history. This is a critical concern because such needs can arise at any time. They should gather information about the cash app account to run the cash app system with ease and obtain solution aspects. It is critical to handle imperative factors related to the cash app account and use the digital platform efficiently for transactions.

I found this post which is more educational and well written. It will be also helpful for the students who are looking for the best academic help or Assignment Help Australia services from the best assignment expert online. I’ll be sure to bookmark it and come back to read more of your useful information.
When I read your article on this topic, the first thought seems profound and difficult. There is also a bulletin board for discussion of articles and photos similar to this topic on my site, but I would like to visit once when I have time to discuss this topic. 카지노게임사이트

I've been searching for hours on this topic and finally found your post. 카지노사이트추천, I have read your post and I am very impressed. We prefer your opinion and will visit this site frequently to refer to your opinion. When would you like to visit my site?

Hey, I am sophia william, I read your blog and find it very informative and interesting I definitely gonna share it with my friends. Keep posting like this.
Visit for more:- Medical Dissertation Help

How to add money to cash app card at Walgreens- Call techies to know
If any technical urgency occurs while loading money at Walgreens then seek cash app help. Through this, you’ll get to know How To Add Money To The Cash App Card At Walgreens Simply, speak to the professionals of the cash app and get the right solution by picking up your phone. To fix all the woes of cash app account, dial the helpline number to get effective and quick Cash app customer service. With cash app experts, you will get real-time assistance for solving cash app issues.

Avail the best convection microwave oven in India with buyers guide and customers review. best convection microwave oven india
It is very common to confront a wide variety of technical and non-technical problems due to several known and unknown reasons during the course of using the Instagram services. So, if you are one of those needy Instagram account holders who are also having a bad experience with their Instagram account, it is recommended to go to the Instagram help center. Luckily, you will be able to determine the best possible solutions and understand
How Do I Contact Instagram About A Problem within the least time frame, even at the comfort of your home.
Wow! Great article you shared. I Appreciated the words you used in your article, thank you for sharing with us. I am also here to tell people about my website that is Assignment Help. We provide online assignment help for students who need expert help to complete their assignments. I would like to tell you that we are in this Academic line for the last 6 years and we have an army of experts who provide online assignment services. We live in Santa Clara, CA, USA, and provide online assignment help worldwide.

Utilizing British Dissertation Help gives you the opportunity to submit your Humanities Dissertation on time, with excellent results, and for one of the lowest prices. Our team of talented writers offers the best online Humanities Dissertation Help. They have years of writing experience and have studied the various subjects that make up the field of Humanities. As a result, we can easily accommodate any of your demands of homework assistance. Our writers personally handle your English projects while also providing you with unique papers that will hasten your grasp of the subject, aid you in performing well on exams, and aid you in submitting assignments on time.
It absolutely astounded me, and I hope you'll continue posting material like that anytime you like. I'm in a great mood now that I've found this blog article.
Spine surgeon in New Delhi
Price Gadgets

Buy test banks like Communication Between Cultures 9th Edition Test Bank from testbanks22 for instant grade improvement.

Techniques to getting Borrow Feature on Cash App

Consideration of some of the factors for trading purposes is necessary to realize the techniques that may enable you to get the Borrow Feature on Cash App
. If you are just looking for a system that might help them, you can start it for the same purpose. The right strategy will help you fully manage the account cash register app without delay.

Do you want to finish your homework fast but you are frustrated that how do you finish your homework fast? So hire GotoAssignmentHelp, a leading assignment provider agency based in Australia, to provide assignment help, essay help, homework help and many more. So if you are looking for such agency then we are best one. For more information, read this complete blog.
This comment has been removed by the author.
Are you one of those users who are looking forward to knowing how Can You Send $10000 Through Cash App? To determine the best possible solution and guidance regarding the same, you don’t need to wander here and there.Apart from that, you will need tofirst verify your account identityand then it will take around two weeks tosend such amounts of money. For any kind of assistance and support, you should go to the Cash App support page right now.
As a new user, you must have the answer to your question like Can Someone Hack Your Cash App With Your Username or not.No such technologies and methodologies are available for hackers and scammers to use to hack your Cash App account with the help of your username.So, instead of making it stressful, you have to simply feel free while sharing your Cash App username. For more information to safeguard your account, you have to take help from the Cash App geeks.
Thanks for sharing your article with us. This means a lot and thanks for providing information to us from time to time. I am also here to tell people, especially students about our Do Assignment Help website. With the Do Assignment Help website, we offer information and help for students to complete their assignments on time. I would like to tell you that we provide online assignment help from Santa Clara, CA, USA. for further information, you may visit our website and chat with our experts.

Very good blog post, it is very well written and your points are well-expressed. Thanks for sharing kwara state college of health 1st batch admission list, visit Best Rated Educational Update Portal in the World; Examination and Academic Guide, High Paying Jobs & Scholarship  Website.
Let’s reach Facebook Support Chat Team Instantly
Connecting Live Facebook Support Chat team by following these instructions. For better talking points and tips, be sure to reveal your problem and what kind of issue you are trying to message with Facebook about. Official teams can usually help ensure a better outcome. This is the best way to live chat with Facebook because a bunch of Facebook users have used it over the last 18 months to reach customer service and resolved their queries. To know more you can follow the link below to grab guidelines.


How Does Sutton Bank Cash App Assist In Using The Cash App Services?
Sutton Bank Cash App. is a partner bank of Cash app that Square has a strong association with.Whenever you set up a Cash App account, you will get your account opened under either a Lincoln Savings bank routing number or aSutton bank routing number.However, if you have any doubts or confusion regarding the same, you have to get in touch with the professionals of the Cash App department who will be ready to assist you out all the time.

How Does Sutton Bank Cash App Assist In Using The Cash App Services?
Sutton Bank Cash App. is a partner bank of Cash app that Square has a strong association with.Whenever you set up a Cash App account, you will get your account opened under either a Lincoln Savings bank routing number or aSutton bank routing number.However, if you have any doubts or confusion regarding the same, you have to get in touch with the professionals of the Cash App department who will be ready to assist you out all the time.

How to fix cash app failed for my protection -solve with expert’s help
How to fix the cash app failed for my protection?
Want to fix the issue of the cash app frequent transaction fail?
If yes then seek technical guidance from professionals for solving the glitches of the cash app. For fixing this, try genuine cash app customer guidance that offers technical assistance round the clock. Get in touch with the cash app technical specialist’s team. Cash app users can connect with techies anytime via a helpline number. If you are looking for quick service then dial all time reachable helpline number to get technical assistance.

Can Cash App Be Hacked By Taking Access To Your Linked Phone Number?
Can Cash App Be Hacked if someone is getting access to your linked phone number?With the help of a phone number that is already linked to your Cash App account, hackers will be able to change the password of your Cash App account. Apart from that, they will also create a new password for your Cash App account and then start getting access to it without your permission. Furthermore,you should immediately contact the Cash App geeks if seeking a helping hand.

BAPE Hoodie
Thank you very much for writing such an interesting article on this topic. This has really made me think and I hope to read more.
The rapid stride of technology and digitization has given a new lease of promising learning platforms, i.e.,eLearning development. Organizations use different learning methods to enhance the skillsets of the learners. It does not mean to adhere to specific modules but rather modules that aptly fit learners’ requirements. Hence, the emergence of Software Simulation Solutions is in learning platforms.
Online Q&A Services
How To connect sutton bank ?
To Connect Sutton bank for cash app, you should make a call at the official helpline number.
More information connect with us.
Check now : - Sutton bank cash app

xcxdf Buy instagram verification
Want best report writing help to Get Higher Grades? Hire our assignment writers in Australia at low prices.
"여기에 제공해 주신 귀중한 정보와 통찰력에 감사드립니다 ... 토토사이트 순위

블로그에 북마크를 추가 할 가능성이 높습니다. 당신은 정말 멋진 이야기를 가지고 있습니다. 블로그를 공유해 주셔서 감사합니다. 슬롯사이트

Excellent written information.
Price Gadgets
Oppo A94 Price in the Philippines
iPhone 7 in Philippines


Thanks for sharing this useful information! Hope that you will continue with the kind of stuff you are doing.
iphone screen replacement dubai
Thanks for sharing this informative information with us. This is a fantastic website, thanks for sharing.

cuevana 3 | pelis plus

«Oldest ‹Older 401 – 450 of 450

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

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

Subscribe to Posts [Atom]