Security

How to capture all HTTP(S) traffic from an app on a smartphone

Use the excellent mitmproxy. For macOS and iOS:

  1. Install using brew install mitmproxy
  2. Start the interactive web tooling using mitmweb
  3. Make a note of your current IP address: Option-click the WiFi-symbol to find it
  4. Configure the proxy on iOS: Settings ➡ Wifi, hit the ‘I’ icon on your current network, scroll down and ‘Configure Proxy’. Select ‘Manual’, enter your IP address in ‘Server’ and ‘8080’ in port
  5. Go to mitm.it to see if everything works. If it does, follow the steps there to install the certificate.

Internet Explorer 11 bugs

Add a class if the browser is Internet Explorer 11 or lower

if ('ActiveXObject' in window) {
    document.documentElement.className = 'is-ie';
}

Fixing childen of a flexbox container exceeding their parent width

Just add width: 100% to the elements, or if you’re really lazy:

.container > * {
    width: 100%;
}

SASS

Getting both value and index from a SASS list

$colors: red, blue, yellow, green;
@for $index from 1 through length($colors) {
    li:nth-child(#{length($colors)}n + #{$index}):before {
        background-image: url('../img/bullet-#{nth($colors, $index)}.svg');
    }
}

Javascript

Is there a quicker way to assign a default value if the result is undefined?

Instead of this:

const bar = foo.bar ? foo.bar : 'bar';

Or this:

let bar;

if (foo.bar) {
  bar = foo.bar;
} else {
  bar = 'bar';
}

Try this:

const bar = foo.bar || 'bar';

Promises

// Transforming jQuery's $.get to a Promise
function get(url) {
    return new Promise(function(resolve, reject) {
        $.ajax({
            method : "GET",
            url : url,
            success : function(data) {
                resolve(data);
            },
            error : function() {
                reject('Something went wrong');
            }
        }
    });
}

get('http://example.com').then(function(data) {
    console.log(data);
});

async/await

const URL = 'https://api.github.com/gists/a09e180c6064906b5271';

async function getGist() {
    try {
        const res = await fetch(URL);
        const data = await res.json();
        return data;
    } catch (err) {
        console.log(err);
    }
}

getGist().then(gist => console.log(gist.description));

Lodash: Transform an array with objects to an object with keys and values

_.mapValues(_.keyBy(data, 'key'), 'value');

Transform this:

[
    { key : 'foo', value : 'bar'},
    { key : 'baz', value : 'qux'}
]

Into this:

{
    'foo' : 'bar',
    'baz' : 'qux'
}

Chrome

Remove URLS from autocomplete

Highlight the item using keyboard arrows and press Shift and Delete keys.