Skip to content

Instantly share code, notes, and snippets.

View demikhovr's full-sized avatar
🎯
Focusing

Rodion Demikhov demikhovr

🎯
Focusing
  • Emerging Travel Group
View GitHub Profile
@sungwoncho
sungwoncho / cleanup_example.sh
Last active November 11, 2022 21:50
Clean up previous build after a webpack build. Used in production at https://remotebase.io
# Store the filenames of previous build
PREVIOUS_BUILD=(./static/dist/*)
# ...
# build using webpack
# ...
# after the build
regex="([a-zA-Z_0-9]+)-([0-9a-z]+)\.(.*)"
@odewahn
odewahn / error-handling-with-fetch.md
Last active February 27, 2024 09:56
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@paulirish
paulirish / what-forces-layout.md
Last active May 19, 2024 03:45
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@orbitbot
orbitbot / index.html
Created October 23, 2014 21:43
Ace editor with http-link highlighting and click action, from http://jsbin.com/jehopaja/30/edit?html,output
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="http://ajaxorg.github.io/ace-builds/src/ace.js"></script>
<style>
#editor { position: absolute; top: 0; left: 0; right: 0; bottom: 0;}
.ace_link_marker {
position: absolute;
@miohtama
miohtama / parse-hash-bang-arguments-in-javascript.js
Created January 6, 2012 12:08
Parse hash bang HTTP GET query style arguments from an URL using Javascript
/**
* Parse hash bang parameters from a URL as key value object.
*
* For repeated parameters the last parameter is effective.
*
* If = syntax is not used the value is set to null.
*
* #x&y=3 -> { x:null, y:3 }
*
* @param aURL URL to parse or null if window.location is used
@briancavalier
briancavalier / simple-promise-retry.js
Created February 24, 2011 18:35
A few general patterns for retries using promises
function keepTrying(otherArgs, promise) {
promise = promise||new Promise();
// try doing the important thing
if(success) {
promise.resolve(result);
} else {
setTimeout(function() {
keepTrying(otherArgs, promise);