3540 cards
View
Auto-destruct in 23 days

Updated: Minor caveat for minified Font Awesome fonts with webpack

I noticed that changing the subset of used icons does not change the file name of the generate font, and will cause issues with browser caching.

I've added a workaround.

AngularJS 1 Performance: One-time bindings in expressions

In addition to the {{ myValue }} two-way binding syntax, since Angular 1.3 there's a one-time binding syntax, prefixing the value or expression with ::, e.g. {{ ::myValue }}, {{ ::myValue >= 42 }} and {{ ::myExpression(value) | someFilter }}.

One-time bound expressions get dropped from the list of watchers as soon as they can be resolved. Performance-wise the impact for this small change is huge, since Angular apparently slowes down with too many watchers registered [(Source)](http://www.binpress.com/tutorial/speeding-up-angular-js-wi…

Unpoly 0.57.0 released: New params API, compiler improvements and scrolling fixes

This is a major rewrite with many bugfixes, performance improvements and some minor breaking API changes.

Request parameters

To prevent confusion with [up-data], Unpoly now uses the word "params" when talking about form values or request parameters:

  • up.request() option { data } has been renamed to { params }.
  • up.replace() option { data } has been renamed to { params }.

Parameters may be passed in one of the following type…

all_blank_except for accepts_nested_attributes_for

Put the attached file to config/initalizers to ignore some fields for rejecting nested records (e.g. hidden input fields).

class Post < ActiveRecord::Base
  
  has_many :comments
  accepts_nested_attributes_for :comments, :reject_if => all_blank_except(:position, :other_nested_attrs)

end

Minify Font Awesome fonts with webpack

Font Awesome 5 is a comprehensive solution for vector icons on your website.

Originally, Font Awesome came as an icon font (plus stylesheets), but recently it can also be used as a pure JavaScript solution (which will render icons as inline <svg> tags), or even as SVG sprites.

All solutions have their pros and cons:

Icon font:

  • little CPU load (no JavaScript)
  • fonts are relatively large
  • 1 extra HTTP request

Javascript + inline SVG:

  • higher CPU load (needs to watch the DOM via mutation observers to ad…
Repeats

Javascript: Comparing two arrays for equality

Don't Google this, you will lose all will to live. Instead use Object#isEqual from Lodash or Underscore.js:

_.isEqual([1, 2], [2, 3]) // => false

To compare two arrays for equality in a Jasmine spec assertion, see Jasmine: Testing complex types for equality.

Accessing Rails config in webpack(er)

It is possible to access Rails config (for example secrets) from within your webpack bundles, thanks to rails-erb-loader. When using webpacker, the setup is like this:

  1. Install rails-erb-loader:

    yarn add rails-erb-loader
    
  2. Add this to your config/webpacker/environment.js:

    environment.loaders.prepend('erb', {
      test: /\.erb$/,
      enforce: 'pre',
      use: [{
        loader: 'rails-erb-loader',
      }]
    })
    
  3. Start using erb. For examp…

Repeats

How to create memory leaks in jQuery

jQuery doesn't store information about event listeners and data values with the element itself. This information is instead stored in the global $.cache object. Every time you add an event listener or data value to a jQuery object, $.cache gains another entry.

The only way that a $.cache entry gets deleted is when you call remove() on the element that put it there!

Since cache entries also have a pointer back to the element that spawned them, it is easy to create DOM elements that can never be garbage-collected.

Below are …

Repeats

How to examine an unknown Ruby object

When debugging your application, you will come across objects created by some gem or framework. You don't have the source code at hand, still need to inspect this object. Here are some tools to do so:

Relevant methods

@object.methods - Object.instance_methods returns a list of methods excluding methods inherited from Object. This makes the methods list drastically more relevant. You can also try subtracting other base classes like ActiveRecord::Base.methods etc.

Filtering method list

@object.methods.grep /keyword/ comes…

Repeats

Ruby tempfiles

Tempfiles get deleted automatically

With the the ruby Tempfile class you can create temporary files. Those files only stick around as long as you have a reference to those. If no more variable points to them, the GC may finalize the object at some point and the file will be removed from the filesystem. If you would try to access your tempfile then using its path (which you stored previously), you would get an error because the file no longer exists.

Unlink your tempfiles when you're done with them
-…

Auto-destruct in 0 days

Updated: Sun Java JVM/JRE on Ubuntu Linux

  • Added Java 10 installation guide
  • Added an instruction how to change the default java version

How to: Use different configurations for S3cmd

S3cmd is a free command line tool and client for uploading, retrieving and managing data in Amazon S3. S3cmd reads its configuration by default from ~/.s3cfg, which is created once you run s3cmd --configure.

If you have many configurations, we recommend to always specify the configuration you want to use. This prevents applying actions to the wrong bucket.

Examples:

```
s3cmd -c ~/.s3cfg-github-staging ls
s3cmd -c ~/.s3cfg-github-development …

Repeats

Do not pass an empty array to ActiveRecord.where when using NOT IN

Be careful with the Active Record where method. When you accidentally pass an empty array to the where method using NOT IN, you probably will not get what you expected:

User.where("id NOT IN (?)", [])
=>  SELECT `users`.* FROM `users` WHERE (id NOT IN (NULL))

Even though you might expect this to return all records, this actually results none.

Never use the expression id NOT IN (?) in any scope! See below some workarounds.

Rails < 4

Rails < 4 does not provide a pretty workaround.

```
ids = []

if ids.present?
Us…

Repeats

Ruby: required keyword arguments in the pre-2.1 era

Starting with Ruby 2.0 you can define methods with keyword arguments.

In 2.1+ required keyword arguments can be defined by using a colon without default value:

def match(value, ignore:)
  ...
end

To accomplish something similar in ruby 1.8, use:

def match(value, options = {})
  ignore = options.fetch(:ignore)
  ...
end

Git: Ignore whitespace when merging or cherry-picking

You can tell git to ignore different kinds and amounts of whitespace when merging or cherry-picking. This often occurs when you changed indentation, or converted tabs to spaces.

Simply use

git merge <REV> -Xignore-space-change

or

git cherry-pick <REV> -Xignore-space-change
Auto-destruct in 12 days

Updated: How Rails chooses error pages (404, 500, ...) for exceptions

Emphasized that changing the error mapping has nothing to do with "rescueing", and that error notification has to be muted on its own.

Repeats

Defining class methods with Modularity traits

There are two ways to define a class method from a Modularity trait. Note that the usual caveats regarding class method visibility apply.

Using define_method

The recommended way is to define a method on your module's singleton class:

# ruby 1.9+
module SomeTrait
  as_trait do
    define_singleton_method :foo do
      # ...
    end
 ...

Rbenv: How to remove a gem installed from a Github source

Normally you can list all gems of the current ruby version with gem list, which also includes the gems of you Gemfile. These can be uninstalled with gem uninstall gemname.

List and uninstall a gem installed via Bundler from Github

This does not work for gems installed directly from Github. They do not appear in gem list.

Show all gems installed via Github by bundler:

ls ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/bundler/

Remove a gem installed via Github by Bundler:

```
rm -rf ~/.rbenv/versions/2.4.1/lib/ruby/gems/2….

This website uses cookies to improve usability and analyze traffic.
Accept or learn more