The easiest way to detect touch-capable browsers is to check for the presence of touch events. It is no 100% solution, but has by far the best cost-benefit ratio. (Know that this does not detect touch devices, but browsers.)
var isTouchDevice = 'ontouchstart' in window
isTouchDevice = 'ontouchstart' of window
On the difference between the Javascript and the Coffeescript version, see [Beware: Coffeescript "in" is not the Javascript "in"](https://makandracards.com/makandra/31073-beware-c...
The Javascript in
operator does what Hash#has_key?
does in Ruby: Return whether an object has a property.
However, Coffeescript has its own in
operator that checks for array inclusion. To check whether an object has a property, use of
:
'name' in {name: 'Horst'} # => true
# wrong
'name' in {name: 'Horst'} # => false
# correct
'name' of {name: 'Horst'} # => true
1 in [1,2,3] # => true
True story.
TL;DR Block formatting contexts establish an isolating container. float
and clear
only apply to elements within such a container.
Block formatting contexts (BFCs) are important for the positioning and clearing
of floats. The rules for positioning and clearing of floats apply only to
things within the same block formatting context.
Floats do not affect the layout of things in other block formatting contexts,
and clear
only clears past floats in the same block formatting context.
To find a hash key by it's value, i.e. reverse lookup, one can use Hash#key
. It's available in Ruby 1.9+.
Hash#key(value) → key
# => Returns the key of the first occurrence of a given value.
If the value is not found, returns nil.
hash = { "a" => 100, "b" => 200, "c" => 300, "d" => 300 }
hash.key(200) #=> "b"
hash.key(300) #=> "c"
hash.key(999) #=> nil
tldr; Use git diff -M
or git diff --find-renames
when you've moved a few files around.
$ git diff --help
Options:
-M[<n>], --find-renames[=<n>]
Detect renames. If n is specified, it is a threshold on the similarity index
(i.e. amount of addition/deletions compared to the file’s size). For example,
-M90% means Git should consider a delete/add pair to be a rename if more than
90% of the file hasn’t changed. Without a % sign, the number is to be read as
a fraction, with a decimal point...
If your angular app is not served on /
, but on a different url (say /admin
), links generated with ui-router will not work when you open them in a new tab.
Fix this by adding this tag in your <head>
:
<base href='/admin#/'>
Helper method:
def base_tag
tag(:base, href: request.path_info + "#/")
end
Flickraw is a library to access flickr api in a simple way. It maps exactly the methods described in the official api documentation. It also tries to present the data returned in a simple and intuitive way. The methods are fetched from flickr when loading the library by using introspection capabilities. So it is always up-to-date with regards to new methods added by flickr.
Preview what your markdown would look like on Github. Helpful e.g. when writing or extending a Readme for your gem or projects.
sudo apt-get install cmake libicu-dev # required for building native extensions
gem install octodown
Know that this will install at least 12 other gems. However, the beautiful output should be worth it.
octodown README.md
greckout query
This will list all branches matching your query as input options for git checkout
greckout ar
1) ar/cache-api-keys-1098
2) ar/add-categories-object-to-tv-show-1382
3) ...
If you want to load an SQL dump from an ActiveRecord migration, you might find this to be harder than you thought. While you can call ActiveRecord::Base.connection.execute(sql)
to execute arbitrary SQL commands, the MySQL connection is configured to only accept a single statement per query. If you try to feed it multiple statements, it will die with You have an error in your SQL syntax.
You can work around this by opening a second MySQL connection that does accept multiple statements per call.
Below is an example for a migration that l...
In this post, I'll walk you through the four phases of the typical journey into coding and what you'll need to do to survive each of them.
If you're getting this strange error message when setting debugging breakpoints, probably HAML is the culprit.
As far as I could find out, the error is the result of setting a breakpoint (debugger
) in a helper method that's called from a haml partial.
Try putting the breakpoint into the HAML view.
I've pushed an update to Cucumber factory that simplifies working with FactoryGirl
factories.
Say you define a factory with the class:
option:
factory :admin, class: User
email
admin true
end
In the past, you had to write
Given there is a user (admin)
Now you can simply write
Given there is an admin
The class is inferred from the factory.
To only stub a method call if a given argument is used, but use the default implementation for other arguments:
object.should_receive(:some_method).and_call_original
object.should_receive(:some_method).with('my argument').and_return('other value')
Requires rspec-mocks
2.13+.
The Capybara API is somewhat hard for parse for a list of methods you can call on a Capybara node. Below you can find such a list. It's all copied from the Capybara docs, so all credit goes to the Capybara committers.
When you talk to Capybara from a Cucumber step definition, you always have page
as the document root node, or whatever you scoped to by saying within(selector) { ... }
. You can select child notes by calling page.find(selector)
or page.all(selector)
. You can call the same ...
If you get this error (probably because you want to load some modules):
# modprobe xt_comment
FATAL: Could not load /lib/modules/3.2.0-40-generic/modules.dep: No such file or directory
The reason could be that apt-get autoremove
already removed /lib/modules/.../modules.dep
even if you still using this kernel version:
# uname -r
3.2.0-40-generic
# ls -l /lib/modules/
total 24
drwxr-xr-x 4 root root 4096 Oct 22 17:05 3.2.0-68-generic
drwxr-xr-x 4 root root 4096 Jan 7 16:38 3.2.0-69-generic
drwxr-...
I couldn't successfully execute a simple iptables command and got this error on an Ubuntu server:
# /sbin/iptables -I INPUT ....
iptables: No chain/target/match by that name
The cause was that two modules weren't loaded: xt_multiport
and xt_comment
. Normally Ubuntu loads them automatically, but not this time due to another problem.
Geordi 1.0 features a command line application geordi
, that holds most of Geordi's previous commands.
command help and usage examples right within geordi
(geordi help
and geordi help <command>
)
quick command access: type just the first few letters of a command, e.g. geordi rs
or geordi dev[server]
command dependencies, e.g. geordi rspec
invokes geordi bundle-install
(which bundles only if needed)
no cluttered /usr/bin
, but all commands in one handy tool
template for easily adding new...
Add gem 'database_cleaner'
to your Gemfile. Then:
# features/support/database_cleaner.rb
DatabaseCleaner.clean_with(:deletion) # clean once, now
DatabaseCleaner.strategy = :transaction
Cucumber::Rails::Database.javascript_strategy = :deletion
The latest available cucumber-rails
for Rails 2 automatically uses database_cleaner
when cucumber/rails/active_record
is required -- but only if transactional fixtures are off. To have database_cleaner
work correctly:
When a gem author releases a new version to Rubygems, usually a tag with the version number (e.g. v1.2.0
) is created an pushed to Github, so everyone can check out or take a look at the source code at this point version release at a later time.
If you'd like to take a look at the Readme of a specific Gem version, you can easily switch to that git tag on Github.
Open Source Chrome Extension/App that can show you stories you're assigned over multiple projects and more.
Use this if you want to show or hide part of a form if certain options are selected or boxes are checked.
The triggering input gets an data-selects-visibility
attribute with a selector for the elements to show or hide, like
<%= form.select :advancedness, [['basic', 'basic'], ['advanced', 'advanced'], ['very advanced', 'very_advanced]], {}, :"data-selects-visibility" => ".sub_form" %>
The elements that are shown/hidden look like
<div class="sub_form" data-show-for="basic">
only shown for advancedness = basic
</div>
...