Skip to content

Instantly share code, notes, and snippets.

@nepsilon
nepsilon / how-to-append-line-numbers-in-front-of-each-line-in-a-file.md
Last active February 8, 2017 09:10
How to append line numbers in front of each line in a file? — First published in fullweb.io issue #86

How to append line numbers in front of each line in a file?

Just use cat. No kidding, cat has the -n option to number the output lines, starting at 1:

cat -n file.txt

This works well both on Linux and Mac. Use the shell redirection to keep the output in a new file (don’t override the original file with the redirection though).

@nepsilon
nepsilon / email-address-syntax-validation-let-the-browser-do-it.md
Last active August 14, 2022 18:34
Email address syntax validation? Let the browser do it (without regexp) — First published in fullweb.io issue #77

Email address syntax validation? Let the browser do it (without regexp)

Here is a simple and robust way to check for the validity of an email address syntax directly in the browser. No need for crazy regular expressions.

e = document.createElement('input')
e.type = 'email'
// check some email addresses
e.value = 'hi@'
@nepsilon
nepsilon / dom-how-to-select-range-of-children.md
Last active August 16, 2016 02:58
DOM: How to select a range of children? — First published in fullweb.io issue #58

DOM: How to select a range of children?

Given the following HTML code:

<ol>
  <li>1</li>
  <li>2</li>
  <li>3</li>
 4
@Rich-Harris
Rich-Harris / service-workers.md
Last active November 5, 2024 06:39
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@sorenlouv
sorenlouv / facebook-cookie.MD
Last active December 21, 2023 03:48
Get "xs" value from Facebook cookie
@staltz
staltz / introrx.md
Last active November 19, 2024 18:00
The introduction to Reactive Programming you've been missing
@dherman
dherman / realms-api.md
Last active September 7, 2024 17:42
ES6 Realms API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.

Realms

@PaulKinlan
PaulKinlan / criticalcss-bookmarklet-devtool-snippet.js
Last active October 12, 2024 16:34
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active November 29, 2023 15:35
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>