Ask for Help
"In an android web browser, if I have an autocomplete menu, and I click on one of the items, the click is registered on that item, but also seems to pass through to the elements behind it. For instance, a different text input was behind it, and became focused."
"Yep, that bug sucks." "The world may never know."
Interesting Things
Fixnum's
[]operator works! According to the ruby docs"Bit Reference—Returns the nth bit in the binary representation of fix, where fix is the least significant bit."
# 2:Fixnum in binary is 10, right? So… 2[0] = 0 2[1] = 1Also:
a = 0b11001100101010 30.downto(0) do |n| print a[n] endproduces:
0000000000000000011001100101010innotop
innotopis a 'top' clone for MySQL with more features and flexibility than similar tools. It'll let you do all sorts of dangerous things to your database! Have fun!!Parse.com apparently accepts job applications via API! Check it out at https://parse.com/jobs#api
jQuery and the
resizeevent – If you trigger aresizeeven on any object other than the window, it will not trigger the binding on that element. It will, however, trigger anyresizebindings you have on window.Did you commit to git under the wrong author's name and email? Use
--ammend --reset-authorafter committing, but before pushing (unless you want a pain in the tuchus)mkdir foo cd foo git init touch README git config --global user.name "Santa Claus" git config --global user.email "santa@claus.no" git add . git commit -m "Commit from Santa Claus" git show # commit e5f4ebe6c689ddbf4ff595855fec544da5d8ce01 # Author: Santa Claus <santa@claus.no> # Oops! I'm not Santa Claus git config --global user.name "Easter Bunny" git config --global user.email "easter@bunny.cl" git commit --amend --reset-author git show # commit d523479d487d04388972bea872913ffda734ef89 # Author: Easter Bunny <easter@bunny.cl>Looking to game the system on Superbowl Game day? Check out Onsi's Super Square http://supersquare.heroku.com/ stats app for your Squares pool.
Interesting Things
- When using TimeCop to travel in time in your specs,
Timeworks normally, howeverDateTimewill round to the nearest second. You have been warned
Help!
"What's going on with Facebooker and :class/:class_name_?"
Normally, in an ActiveRecord class definition you can use :class_name to change the class of an association.
has_many :foos, :class_name => 'Bar'
With Facebooker installed, one project found that their project was able to use :class
has_many :foos, :class => 'Bar'
When Facebooker was removed, it all blew up. No one had a solid answer as to why this worked in the first place.
"How do can we tell if our app's email has been marked as spam like Campaign Monitor claim to do? How else can I get spam reports?"
*"Does anyone know to get this info from ISPs?"
Services like Return Path can give you aggregate reports, but not specifics.
All other suggestions were vague and/or said "Contact the ISP."
*"How do I sign up for Heroku with a Google Group email?"
Allow non-member emails. You want to do this before you sign up, because some Pivots have reported that they could not get a second confirmation message to be sent.
Interesting Things
- If you haven't noticed, Jasmine tests are at least twice as fast in Chrome as they are in Firefox. Closing the inspection pane makes it even faster. Be aware that part of the speed is from Chrome's aggressive caching, which can lead to erroneous test results.
- One team is using Backbone's local storage. When they add
model.clear()after every test run, their tests go from 20 seconds to over 100 seconds. Someone suggested thesilent: trueoption, to suppress thechangeevents thatcleartriggers. - To avoid bugs in minified JS put semicolons in the right spots. The easiest way to do that is to run a tool like JSLint or JSHint over your code. Add it to your test suite to prevent mistakes.
Ask for Help
- "In IE8 the numbers don't show up on ordered lists if we dynamically create
lis"
Or rather, they do, but only after hovering over the list. The common wisdom is that this has been broken in IE for a long time.
- "Our project does some DNS resolution. Is there a preferred way to mock this in tests?"
No suggestions.
- "When replying to an email each email system adds different junk to the message. We're processing those incoming replies. Any standard way to strip out the junk?"
Everyone is using the ugly regex approach. Are there mail gems that handle this?
Interesting Things
- There's a new release of Backbone - 0.9.0. It's billed as a release candidate for 1.0, and seems to be a bit buggy, as RCs can be. However, it's exciting to see that Backbone is getting close to that milestone.
- You should default boolean fields to true or false, at the database layer. Otherwise your queries have to deal with three-valued logic.
- Rails 3.2 has some unexpected behavior. First, the generated form ids have changed ... what used to be
id=user_newis nowid=new_user. Second, if your routes file is missing an entry, you will no longer get errors in controller tests. If you liked that behavior, try out request specs.
Ask for Help
- "Anyone seen problems with the latest REE and iconv?"
Everything works on the Linux machines, but on Macs, there's an error about an unrecognized target encoding. Iconv works on the command line, so it's something about REE.
Inheritance in Backbone
Backbone.js comes with a minimalist OO inheritance framework similar to the one employed by CoffeeScript. Each base class has a static method called extend that is used to create a subclass, like this:
User = Backbone.Model.extend({
// instance methods
},
{
// class methods
});
extend returns a constructor whose prototype inherits from Backbone.Model.prototype. References to all of Backbone.Model's static methods and properties (including extend) are copied to the new constructor.
Calling 'super'
The constructor also receives a __super__ property, which references its superclass.
User.__super__ === Backbone.Model
This makes it possible to call super inside of a class or and instance method:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
User.__super__.save.apply(this, arguments);
};
CoffeeScript has a super keyword that compiles to the line above, but when using Backbone with plain javascript, its a little grating to have to type that out.
A small layer of convenience
I wrote this little super method (test-driven using jasmine) which saves me having to repeat the constructor's name all over the place. You call it like this:
User.prototype.save = function(attrs) {
this.beforeSave(attrs);
this._super("save", arguments);
};
The second parameter to _super is the array of arguments to pass to the overridden method. This is to optimize for the common case of passing the arguments object straight through.
There's no way to avoid having to repeat the method name like that, unless you wrap every method definition with a helper function that either passes the overridden method as a parameter (a la Prototype.js) or reassigns a hidden super property behind the scenes (like JS.Class or John Resig's approach). These approaches won't work with Backbone's ultra-minimalist inheritance system.
Interesting Things
should_not render_with_layoutcan be flaky. For example, asserting that an XHR request doesn't have a layout could fail if the request renders an email template that does have a layout. These matchers are not very sophisticated, mostly doing string matching, not real template resolution.
Ask for Help
- "How do I test relative time with FixtureBuilder?"
Since the models are all built beforehand, it's tricky to write tests that make assertions about relative time. There were a variety of suggestions. You can write all the tests relative to a model: some_time.should == model.created_at - 3.days. You can wrap the entire suite and fixture generation in a Timecop block, but you'll have to deal with losing that context whenever any test calls Timecop.return.
- "How do I separate multiple FixtureBuilder files, but allow them to reference objects created in each other?"
Typically you want to separate fixtures into smaller files. But, you also often want to reference objects in other files, for example so you can assign a user from user_fixtures.rb to a post in post_fixtures.rb. One solution is to eval each file in a loop, so they can share instance variables. You can also use User.where(:name => "Tom") but that's awkward and repetitive.
- "Any suggestions for a CMS that would allow lots of different visual presentations of the content?"
The questioner is experimenting with branding. Not many suggestions... a shared database perhaps?
Interesting
- Assigning a collection with an
=operator will not set the id on the parent object, to do this use<<.
Events
- This weeks brown bag will be on SQL, three of our Australian pivots will be presenting it. You can join our meetup group to find out more information.
We recently came across a situation in our markup where we wanted whitespace in the markup for readability, but we didn't want that whitespace represented between the elements.
We found a fix that suggested using font-size: 0 in CSS to eliminate the whitespace. That worked fine in Chrome, but we found that in Firefox, the containing element no longer scrolled with the mouse wheel or arrow keys! Apparently Firefox's scroll speed is proportional to font-size.
Ask for Help
How to scrub production data
- try my_obfuscate
- use handcrafted update-all sql
Interesting Things
- Do not stretch monitor cables, they make the ports break
- MySql: Different os have different rules on table case sensitivity(My_Table <-> my_table), be strict or you get into trouble
- validates_acceptance_of can crash your asest:precompile on heroku (because it uses the db when loaded, but db is not yet ready), least hacky solution: validates_acceptance_of xxx unless ENV['RAILS_ASSETS_PRECOMPILE']
