Skip to content

Instantly share code, notes, and snippets.

@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@zacstewart
zacstewart / anonymous_user.rb
Created October 2, 2012 17:35
Rails Soft Sign-Up
class AnonymousUser < User
attr_accessible *ACCESSIBLE_ATTRS, :type, :token, as: :registrant
def register(params)
params = params.merge(type: 'User', token: nil)
self.update_attributes(params, as: :registrant)
end
end
@machty
machty / new-router-examples.md
Last active April 16, 2020 22:03
How to do cool stuff with the new Router API
var get = Ember.get, set = Ember.set, doc = document;
var FastSelectComponent = Ember.Component.extend({
items: null,
valuePath: 'value',
labelPath: 'label',
value: null,
selected: null,
tagName: 'select',
@gelitenight
gelitenight / Example.java
Last active November 8, 2023 08:42
A way to easily traverse any view hierarchy in Android
/* basic usage */
ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
LayoutTraverser.build(new LayoutTraverser.Processor() {
@Override
public void process(View view) {
// do stuff with the view
}
}).traverse(root);
@garth
garth / emberViewExtension.js
Created December 30, 2013 16:01
Add support for keyboard shortcuts in emberjs views. Include keymaster.js and emberViewExtension.js and then see the example usage.
// enable keyboard shortcuts in views
Ember.View.reopen({
bindKey: function (shortcut, action) {
var controller = this.controller;
window.key(shortcut, function () {
controller.send(action);
});
},
unbindKey: function (shortcut) {
window.key.unbind(shortcut);
@machty
machty / document-title-router.js
Created January 14, 2014 05:12
document.title integration in ember
// Extend Ember.Route to add support for sensible
// document.title integration.
Ember.Route.reopen({
// `titleToken` can either be a static string or a function
// that accepts a model object and returns a string (or array
// of strings if there are multiple tokens).
titleToken: null,

Consider the example:

var MyObject = Ember.Object.extend({
  selectedContent: Ember.computed.filterBy('content', 'isSelected')
});

var obj = MyObject.create({
  content: [
    Em.Object.create({name: "one", isSelected: false}),
 Em.Object.create({name: "two", isSelected: false})