Search_spinner Cross_grey Magnifier
help

Search syntax

  • Search for repeating cards with repeats:yes
  • Search for unfinished cards with unfinished:yes
  • Search for cards in a certain topic with topic:"name"
  • Search for phrases with "a phrase"
  • Exclude a word from search: -word
  • Exclude a phrase from search: -"a phrase"
  • Exclude a topic from search: -topic:"name"
Repeats

How to create giant memory leaks in AngularJS

This guide shows how to create an AngularJS application that consumes more and more memory until, eventually, the browser process crashes on your users.

How to observe memory consumption

To inspect the amount of memory consumed by your Javascripts in Chrome:

  • Open an incognito window
  • Open the page you want to inspect
  • Press Shift + ESC to see a list of Chrome processes
  • Find the process for the incognito window
  • Right-click on the list and check Javascript memory
  • Observe the *Javascript memor…

twitter responds with HTTP 401 for missing profiles

When your application crawls twitter profiles for tweets, it might throw HTTP 401 (Unauthorized) errors.

Those can happen for a number of reasons, one of them obviously being incorrect credentials.
However, 401 is also returned when crawling profiles that no longer exist.

True story.

Install MySQL 5.6 in Ubuntu 16.04

Ubuntu 16.04 only provides packages for MySQL 5.7 which has a range of backwards compatibility issues with code written against older MySQL versions.

Oracle maintains a list of official APT repositories for MySQL 5.6, but those repositories do not yet support Ubuntu 16.04. However, the 15.10 repos will work for 16.04.

I would not recommend to do this in production environment, but on a development machine, follow these steps:

  • Dump your databases, if you want to keep them. Keeping the data directory itself did not work for me.
  • Uni…

VCR: An OAuth-compatible request matcher

OAuth requires a set of params to be carried along requests, among which a nonce. Some libraries pass these along as headers, some as query parameters. All fine.

When you're using VCR, the latter case is an issue. By default, requests are matched on method and URI. However, no request URI will equal another when they include a nonce. You won't be able to match these requests with VCR.

Solution

Obviously you need to…

Running the Awesome window manager within MATE

Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi-display support with per display workspaces and more. Since it is only a window manager, you will probably miss some of MATE's conveniences like the network manager, application menus, automatic updates etc.

Fortunately, you can run Awesome within MATE, by following these steps (tested on Ubuntu MATE 16.04):

Awesome + MATE

  • Create the following file at `/usr/share/xsessions/Xses…
Repeats

Heads up! Years are always floats in Rails

Watch out when saying something like 1.year in Rails. The result is not a Fixnum and can cause unexpected errors when the receiving end expects a Fixnum.

While anything from seconds to months are Fixnums, a year is a Float in Rails – when called on a Fixnum itself:

>> 10.seconds.class
=> Fixnum
>> 2.minutes.class
=> Fixnum
>> 24.hours.class
=> Fixnum
>> 28.days
=> 28 days
>> 9.months.class
=> Fixnum
>> 1.year.class
=> Float # Boom.

While they are [technically correct](http://en….

How to use triple quotes inside a Cucumber docstring

Cucumber's docstrings let you add long strings to a step like this:

# foo.feature
Given this text:
"""
First line
Second line

Second Paragraph
"""

# foo_steps.rb
Given /^this text:$/ |docstring|
  puts docstring.split
end

You see these neat triple double quotes ("""). Now what to do [when you need your docstring to contain triple double quotes], too?

# Does not work:
Given this text:
"""
Docstrings work like this:
  """
  Docstring example
  """
You see?
"""

Solution

Cucumber Transforms to the rescue! Transforms a…

External content

Using Bumbler to Reduce Runtime Dependencies - The Lean Software Boutique

Tool to show you which gems are slow to load:

➜  git:(master) ✗ bundle exec bumbler
[#################################################                             ]
(49/65) travis-lint...
Slow requires:
    110.21  render_anywhere
    147.33  nokogiri
    173.83  haml
    179.62  sass-rails
    205.04  delayed_job_active_record
    286.76  rails
    289.36  mail
    291.98  capistrano
    326.05  delayed_job
    414.27  pry
    852.13  salesforce_bulk_api
Repeats

Getter and setter functions for Javascript properties

Javascript objects can have getter and setter functions that are called when a property is read from or written to.

For example, if you'd like an object that has a virtual person.fullName attribute that dynamically composes person.firstName and person.lastName:

```
var person = {

firstName: 'Guybrush',

lastName: 'Threepwood',

get fullName() {
return this.firstName + " " + this.lastName;
},

set fullName(name) {
var parts = name.split(" ");
this.firstName = parts[0];
this.lastName = parts[1];
}

};
```…

Top-level constants in BasicObject

If you want to access top-level constants inside a BasicObject class, you need to prefix them with ::.

This will not work

class Foo < BasicObject
  def bar
    Hash.new
  end
end

Foo.new.bar # => NameError: uninitialized constant Foo::Hash

You need to explicitly write ::Hash.

The reason is that top-level constants are internally attached to Object, so Hash is not in the lookup chain inside a BasicObject.

Repeats

Fix PNG colors in IE, old Safaris and new Firefoxes

Some browsers render PNG images with color profiles and other shenanigans, some don't. Remove some PNG chunks to render colors uniformly.

Geordi brings a command png-optimize which conveniently optimizes your PNGs for the web. See Github for a description

  • Single file and batch optimization is supported
  • optimize-png will overwrite the original files

Without Geordi

Linux:
sudo apt-get install pngcrush
  • Single file:

    pngcrush -rem...
    
Auto-destruct in 58 days

Updated: Getter and setter functions for Javascript properties

Added explanation for defining getters/setters with CoffeeScript.

External content

Caching best practices & max-age gotchas - JakeArchibald.com

Showing various caching patterns. Includes WhatsApp screenshots.

Repeats

MySQL: Do not use "WHERE id IN (SELECT ....)"

Note: This applies specifically to MySQL. In PostgreSQL for example, this is not an issue.

If you care about performance, never use a query like

UPDATE users SET has_message = 1 WHERE users.id IN (SELECT user_id FROM messages)

MySQL does not optimize this and seems to scan the temporary table, which isn't indexed, for every row in the update statement. This applies to other statements than UPDATE as well.

Instead, either use a JOIN like

UPDATE users INNER JOIN messages ON messages.user_id = users.id SET has_message =...
External content

Postgres Index Types

When creating an index using CREATE INDEX, Postgres will create a B-Tree type index by default. The B-Tree type is great for general purpose indexes but there are special cases when other types provide better results.

Repeats

How to create memory leaks in jQuery

Note that the information in this card pertains to jQuery 1 and jQuery 2.0 and 2.1. Future versions of jQuery will probably attach information directly to DOM nodes.


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 elem…

3069 cards