Max has an almost-there solution that he sent out to the mailing list:
Rails.application.assets["application"].dependencies.map do |asset|
"assets/" + asset.logical_path
“I’m looking for a client-side JS syntax highlighter!”
- Don’t use: pygments — it’s what GitHub uses and is server-side only.
- Consider using: code mirror
That slowness when you start Terminal? It’s parsing through all your system logs to figure out when the last log-in occured. Speed up your terminal with
http != https — who knew? Turns out sending an AJAX post from a non-secured origin (http) to a secured end point (https) smacks agains the same-origin policy. Solutions?
- Bring up and iframe pointed to https and AJAX post from there.
- Or (better): Enforce SSL on the originating page.
Ask for Help
What’s the best way to think about redirects for API calls? e.g. You post to create an object, what should you get in return?
The crowd: Some concensus emerged around: send back a 201 with a location header pointing to the url for the object and a body containing the object itself.
Mongoid’s atomic operations don’t trigger hooks (before_save, after_save, etc…)
The crowd: Crickets…
haproxy, like nginx, can pass http connection through with the header ‘X-Forwarded-For’ set so that it is possible for the app to know the original client IP. But haproxy doesn’t have support for serving as an SSL endpoint, so https:// connections are proxied in tcp mode instead of http mode. And no headers can be added because the request remains encrypted.
Terminate the SSL connection in front of haproxy. PIvots suggested doing this via an additional nginx instance. Online resources show how to do this using stunnel. (http://www.completefusion.com/ssl-load-balancing-with-haproxy-and-stunnel-on-debian/)
Use nginx as the load balancer and discontinue using haproxy, or find a load balancer that fully supports SSL.
Build HAProxy with TPROXY support. http://blog.loadbalancer.org/configure-haproxy-with-tproxy-kernel-for-full-transparent-proxy/
Ask for Help
“Reloading of models under spork?”
From hybrid-cutlery expert Sobo:
Spork requires you to divide your spec helper into two phases, before fork and after fork.
Before fork, you want to do time consuming things like loading the Rails environment, so you don’t have to pay that cost on each test run.
If you end up requiring model classes or other volatile files before forking, then they won’t be reloaded for each test run.
This can happen, for example, when you use Devise route helpers, which touch the User constant during route evaluation.
This causes user.rb to be auto-required before fork.
Since the User constant is defined after forking, Rails won’t autoload changes to User, forcing you to restart the Spork server every time you change it.
There are two solutions:
- The first is simply to avoid loading models or other code you want to auto-reload before fork.
- If you must refer to models before fork, as is the case with the Devise route helpers, then put an explicit
require because it won’t load the file if it’s already been loaded) in your after fork block for the files that were loaded before fork.
This will force them to be reloaded.
- It’s open season on open enrollment. SF will have an info session today at 12:30. Pizza will be served. Y’all have between now and December 9th to make changes.
- Those with mohawks and staches in SF are encouraged to take a picture at the Vermehr e-mail station (closest e-mail station to the bathrooms).
Ask for Help
“Postgres SELECT * GROUP BY insists that all selected fields must either appear in the GROUP BY or be aggregated.”
Many agreed that this is, in fact, how a database should behave and that MySQL’s leniency on this matter is faulty. If you select a field that you don’t group by, you must tell Postgres how to combine the sub-set of values that fall in a given group into a single result (should it take the max? the min? the mean? the most purple?).
Ask for Help
“I have a fresh install of Rails 3.1 and when I run specs with rake (with the development server running) it complains that the database is already in use.”
A chorus of replies: “I hate it when it says that.”
Looks like the test suite is trying to use the development DB. Try:
RAILS_ENV=test rake ...
It was pointed out that a call to rake that does not explicitly specify RAILS_ENV typically runs in development mode, detects that tests are being run, then switches to test mode. Any code that runs before the environment switch (in initializers, say) will run against the development DB.
“I have a large inherited cucumber suite that consistently fails on CI…. unless I screen share in and watch it. Why do I need to peek for my tests to pass?”
The likely answer: The very act of screen-sharing causes the test-suite to slow down. Use the setSpeed method in Selenium to force Selenium to take a breather between commands (the passed in value is in milliseconds).
Ask for Help
“We’re trying to get the Google Docs API working on our project but we keep hitting unauthorized/bad request responses. Help!”
One thought: some ruby OAuth implementations are known to fail. Try shelling out and running a command line OAuth to make sure this isn’t an incompatibility with your ruby OAuth library.
Ruby is slower than node.js.
Two loops and a square root turns out to be a recipe for ruby slowness. The v8 engine wins again!
Ubiquitous Singaporean Chile (”Sambal Chilli”) now available – briefly – in the San Francisco lounge (courtesy of Nate Clark).
To quote Nate: “It’s usually Shrimp based but this is the Vegetarian version which I find to be pure and good.”
Gogaruco sign up is now open.. and the early bird tickets are gone. Sign up soon!
(Title: Standup 7/18/2011: I Bless the Rains Down in Africa)
Ask for Help
“I want a super-lightweight rack-based CMS/blogging setup. Any thoughts?”
Try out Toto a light-weight git-powered blog engine.
Ask For Help
We’re running into a problem where MongoMapper is somehow setting the value of a ‘many’ relationship to null in the parent document, which then makes MongoMapper blow up when trying to load the parent doc from mongo. There’s an argument to be made that MongoMapper shouldn’t blow up, but it’s understandable that it’s confused when the key exists – here’s a spec demonstrating what happens when the null exists in
The big question is what is creating these values. All our inserts are through MongoMapper, so we’re blaming a bug we can’t reproduce in MongoMapper for the moment.
How to fill up your Redis instance (part 2). Resque stores all records of failed jobs – including full backtraces – on Redis. Pushing a bug that generates lots of these can rapidly fill up your Redis instance. The solution? Send your Resque errors directly to hoptoad (which has better error management infrastructure anyway).
To get it running:
$ gem install fuubar
$ repsec --format Fuubar --color spec
Kevin Kelly, Founding Executive Editor of Wired Magazine and noted technologist will be at Pivotal Labs tomorrow (Thursday January 13th, 2011) at 6:30pm to talk about his latest book What Technology Wants.
For details look here.
Ask for Help
“Does Active Record have batched insert? I need to dump 10,000 rows into the database in process and I don’t want it to take 45 seconds.”
The upshot: use a raw SQL
For a day as interesting as today (1/11/11 anyone?) there were surprisingly few interesting things of note.
Ask for Help
A pivot asks: “Anyone know anything about data warehousing & ETL?”
A handful of pivots raise their hands.
Another pivot asks: “How about Radiant CMS?”
More pivots raise their hands.
before(:all) in Rspec raise an exception the return code coming back is 0. This breaks CI.
before(:suite) — this runs, just once, before all other befores.
In MongoMapper if you have a key (field) with type Hash, and set a default value, that default value points to a reference instantiated at class loading time. Instances inherit a reference to the same object (instead of a copy) which means any changes to to an instance with the default value propagate to all future instances using default. The immediate work-around is to wrap the value in a lambda, but within hours of reporting the bug there was a fix on HEAD.
splunk users meetup here (at Pivotal Labs in SF) on Wednesday January 12th. More details on meetup.com.
A global Rspec
before(:each) defined in
spec_helper.rb apparently does not have access to fixtures. One admittedly klunky workaround involves
config.include a Module, and then a
class_eval inside the included hook of the module. This has the unfortunate property that the
before(:each) will run multiple times, once at every test level, instead of just once at the top level — though this can be fixed by looking at the length of ancestors in the included hook in the module and only doing the
before(:each) if you are on the first level. Others argued that fixtures should be available in a
before(:each) and that the problem is a load-order issue.