Skip to content

Instantly share code, notes, and snippets.

View andreaseriksson's full-sized avatar

Andreas Eriksson andreaseriksson

View GitHub Profile

###Text Delete word: dw
Delete line: dd
Delete rest of the line: D or C
Undo: u
Redo: ctrl+r
Yank: y or Y
Copy the line: yy
Copy the word: yw
Paste the copied or deleted text after the current line: p

###Navigation character left, right; line up, down: h l k j

word/token left, right: b w

Move to the end of a word: e

Move forward to the beginning of a word. w

Move forward three words. 3w

=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')
@andreaseriksson
andreaseriksson / gist:8537613
Created January 21, 2014 10:24
Emails regex matching
emails = %w/ [email protected] [email protected] 23214sdj^as
[email protected] /
pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/
emails.each do |email|
if email.match pattern
puts "#{email} matches"
else
@andreaseriksson
andreaseriksson / gist:7579624
Created November 21, 2013 10:49
rspec test mail attachments
mail.attachments.should have(1).attachment
attachment = mail.attachments[0]
attachment.should be_a_kind_of(Mail::Part)
attachment.content_type.should be_start_with('application/ics;')
attachment.filename.should == 'event.ics'
@andreaseriksson
andreaseriksson / gist:7577235
Created November 21, 2013 07:10
Converts a dotted hash to nested hash
def to_dotted_hash(hash, recursive_key = "")
hash.each_with_object({}) do |(k, v), ret|
key = recursive_key + k.to_s
if v.is_a? Hash
ret.merge! to_dotted_hash(v, key + ".")
else
ret[key] = v
end
end
end

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
@andreaseriksson
andreaseriksson / gist:5662460
Created May 28, 2013 12:35
RAILS Simple form
f.error_messages
f.input :username
f.button :submit
f.input :username, label: 'Your username please'
f.input :password, hint: 'No special characters.'
f.input :email, placeholder: '[email protected]'
f.input :remember_me, inline_label: 'Yes, remember me'
f.input :username, label_html: { class: 'my_class' }
<strong class="code" id="message">Hello, World!</strong>
%strong{:class => "code", :id => "message"} Hello, World!
%strong.code#message Hello, World!
================================================================
<div class='item' id='item<%= item.id %>'>
<%= item.body %>
</div>
.item{:id => "item#{item.id}"}= item.body
================================================================