Skip to content

Instantly share code, notes, and snippets.

Use Capybara as genius

Purpose

Capybara uses selector css to find elements, we can do more than ".my-class" or "#my-id". XPath can be used to look for elements using different syntax, see above exemple.

Exemples

Sublime hidden Shortcut, macro

All shortcuts

You can find all shortcut in Preferences -> Key bindings - Default

Usefull shortcut

super+k, super+b -> Toggle side bar

super+k, super+v -> Get more paste

@LolWalid
LolWalid / collection_methods.rb
Last active December 10, 2015 10:19
Class methods apply to collection - Ruby
class MyModel < ActiveRecord::Base
scope :custom_scope, -> { where.not(id: [1, 2, 3]) } # id not in (1, 2, 3) <=> id != 1 and id != 2 and id != 3
def self.class_method
all.each { |x| puts x }
end
def to_s
'Hey'
end
@LolWalid
LolWalid / references.rb
Created December 16, 2015 15:49
All is reference !
# toute donnée est un objet, y compris les types ;
# toute fonction est une méthode ;
# toute variable est une référence à un objet ;
a = [1, 2, 3]
b = a
a << 4
@LolWalid
LolWalid / How_to_route.rb
Last active January 13, 2016 14:11
Beautiful routes
# params[:id] || params[:my_model_id]
# routes.rb
MyApp::Application.routes.draw do
resources :my_models do
collection do
get :search # GET /my_models/search(.:format)
end
member do
post :disable # POST /my_models/:id/disable(.:format)
@LolWalid
LolWalid / active_record_guide.rb
Last active January 20, 2016 14:53
Some tips using active record, check the documentation
# http://guides.rubyonrails.org/active_record_querying.html
class Article < ActiveRecord::Base
has_many :comments, -> { order('posted_at DESC') }
end
##### REORDER #####
Article.find(10).comments.reorder(:name)

Pushbullet

Your devices working better together

Pushbullet

Redirect all your notifications ! (Receive text message in your computer).

Send text message from your computer.

API

API

@LolWalid
LolWalid / cool_class.rb
Last active January 28, 2016 15:20
How to define private class method ruby
class CoolClass
# This is the documentation
# # return a string containing Something Cool or Something Coolest !
# arg1 = boolean # Default value to true
# CoolClass.cool_method # return 'Something Cool'
# CoolClass.cool_method(false) # return 'Something Coolest'
def self.cool_method(arg1 = true)
return public_method1 if arg1
private_method1
@LolWalid
LolWalid / noti.sh
Last active January 27, 2016 13:12
# https://github.com/variadico/noti
noti ls
noti -t "Reply to Pedro" -m "Don't forget Pedro" sleep 1&
export PUSHBULLET_ACCESS_TOKEN="Token"
noti -p "Realy don't forget pedro"
@LolWalid
LolWalid / custom_object.rb
Last active January 28, 2016 08:49
Operator Overloading in ruby
class CustomObject
attr_reader :a, :b
def initialize(a, b)
@a = a
@b = b
end
def ==(other)
(@a + other.a) == (@b + other.b)
end