Simple Naming for Modular CSS Class Names ··· Nico Hagenburger
An opinion how to implement BEM. I don't agree with all of Nico's choices, but I applaud his approach to compile a simple and short list of rules.
Git & Mac: Working with Unicode filenames
I had some problems with Git and the file spec/fixtures/ČeskýÁČĎÉĚÍŇÓŘŠŤÚŮÝŽáčďéěíňóřšťúůýž
. After pulling the latest commits, it would show that file as untracked, but adding and committing it would throw error: pathspec 'check in unicode fixture file once again' did not match any file(s) known to git
.
Solution
Install Git version > 1.8.2 using homebrew and set
git config --global core.precomposeunicode true
Done.
Reason
According to the linked Stackoverflow post ...
... the cause is the different im...
The "private" modifier does not apply to class methods or define_method
Ruby's private
keyword might do a lot less than you think.
"private" does not apply to class methods defined on self
This does not make anything private:
class Foo
private
def self.foo
'foo'
end
end
You need to use private_class_method
instead:
class Foo
def self.foo
'foo'
end
private_class_method :foo
end
"private" does not apply to define_method
This does not make anythin...
Firefox file upload breaks after a few megabytes
- A short browsing revealed that this may be a current firefox issue
- Current workaround: use another browser
- If you have further helpful information, please notify me
RSpec: Where to put shared example groups
Shared example groups are a useful RSpec feature. Unfortunately the default directory structure generated by rspec-rails
has no obvious place to put them.
I recommend storing them like this:
spec/models/shared_examples/foo.rb
spec/models/shared_examples/bar.rb
spec/models/shared_examples/baz.rb
spec/controllers/shared_examples/foo.rb
spec/controllers/shared_examples/bar.rb
spec/controllers/shared_examples/baz.rb
To ma...
Render a view from a model in Rails
In Rails 5 you can say:
ApplicationController.render(
:template => 'users/index',
:layout => 'my_layout',
:assigns => { users: @users }
)
If a Request Environment is needed you can set attributes default attributes or initialize a new renderer in an explicit way (e.g. if you want to use users_url
in the template):
ApplicationController.renderer.defaults # =>
{
http_host: 'example.org',
https: false,
...
}
...
RubyLTS
RubyLTS is a long term supported fork of Ruby 1.8 that will continue to receive security updates for the forseeable future.
Remote Debugging on Android - Chrome DevTools
The Google Chrome DevTools allow you to inspect, debug, and analyze the on-device experience with the full suite of tools you're used to, meaning you can use the Chrome DevTools on your development desktop machine to debug a page on your mobile device.
angular/angularjs-batarang
Extends the Chrome WebInspector so you can debug AngularJS applications and hunt down performance issues.
It's really, really good.
Many box shadows will make your app unusable on smartphones and tablets
Box shadows are awesome. Unfortunately they are also very costly to render. You will rarely notice the rendering time on a laptop or desktop PC, box shadows can make your app completely unusable on smartphones and tables. By "unusable" I mean "device freezes for 10 seconds after an user action".
But isn't it the future?
Not yet. Eventually mobile devices will become powerful enough to make this a no...
Git: How to remove ignored files from your repository's directory
When you have files in your .gitignore
they won't be considered for changes, but still you might want to get rid of them, e.g. because they clutter your file system.
While a regular git clean
will ignore them as well, passing the -x
switch changes that:
git clean -x
If you want to see what would happen first, make sure to pass the -n
switch for a dry run:
git clean -xn
Clean even harder by passing the -f
(force cleaning under certain circumstances; I think this is also required by default) or -d
(removes director...
Rails: Disable options of a select field
Simply give the select
helper an option :disabled
, passing either a single value or an array. You need to specify the option's value
, not its text.
= form.select :country, Address.countries_for_select, :include_blank => true, :disabled => ['disabled-value1', 'disabled-value-2']
Also see Cucumber: Check if a select field contains a disabled option on how to test this.
Cucumber: Check if a select field contains a disabled option
For Capybara, use this step:
Then /^"([^"]*)" should be a disabled option for "([^"]*)"(?: within "([^\"]*)")?$/ do |value, field, selector|
with_scope(selector) do
field_labeled(field).find(:xpath, ".//option[text() = '#{value}'][@disabled]").should be_present
end
end
exception_notification 3.0.0+ lets you send errors as HTML e-mails
Exception notifications contain a lot of information: Backtraces, HTTP headers, etc. exception_notification tries its best to format this wall of information using ASCII art, but you can also make it send those notification as simple HTML e-mails that have some simple formatting for clarity, but no images etc. To do so, activate this option:
:email_format => :html
Those HTML notifications are still delivered with a text-only version, so if you are using a console cli...
exception_notification 4.0.0+ makes it easier to ignore errors, crawlers
The new exception_notification has awesome options like :ignore_crawlers => true
and :ignore_if => lambda { ... }
. These options should be helpful in ensuring every notifications means something actionable (instead of a long log of failures that just scrolls by).
Note that you should not ignore crawlers by default. Ideally, cool URLs never change and always respond with a helpful redirect or similar.
Ignore Errors like this:
# config/initializers/exception_notification.rb
Ex...
RubyMine detects syntax errors where there are none
To make this go away I had to wipe my RubyMine settings (~/.RubyMine
) and configure everything again. Fun.
Webservice to mock HTTP responses
Sometimes in the course of development you may need to mock HTTP responses.
This is a simple service to return various HTTP responses.
The Chokehold of Calendars
Most people don’t schedule their work. They schedule the interruptions that prevent their work from happening.
Consul 0.9 lets you optimize records checks
Consul 0.9 comes with many new features to optimize powers that only check access to a given record. e.g. Power.current.post?(Post.last)
. See below for details.
Powers that only check a given object
Sometimes it is not convenient to define powers as a collection. Sometimes you only want to store a method that
checks whether a given object is accessible.
To do so, simply define a power that ends in a question mark:
class Power
...
power :upd...
Maker's Schedule, Manager's Schedule
One reason programmers dislike meetings so much is that they're on a different type of schedule from other people. Meetings cost them more.
Cryptic Ruby Global Variables and Their Meanings
The linked page lists and explains global Ruby "dollar" variables, such as:
-
$:
(load path) -
$*
(ARGV
) -
$?
(Last exit status) -
$$
(PID) -
$~
(MatchData
from last successful match) - ...and many more you'll need when reading weird code.
Regex
-
$~
(lastMatchData
) -
$1 $2 $3 $4
(match groups from the last pattern match) -
$&
(last matched string) -
$+
(last match group) - `$`` (the string before the last match)
-
$'
(the string after the last match
See [this extensive list of variables](http://www.tu...
Short lambda syntax in Ruby 1.9
Ruby 1.9 brings a shorter way to define lambdas using the ->
operator:
twice = -> (x) { 2 * x }
twice.call(5) # => 10
This is equivalent to:
twice = lambda {|x| 2 * x }
twice.call(5) # => 10
Note that the syntax is subtly different from Coffeescript where you define function parameters before the arrow: (x) -> { 2 * x }
.
Do not try to "slice" on an ActionController::CookieJar
The cookies
object in your controllers and views is a ActionController::CookieJar
and even though that class inherits from Hash
and often behaves like one, you can not call slice
on it to select only a subset of cookies. Why? Because Hash#slice
calls self.class.new
-- which in case of a CookieJar
just won't work.
Unfortunately, you can't even say cookies.to_hash
and slice
on that, just because CookieJar#to_hash
is inherited from Hash
and will just return self
. Bummer.
You need to do it yourself, for example by usin...
Bash: How to generate a random number within given boundaries
$RANDOM
on bash returns a random integer between 0 and 32767.
echo $RANDOM
9816
echo $RANDOM
30922
If you want to limit that to a certain maximum, you can just compare against the modulus of that maximum + 1. \
For example, the following will yield results between 0 and 9:
echo $(($RANDOM % 10))
5
echo $(($RANDOM % 10))
9
Note that this skews random numbers to the lower regions of your boundaries in most cases.