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
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
}
}
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...
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+).
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:
ttf
) into ~/.fontsfc-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.
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
and launchy
.
If you...
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
.
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.
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...
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...
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
You select some characters, make them bold and suddenly your entire document is bold?
Here's how to fix that:
You're welcome.
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...
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...
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'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
The Object.is()
method determines whether two values are the same value. It even works for NaN
:
Object.is(NaN, NaN) // true
The example above shows that simply using isNaN
would match other ...
Angular-xeditable is a bundle of AngularJS directives that allows you to create editable elements.
Such technique is also known as click-to-edit or edit-in-place.
It is based on ideas of x-editable but was written from scratch to use power of angular and support complex forms / editable grids.
Simply use one(...)
instead of on(...)
. It takes the same arguments.
bower-rails
is a great solution for managing vendored assets in your Rails app. It feels especially much more convenient and easier to update assets when going this way.
bower-rails generates a Bowerfile
that works much like the Gemfile
you're used to. Just specify your dependencies and run rake bower:install
. You can find available packages here.
An example Bowerfile
:
# ./Bowerfile
asset 'angular'
asset 'angular-i18n'
asset 'angular-ui-router'
asset 'angu...
JavaScript structures that include circular references can't be serialized with a"plain" JSON.stringify
. Example:
a = { name: 'Groucho' };
b = { name: 'Harpo', sibling: a };
a.sibling = b;
Doing a JSON.stringify(a)
will throw an error:
TypeError: Converting circular structure to JSON
There is not much you can do about that except specifying a custom serializer function that detects and cleans up circular references. There are existing solutions so you do not need to think of one yourself, like <https://githu...
Returning an empty scope can come in handy, e.g. as a default object. In Rails 4 you can achieve this by calling none
on your ActiveRecord model.
MyModel.none # returns an empty ActiveRecord::Relation object
For older Rails versions you can use the attached initializer to get a none
scope.