-
Ruby FreshBooks Integration
By Jonathan Siegel / 02:06 AM / 0 CommentsHaving trouble integrating FreshBooks? So were we.
Some gotchas:
- The README is often incorrect.
- Update doesn't work. Use our gem.
- Status for estimates is an integer, not string: 1 draft, 2 sent, 3 viewed, 4 replied 5 accepted, 6 invoiced
- Check the result for invoice.update. If it's false, there's an error. Edit the gem to turn on debug statements around lib/freshbooks/connection.rb:call_api
- To download the pdf, you must set the status to 'sent' for a draft (remember to set it back!).
- Install it: gem install elc-freshbooks.rb --source http://gems.github.com
Full code to download an invoice or estimate PDF:
TutorialTutorial -
Auto updating sphinx delta on child record updates
Thinking Sphinx is quickly becoming the de-facto rails search plugin. In the past there have been a few other plugins that gained popularity and lost it almost as quickly by either being orphaned, outdated, etc. Thinking Sphinx has a clear path and a very involved/attentive maintainer.
ArticleArticle -
Scraping Images from Twitpics
By Alex Chee / 12:32 AM / 2 CommentsRecently, I've been scraping Images and videos from Twitter and one site that has not been too easy to grab pics from is Twitpics. Here's a snippet of code that I've been using to grab the image from Twitpic with Hpricot:
require 'net/http' require 'hpricot' def rip_twitpic(url) begin code=url.match(/[\w]+$/).to_s unless code.blank? uri=URI.parse(url) resp=Net::HTTP.get_response(uri) html=Hpricot(resp.body) html.at("#photo-display")['src'] end rescue Exception => e puts "Error extracting twitpic: #{e}" url end end
SnippetSnippet -
Listen up, Señor T is talking to you. If you have ever tried to spend 8 hours working from a coffee shop, then I don't have to tell you that it's not all that it's cracked up to be. Yes, its a fun dynamic working environment, where people will make you coffee and tasty snacks. However, spotty internet connections, loud music, chatty patrons and lack of power outlets get old quick. But for a cybernomad like me, plopping down a monitor on a desk just isn't an option.
ArticleArticle -
ReCSS - AJAX friendly CSS testing
By Gregor Martynus / 04:28 PM / 0 CommentsBack in the days when the web didn't yet have a version number, David from dojotoolkit.org came up with a neat solution to reload your css without the need of reloading your page: ReCSS.
It's just a simple bookmarklet that walks through all linked stylesheets and reloads them. This omits page reloads in order to test your CSS changes, very helpful for AJAX heavy sites. Here is what the code looks like:
javascript: void(function() { var i, a, s; a = document.getElementsByTagName('link'); for (i = 0; i < a.length; i++) { s = a[i]; if (s.rel.toLowerCase().indexOf('stylesheet') >= 0 && s.href) { var h = s.href.replace(/(&|%5C?)forceReload=\d+/, ''); s.href = h + (h.indexOf('?') >= 0 ? '&': '?') + 'forceReload=' + (new Date().valueOf()) } } })();
This is one of the small things that makes my life easier, and I want to make sure that it does the same for you. Drag the following link to your Bookmarks toolbar and become a CSS rockstar: ReCSS
SnippetSnippet -
Dealing with ajax has become so easy and high-level that it is pretty easy to forget about the details. A nice habit to get into when dealing with an ajax-heavy frontend is to manage the event listeners and connections that a user can initiate.
Something simple to remember is that you can't rely on your requests to complete FIFO because your requests are getting routed across multiple processes/machines that may or may not be under load. Alot of users are rather click-happy (my mom still double-clicks links) which can lead to problems with content that was requested on the first click being loaded after the content from the most recent click.
In the past I have always included sequence numbers as request ID's and then have the server include the request ID it is responding to in the JSON response. This gives the event handlers some context of the response it just received in relation to the most recent action the user has performed on the page.
This works well, but sometimes you just want to throw out any response that is not in response to the most recent request. This is where the abort() method is useful.
var current_conn; function getSome() { if(current_request) {current_request.abort();} current_request = $.get('/events', { team : "Ramrod" }, function(resp) { alert(resp); } ); }
If you need to, you could use the sequence number approach and create a response queue or other more complex solution. Here are a few neat ideas as well...
SnippetSnippet -
pdf2swf on Mac OS X and ASVM mismatch
By David Palm / 01:52 PM / 0 Comments
The current version of swftools in macports is 0.8.1 and for many cases it's not good enough. In particular, for pdf2swf to generate swf files that are recognized as ASVM3 (i.e. Flash version 7+ I think, but do correct me if I'm wrong) you need swftools 0.9.0 or greater. Loading an external swf movie from within another is considerably more cumbersome if the virtual machine used in the two files versions differ.
You know you ran into the above VM mismatch error if your Flash logs are telling you something like this:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@1e3d9e01 to flash.display.MovieClip. at com.elctech::PdfViewer/doneLoading()
The above error will show only if -- only if -- you have a debugger enabled flashplayer and logging enabled.
But as we said, the current macports version isn't recent enough, so what to do? One option is to install everything from source, which for a package such as swftools entails a lot of dependencies. Another option is to install the current macports version anyway to get all the dependencies installed and then compile just the swftools package from source (http://www.swftools.org/download.html). Not ideal perhaps, but IMHO better.
ArticleArticle -
With the 3.0 update coming out for the iPhone, people have been talking about one of the new features called tethering. Tethering is the process of using your mobile device's internet connection on your computer. This allows you to have internet on your computer anywhere there is cell service.
While phones like the Blackberry and Palm have had tethering for a few years, Apple has finally updated the new iPhone to include this feature. The problem is the US carrier for the iPhone (AT&T) will not support tethering for quite some time. And when they do decide to support it, they will charge an additional monthly fee.
ArticleArticle -
Distributed Sphinx
By Dylan Stamat / 01:41 AM / 1 CommentWhile installing Sphinx for a largish application, I wasn't able to find many documented examples that touched on distributed deployments. The examples I did find were either a bit complicated when it comes to setup and execution, or, they didn't necessarily meet my needs. I "think" my needs are pretty simple:
I need indexing to be fast, searching to be fast, result sets to be up-to-date, and, this painlessly deployed across a large and dynamic array of machines.
ArticleArticle -
Upgrade GIT on OS/X
By Jonathan Siegel / 09:54 AM / 0 CommentsThere's a new GIT version out with at least 10 reasons to upgrade. OS/X users of MacPorts can get the GIT upgrade with:
$ sudo port selfupdate $ sudo port upgrade git-core # not git!
If you try this on your MacBook Air like I did be prepared for massive sluggishness for up to 2 hours.
Don't Forget
To remove that annoying message you now get with git push:
TutorialTutorial -
Your STI Broke My Sphinx
By ceberz / 04:37 AM / 2 CommentsIf you're using Ultrasphinx in your rails application and you have models using ActiveRecord support for Single Table Inheritance, it might not work they way you;d like. Actually it will break.
SnippetSnippet -
Stubbing a method for all tests
By David Palm / 10:31 AM / 0 CommentsIf you ever need to stub out a method for all tests in your test suite, for example a before filter in ApplicationController that goes takes a while to run, here's a neat trick.
Stick the following in your spec_helper:
Spec::Runner.configure do |config| config.before(:each, :type => :controller) do controller.stub!(:blog_feed).and_return([]) end end
If you need to override the above for some specs, just put a similar block on top of the spec file. (Question: how can I remove the stub completely for just a few tests?)
It might not be the most elegant solution known to man, and it sure isn't very clean and could come back and bite you one day, but if you know what you're doing... ;)
Update: Something like this might work for your unstubbing needs, but if the above is an ugly hack, this is a really ugly hack and YMMV:
class Object def unstub!(method_name, *args, &blk) self.send("proxied_by_rspec__#{method_name}", *args, &blk) if self.respond_to?("proxied_by_rspec__#{method_name}") end end
If you need to poke even deeper (and you really shouldn't), this might be useful to you:
rspec_guts = my_instance_of_something.send(:__mock_proxy) # rspec works its magic on this object, which is a Spec::Mocks::Proxy puts rspec_guts.instance_variable_get("@proxied_methods").inspect
ArticleArticle -
Deep Linking Pagination with jQuery Address
By Cary Dunn / 07:17 PM / 0 CommentsWith most sites today so heavily reliant on loads of asyncronous requests with javascript, json/p, flash, etc. It can be quite frustrating when trying to navigate a JS image gallery or RSS reader while also making sure never to accidently hit back/forward/refresh so that you do not lose your place in browsing. Want to send a link to the specific photo you are browsing in a JS gallery? Good luck getting your friends to click the link and then hit "Next" 32 times to see the specific photo.
Facebook does a great job at keeping all of their heavy javascript pages (such as the photo gallery) deep-linked so this is not an issue.
In the past, the most popular library for deep-linking was swfAddress and was primarily used for Flash. swfAddress now supports AJAX though the same team has also released a lightweight version for jQuery called jQuery Address.
To demostrate deep-linking with jQuery Address I put together a quick demo of deep-linked pagination of a Flickr photo gallery as an example. You should be able to use your back/forward/refresh/bookmark functions just fine.
View Demo
TutorialTutorial -
The case of mysterious user interface
By Rick / 07:06 PM / 0 CommentsUntil web coders and designers become one and the same, how does one deal with designing a website that is user interface heavy? Does it mean that all designers should learn to code? Or should all coders learn how to design?
ArticleArticle -
RightSignature Featured on TechCrunch
By Daniel LaBare / 03:25 AM / 0 Comments
ArticleArticle
Viewing 352
Posts











