The Rails asset pipeline improves delivery of application assets (javascripts, stylesheets, images, fonts). Here are some basic facts about its inner workings.
Manifests are the handle on your assets:
app/assets/stylesheets/application.css # use via: stylesheet_link_tag 'application'
The asset pipeline only considers files you explicitly require within your manifest files. The most common directives used in manifests are require some/file
and require_tree some/directory
. Paths may be **relative to the current director...
When you run code inside a $watch
expression that forces a repaint (e.g. by computing an element's width, or running something like element.is(':visible')
) you may end up with "page flickering" or scroll offset changes.
You can hook to the end of a digest cycle to avoid that.
The following is basically straight from the docs, but pretty awkward to use. Do it...
To fix this:
chromedriver
binary from the ZIP file and put it e.g. into ~/bin
.Chromedriver must be available in your path. You can add ~/bin
to your path like this:
echo "export PATH=$PATH:$HOME/bin" >> $HOME/.bash_profile
If you're also using Geordi, disable automatic updating of chromedriver in ~/.config/geordi/global.yml
:
a...
Sidekiq::Client.push('class' => 'WorkerClass', 'args' => [11, 5, 1993])
is equivalent to
WorkerClass.perform_async(11, 5, 1993)
Clamps (ie. cuts off) an HTML element's content by adding ellipsis to it if the content inside is too long.
While you can only truncate single lines with CSS by using text-overflow
, this small JavaScript library also allows truncating text after multiple lines.
Please note:
line-height
set in pixels. A relative value will not work.-webkit-line-clamp
](http:...The Angular ngSrc
directive serves to properly set an image src
via Angular. As anything in Angular, it updates the image as soon as the contained Angular expression changes. However, when the ng-src
attribute is empty, Angular will not empty the src
attribute. To overcome this, use the trick below.
<img ng-src="{{ element.image || '//:0' }}" />
The ngSrc
directive explicitly returns when the attribute value is falsy. As a workaround, set a "blank" image src when the image is empty. As [somebody ...
If you get one of this errors:
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: (<unknown>): found character that cannot start any token while scanning for the next token at line 1297 column 3
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `empty?' for nil:NilClass at /etc/puppet/environments/production/manifests/nodes.pp:1 on node example.makandra.de
Warning: ...
When putting phone numbers into web pages, you should use tel:
links so smartphone users can click those numbers to call someone.
Here is a small helper method that you can use to simplify this:
def tel_to(text)
groups = text.to_s.scan(/(?:^\+)?\d+/)
link_to text, "tel:#{groups.join '-'}"
end
This will allow you to use human-readable numbers and get clean links:
>> tel_to '(01234) 555 6789'
=> <a href="tel:01234-555-6789">(01234) 555 6789</a>
^
>> tel_to '+1 555 123-456'
=> <a href="tel:+1-555-123-45...
Raphaël is a small JavaScript library that should simplify your work with vector graphics on the web. If you want to create your own specific chart or image crop and rotate widget, for example, you can achieve it simply and easily with this library.
An amped-up alternative to Turbolinks that differs in points like this:
A perfect implementation of the wrong specification is worthless. By the same principle a beautifully crafted library with no documentation is also damn near worthless. If your software solves the wrong problem or nobody can figure out how to use it, there's something very bad going on. Fine. So how do we solve this problem? It's easier than you think, and it's important enough to warrant its very own paragraph.
Write your Readme first.
Have you ever opened a file with vim, edited it and when you wanted to save your changes it told you "Can't open file for writing", because you opened it without sudo
? There's an easy hack to let you write it anyway:
:w !sudo tee %
The linked SO post explains in detail what will happen.
If you're already used to the "exit vim, run vim with sudo again (sudo !!
) and save" workflow but can't remember the above command, you may create an easy-to-remember shortcut. Add this snippet to your .vimrc
:
" Al...
Shortener is a Rails Engine Gem that makes it easy to create and interpret shortened URLs on your own domain from within your Rails application. Once installed Shortener will generate, store URLS and “unshorten” shortened URLs for your applications visitors, all whilst collecting basic usage metrics.
RubyMine 7.1:
Settings -> Editor -> General -> Smart Keys -> Unindent -> To nearest indent position
RubyMine 7.0:
Settings -> Editor -> General -> Smart Keys -> Backspace smart indent -> uncheck
If bower complains about a missing node
binary, do not install Ubuntu's node
package.
Instead, you need to create a symlink that points to the binary one of the nodejs
package:
sudo ln -s /usr/bin/nodejs /usr/bin/node
You probably already installed NodeJS. In case you did not:
sudo apt-get install nodejs
If you already installed the node
Ubuntu package, bower
will just do nothing (i.e. not show any input, or respond to any switches) and you need to uninstall that package first.
Upgrading from Ruby 1.8.7 to 2.1.2 took me an hour for a medium-sized application. It involved hardly any changes except
require
to require_relative
where I loaded RSpec factories in Cucumber's env.rb
(the Rails application root is no longer in the load path by default)byebug
sytem_timer
from Gemfile (see [this SO thread](http://stackoverflow.com/questions/7850216/how-to-inst...On your credit card summary, you will find order numbers of rides with Deutsche Bahn ("DB BAHN A-NR XYZ123")
If you need to find out details about the ride, have a look at that: https://fahrkarten.bahn.de/privatkunde/start/start.post?scope=bahnatsuche&lang=de
Google Calendar integration into Thunderbird suddenly did not work any more for me. Thunderbird kept asking me for my password to access calendars, but did not show them when given the correct credentials. Instead, calendars in the list got the famous "yellow triangle".
I got it working again doing the following.
Remove the Ubuntu packages the "Lightning" and "Google Calendar Provider" Thunderbird addons:
^
sudo apt-get remove xul-ext-gdata-provider xul-ext-lightning
Restart Thunderbird
Install the addons using Thu...
If you make a gem with Bundler, you will get a rake release
task that will instantly publish your gem to rubygems.org for all the world to admire. For private gems this is very bad.
To make sure this cannot happen, rubygems 2.2+ allows you to restrict eligible push hosts:
Gem::Specification.new 'my_gem', '1.0' do |s|
# ...
s.metadata['allowed_push_host'] = 'https://gems.my-company.example'
end
In case you already messed up, [follow these instructions to get your gem removed](http://help.rubygems.org/kb/rubygems/removing-an-a...
MetricsGraphics.js is a library built on top of D3 that is optimized for visualizing and laying out time-series data. It provides a simple way to produce common types of graphics in a principled, consistent and responsive way. The library currently supports line charts, scatterplots and histograms as well as features like rug plots and basic linear regression.
Using this gem I could get JSON generation from a large, nested Ruby hash down from 200ms
to 2ms
.
Its behavior differs from the default JSON.dump
or to_json
behavior in that it serializes Ruby symbols as ":symbol"
, and that it doesn't like an ActiveSupport::HasWithIndifferentAccess
.
There are also some issues if you are on Rails < 4.1 and want it to replace #to_json
(but you can always just call Oj.dump
explicitely).
Security warning: Oj does not escape HTML entities in JSON
---------...
Confusingly, RVM installs the bundler
gem into the @global
gemset, which is available to all gemsets and Rubies.
You can get around this and install a particular bundler version like this:
rvm @global do gem uninstall bundler
rvm @global do gem install bundler -v 1.6.5