This lets you set the preload headers for your assets, so that the browser can start fetching them before it begins parsing HTML.
| # Add below into config/application.rb: | |
| # | |
| # config.middleware.use 'RequestLogger' | |
| # | |
| class RequestLogger | |
| def initialize app | |
| @app = app | |
| end | |
| def call(env) |
It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
| <?php | |
| $number = "\d*(?:\.\d+)?"; // It's a reference to use in other cases that matches any kind of number/float | |
| $width = "(?<w>(?:$number)?%?)?"; // This is the first part, the width | |
| $height = "(?:x(?<h>(?:$number)?%?))?"; // Here is the height, the same as "width" but starting with an "x" | |
| $aspect = "[!><@^]"; // These are the different filters one can use to stretch, shrink, etc. | |
| $size = "$width$height"; // To match any size we need width and height at least (aspect comes later) |
Table of Contents generated with DocToc
This pagination liquid code is an extract of the public repository from http://nicolas-hoizey.com/, where you can see it in action.
| {% if paginator.total_pages > 1 %} | |
| <p> | |
| {% if paginator.previous_page == 1 %} | |
| <a href="{{ '/blog/' | prepend: site.baseurl }}">previous</a> | |
| {% elsif paginator.previous_page %} | |
| <a href="{{ paginator.previous_page_path | prepend: site.baseurl }}">previous</a> | |
| {% else %} | |
| previous | |
| {% endif %} |
Douglas Crockford, author of JavaScript: The Good parts, recently gave a talk called The Better Parts, where he demonstrates how he creates objects in JavaScript nowadays. He doesn't call his approach anything, but I will refer to it as Crockford Classless.
Crockford Classless is completely free of class, new, this, prototype and even Crockfords own invention Object.create.
I think it's really, really sleek, and this is what it looks like:
function dog(spec) {| CREATE OR REPLACE FUNCTION public.json_append(data json, insert_data json) | |
| RETURNS json | |
| IMMUTABLE | |
| LANGUAGE sql | |
| AS $$ | |
| SELECT ('{'||string_agg(to_json(key)||':'||value, ',')||'}')::json | |
| FROM ( | |
| SELECT * FROM json_each(data) | |
| UNION ALL | |
| SELECT * FROM json_each(insert_data) |