How to undo a 'git reset --hard'
So you erased a whole day's work? There is hope! The linked article tells how to recover from an accidental git reset --hard
.
On a Mac
You will need to install GNU find utils as described in this SO post.
Cucumber: Skipping steps in a scenario outline, based on the current example
In Cucumber, scenario outlines help avoiding tests that are basically the same, except for a few variables (such as different inputs). So far, nothing new.
The problem
Now what if your test should (or should not) do something, like filling in a field only for some tests?
Scenario Outline: ...
When I open the form
And I fill in "Name" with "<name>" # <= we want to do this only occasionally
Then everybody should be happy
Examples:
| name |
| Alice |
| Bob |
You could o...
Fixing Ruby debugger: *** Unknown command: "something". Try "help".
So you have placed a breakpoint somewhere and now want to dig around, but not even inspecting variables is working:
(rdb:3) @order_item
*** Unknown command: "@order_item". Try "help".
The reason is, you must tell the debugger to evaluate your expression. One workaround is to call irb
to open an irb session at your breakpoint. Resume by sending Ctrl+D
twice or by returning to the outer irb with "exit
" and then continuing with "c
".
However, the native debugger command for your issue is eval
(or its shorter alias `e...
Manually purge binary logs on MariaDB
Open a MySQL root shell and use this command:
PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY) + INTERVAL 0 SECOND;
6 front-end techniques for Rails developers. Part I: From big ball of mud to separated concerns
Amazing guide how to divide a ball of Javascript spaghetti distinct separate layers (model, view, controller, backend adapter).
It does not use a Javascript framework.
gazay/ids_please
Parses URLs of social networks to extract IDs or screen names.
It does not get confused by child routes: you may also pass URLs like a user's twitter photo stream and the gem will extract their twitter ID .
Note that it just parses URLs, and does nothing magic like looking up IDs when the URL contains only a screen name (e.g. the Instagram API requires you to send the user ID almost always while you at first only know their screen name).
Rails 4 drops support for the :assets group in Gemfile
Previously the assets group existed to avoid unintended compilation-on-demand in production. As Rails 4 doesn't behave like that anymore, it made sense to remove the asset group.
RSpec 3 no longer chooses a spec's type based on its directory
While RSpec 1 and 2 decided that specs inside spec/model
are model specs, and those inside spec/features
are feature specs (and so on), RSpec 3 will no longer do that by default.
This will result in errors such as missing routing helpers, etc.
There are 2 ways to fix this:
-
Explicitly set the type on each spec. For example:
describe '...', type: 'feature' do # ... end
-
Add this to your
spec_helper.rb
(inside theRSpec.configure
block) to restore the old behavior:...
Git: Listing branches with their latest author
Run this command to list the authors of the most recent commit of each branch:
git for-each-ref --format='%(committerdate) %09 %(authorname) %09 %(refname)' | sort -k5n -k2M -k3n -k4n
Credits go to DarVar on SO.
Test if all your favicons exist
When you don't only have a favicon.ico
in your project but also PNGs of different sizes and backgrounds, you should test if all those files are actually reachable.
Here are a few selectors to get you started:
'link[rel~="icon"]' # regular ones, matches "shortcut icon" and "icon"
'link[rel="apple-touch-icon"]' # iOS
'meta[content][name="msapplication-TileImage"]' # IE11
'meta[content][name^="msapplication-square"]' # IE11
A s...
Spreewald 1.1.0 released
Spreewald 1.1.0 drops the be_true
and be_false
matchers in order to be RSpec 3 and Ruby 2 compatible. For backward compatibility, these matchers are replaced with == true
and == false
.
blatyo/page_rankr
Provides an easy way to retrieve Google Page Rank, Alexa Rank, backlink counts, and index counts.
jQuery and cross domain AJAX requests
When making cross-domain AJAX requests with jQuery (using CORS or xdomain or similar), you will run into issues with HTTP headers:
- jQuery will not set the
X-Requested-With
header. On your server, requests will not look like AJAX requests (request.xhr?
will befalse
). - jquery-ujs will not set CSRF headers.
This is by design and improves secu...
Howto respond html or json in the same controller action with Rails 2
Code snippet tested with Rails 2.3
def index
# ...
if request.xhr?
html = render_to_string(:partial => "list", :layout => false)
respond_to do |format|
format.html { render :text => html }
format.json { render :json => {:html => html, ... } }
end
end
end
Note: Perhaps you ran into ActionView::MissingTemplate
error and this card might help. If you call render_to_string
within the format.json
block, Rails will only look for an index.json
template, but not for an `index.erb...
jpillora/xdomain · GitHub
Automagically makes XHR requests work cross-domain by tunneling all communications through an IFRAME on your page.
Note sure if it's a wise idea, but it's a thing now.
Defining Ruby strings with % (percent) notation
The attached post shows some alternative ways to define Strings in Ruby using the percent notation. This can be useful when you'd like to use quotes ("
) or single-quotes ('
) in your strings:
%(any alpha-numeric)
%[char can be]
%%used as%
%!delimiter\!! # escape '!' literal
%( (pa(re(nt)he)sis) ) #=> "(pa(re(nt)he)sis)"
%[ [square bracket] ] #=> "[square bracket]"
%{ {curly bracket} } #=> "{curly bracket}"
%< <pointy bracket> > #=> "<pointy bracket>"
%< \<this...
Ruby lets you redefine backticks
This actually works:
class Klass
def initialize
`hi world`
end
def `(message)
puts "Called with backticks: #{message}"
end
end
Klass.new # Prints "Called with backticks: hi world"
Hat tip to @jcoglan.
Spreewald 1.0.0 released
Spreewald now has a spreewald
binary that lists all available steps, optionally filtering them. Example:
$> spreewald
# All Spreewald steps
Given I am on ...
... long list
$> spreewald check
# All Spreewald steps containing 'check'
When I check "..."
When I uncheck "..."
Then the "..." checkbox( within ...)? should be checked
Then the "..." checkbox( within ...)? should not be checked
Then the radio button "..." should( not)? be (checked|selected)
Use byebug on Ruby 2+
The debugger
gem does not seem to be properly working on Ruby 2. Use byebug
instead!
Byebug is a simple to use, feature rich debugger for Ruby 2. It uses the new TracePoint API for execution control and the new Debug Inspector API for call stack navigation, so it doesn't depend on internal core sources. It's developed as a C extension, so it's fast. And it has a full test suite so it's reliable. Note that byebug works only for ruby 2.0.0 or newer. For...
RSpec 1.x matcher for delegations
The attached RSpec matcher allows for comfortably testing delegation.
Examples
describe Post do
it { should delegate(:name).to(:author).with_prefix } # post.author_name
it { should delegate(:month).to(:created_at) }
it { should delegate(:year).to(:created_at) }
end
Credits go to txus. See the attached link for an RSpec 2+ version.
Google Material Design with AngularJS
The material design project for Angular is a complementary effort to the Polymer project's paper elements collection. Our goal is to provide a set of AngularJS-native UI elements that implement the material design system.
Google Material Design as Polymer components
The Paper elements are a set of UI elements that implement the material design system.
Sass function to set a color to an absolute hue
The adjust-hue
function of Sass allows you to change a color's hue, but only relative to its current hue.
adjust-hue(#ffff00, 120)
// => #00ffff
adjust-hue(#444400, 120)
// => #004444
As you can see, we moved our yellow by 120° to cyan. \
But what if you want to move any color to a hue of 120° which is a nice shiny green?
Take this function:
@function set-hue($color, $target-hue)
$current-hue: hue($color)
$degree...
Skype 4.3 for Linux fixes group chats
Skype has been updated to 4.3 on Linux. This fixes group chat issues with non-linux clients.
If you have previously installed skype via ubuntu packages, you need to remove those fist via
sudo apt-get remove skype skype-bin
Note
Try to install the 32 bit version. In serveral cases this was the way that worked out.
Grab the installer here: