When you have an Angular directive that transcludes content, you might want to do something in case there is no content inside your element, like showing some default content.
Unfortunately, you can not do something like <span ng-transclude>default goes here</span>
. Angular will always empty that element's text, even if there is nothing to transclude.
But you can use your directive's link
function. Here's some CoffeeScript for you:
@app.directive 'myStuff', [->
restrict: 'E'
transclude: true
te...
Directly from the MySql docs:
There are three likely causes for this error message.
Usually it indicates network connectivity trouble and you should check the condition of your network if this error occurs frequently. If the error message includes during query, this is probably the case you are experiencing.
Sometimes the during query form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 s...
Great gem to consume RSS feeds. I was missing some features on Ruby's RSS::Parser
that I found in Feedjira:
length
attribute on an <enclosure>
tag on gizmodo.de's feed)The GitHub project has only a minimalistic readme. You can find its documentation on their homepage.
You know each_with_index
from arrays:
['hello', 'universe'].each_with_index do |value, index|
puts "#{index}: #{value}"
end
# 0: hello
# 1: universe
This also works on hashes. However, mind the required syntax:
{ hello: 'universe', foo: 'bar' }.each_with_index do |(key, value), index|
puts "#{index}: #{key} => #{value}"
end
# 0: hello => universe
# 1: foo => bar
The reason is that each_with_index
yields 2 elements to the block, and you need to deconstruct the first el...
So you erased a whole day's work? There is hope! The linked article tells how to recover from an accidental git reset --hard
.
You will need to install GNU find utils as described in this SO post.
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.
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...
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...
Open a MySQL root shell and use this command:
PURGE BINARY LOGS BEFORE DATE(NOW() - INTERVAL 3 DAY) + INTERVAL 0 SECOND;
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.
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).
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.
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 the RSpec.configure
block) to restore the old behavior:
...
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.
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 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
.
Provides an easy way to retrieve Google Page Rank, Alexa Rank, backlink counts, and index counts.
When making cross-domain AJAX requests with jQuery (using CORS or xdomain or similar), you will run into issues with HTTP headers:
X-Requested-With
header. On your server, requests will not look like AJAX requests (request.xhr?
will be false
).This is by design and improves secu...
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...
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.
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...
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 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)
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...
The attached RSpec matcher allows for comfortably testing delegation.
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.