Bower complains about missing NodeJS on Ubuntu
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 a Rails 3.2 application to Ruby 2.1 is really easy
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
- removing the occasional monkey patch where I had backported functionality from modern Rubies
- Migrating from
require
torequire_relative
where I loaded RSpec factories in Cucumber'senv.rb
(the Rails application root is no longer in the load path by default) - replacing the old debugger with
byebug
- removing
sytem_timer
from Gemfile (see [this SO thread](http://stackoverflow.com/questions/7850216/how-to-inst...
Deutsche Bahn: Show details of past rides
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
How to (possibly) fix Google Calendar in Thunderbird (Lightning) on Ubuntu
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...
PSA: Dont allow private gems to be pushed to rubygems.org
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
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.
Speed up JSON generation with oj
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
---------...
Downgrade Bundler in RVM
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
Bootstrap: How to avoid printing link URLs
By default, Twitter Bootstrap's print styles include printing links.
/* Bootstrap's way of printing URLs */
@media print {
a[href]:after {
content: " (" attr(href) ")";
}
}
If you want to turn that off, you can do
/* Don't print link hrefs */
@media print {
a[href]:after {
content: none
}
}
Angular: Caching API responses in Restangular
Restangular can make use of $http
's built-in response cache.
# Cache response for single request
Restangular.one('accounts', 123).withHttpConfig({ cache: true }).get();
# Cache responses for all requests (be careful with that, you might work with stale data)
RestangularProvider.setDefaultHttpFields({ cache: true });
To invalidate cached responses e.g. on a state change in UI Router, you can do
@app.run ['$rootScope', '$cacheFactory', ($rootScope, $cacheFactory) ->
$rootScope.$on '$stateChangeSuccess', ->
$cacheF...
Draggabilly
Javascript library for drag'n'drop that seems to have more options than native HTML5 drag'n'drop.
They also claim to support "multi-touch", which would be awesome if it means that you can drag on touch devices.
Another library with similar aims is interact.js (Github).
They're pitching JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE8+).
Angular: Binding an HTML value
To bind an HTML value to ng-bind-html
, you need to mark it as "trusted" first. Among other ways, you can do so with a custom filter.
# Filter in Coffeescript...:
@app.filter 'htmlSafe', ['$sce', ($sce) -> $sce.trustAsHtml ]
# ...or JS:
app.filter('htmlSafe', [
'$sce', function($sce) {
return $sce.trustAsHtml;
}
]);
# Usage:
<div ng-bind-html="item.value | htmlSafe"></div>
This is a replacement for the ng-bind-html-unsafe
directive which has been removed in Angular 1.2.
:party:
How to install fonts in Ubuntu
- Put the font files (e.g.
ttf
) into ~/.fonts - Run
fc-cache -v
Or, if you prefer to use the GUI, open each font file and click the "Install" button in the top right of the preview window.
New Firefox and gem versions for our Selenium testing environment (Ubuntu 14.04+)
Firefox 5.0.1, which we were using for most Rails 2.3 projects, does not run on Ubuntu 14.04 any more. Here is how to update affected projects.
-
Update (or create)
.firefox-version
with the content:24.0
If you haven't installed Firefox 24 yet, the next time you run tests with Geordi, it will tell you how to install it. -
On a Rails 2 project:
-
Update your Cucumber-related gems as described in Upgrading Cucumber and Capybara, including
cucumber_spinner
andlaunchy
. -
If you...
-
Fixing tlmgr cannot setup TLPDB
tlmgr
is the TeX Live Manager and responsible for the TeX installation on your (Linux) machine.
If you're getting the message:
(running on Debian, switching to user mode!)
cannot setup TLPDB in /home/dominik/texmf at /usr/bin/tlmgr line 5336.
... tlmgr
has not been initialized. Run this to initialize it:
tlmgr init-usertree
Then, you may set e.g. a global paper size standard: tlmgr paper a4
.
Pitfall: ResourceController overwrites where ActiveRecord enqueues
Defining one callback several times in the same class behaves different in ActiveRecord and ResourceController.
While in ActiveRecord the callbacks are enqueued, they overwrite each other in ResourceController.
ActiveRecord - a common practice
class Post < ActiveRecord::Base
does 'post/behavior'
before_validation :do_something
end
module Post::BehaviorTrait
as_trait do
before_validation :do_something_else
end
end
do_something_else
and do_something
are executed before validation in exactly this order
ResourceC...
Accept nested attributes for a record that is not an association
Note: Instead of using the method in this card, you probably want to use ActiveType's nested attributes which is a much more refined way of doing this.
The attached Modularity trait allows you to accept nested attributes for a record that is not an association, e.g.:
class Site < ActiveRecord::Base
def home_page
@home_page ||= Page.find_by_name('home')
end
does 'a...
How to install the `xelatex` binary on Ubuntu 14.04
Just install the texlive-xetex
package:
sudo apt-get install texlive-xetex
Running integration tests without texlive-xetex
will produce an error during xelatex
execution:
RTeX::Document::ExecutableNotFoundError
Prevent LibreOffice from changing standard styles when you format individual characters
You select some characters, make them bold and suddenly your entire document is bold?
Here's how to fix that:
- Right-click the style in the "Styles and Formatting" window
- Select "Modify"
- Go to the "Organizer" tab
- Unselect "AutoUpdate"
You're welcome.
Scroll a textarea to a given position with jQuery
Browsers make this very hard. Even when you explicitely set the selection inside the textarea (e. g. using jquery-fieldselection) the browser will not scroll the textarea to this selection.
What you can do instead is abuse browsers' behavior that they scroll to the end of a textarea when it gets focus. So we set the textarea's value to the text before the position, then focus it, then reset it to its original value:
function scrollTextareaToPosition($textarea, position) {
var text...
/usr/ports/converters/ruby-iconv This port is marked IGNORE
If you have this problem when you update your FreeBSD Ports:
===>>> Launching child to update ruby19-iconv-1.9.3.547,1 to ruby20-iconv-2.0.0.576,1
===>>> All >> ruby19-iconv-1.9.3.547,1 (17/17)
===>>> Currently installed version: ruby19-iconv-1.9.3.547,1
===>>> Port directory: /usr/ports/converters/ruby-iconv
===>>> This port is marked IGNORE
===>>> Not needed with Ruby 2.0 or newer
===>>> If you are sure you can build it, remove the
IGNORE line in the Makefile and try again.
===>>> Update for ruby19-iconv-1.9.3.547,1 f...
bower-rails can rewrite your relative asset paths
The asset pipeline changes the paths of CSS files during precompilation. This opens a world of pain when CSS files reference images (like jQuery UI) or fonts (like webfont kits from Font Squirrel), since all those url(images/icon.png)
will now point to a broken path.
In the past we have been using the vendor/asset-libs
folder ...
JavaScript: How to check if an object is NaN
JavaScript's NaN
("Not a Number") is hard to compare against. It never equals anything, not even itself:
NaN === NaN; // false
Number.NaN === NaN; // false
There is the isNaN
method, but it is not really what you are looking for:
isNaN(NaN) // true
isNaN('hello') // true
Option 1: ES6
The Object.is()
method determines whether two values are the same value. It even works for NaN
:
Object.is(NaN, NaN) // true
Option 2: ES5
The example above shows that simply using isNaN
would match other ...