Skip to content

Instantly share code, notes, and snippets.

import io from 'socket.io-client';
import getBaseUrl from '../../../utils/get-base-url';
let mSocket: null | SocketIOClient.Socket = null;
let mIsConnecting = false;
/**
* Create io.socket if it doesn't exist. If it does, and it's disconnected
* then reconnect it. If io.socket is in process of connecting, this will
in package.json scripts:
scripts: {
...
"preinstall": "node -e \"if (process.env.npm_execpath.indexOf('yarn') === -1) { console.error('\\u001b[31mPlease use yarn for installing\\u001b[0m'); process.exit(1); }\""
...
}
yarn jest CurrentSchedulesScreen --watch
@Noitidart
Noitidart / e.js
Last active June 16, 2019 01:48 — forked from 1yzo/e.js
if (typeof unreg !== 'undefined') unreg();
function logOnline() {
console.log('ONLINE', new Date().toLocaleTimeString())
}
function logOffline() {
console.log('offline', new Date().toLocaleTimeString())
}
function reg() {
window.addEventListener('online', logOnline);
pre(3); // log "hit" 3 times
post(3); // log "hit" 4 times
function pre(depth) {
let i=0;
while (true) {
console.log('hit');
if (++i === depth) return;
}
}

with string of "file:///var/mobile/Containers/Data/Application/4CA477FA-1C4C-41C0-AF8D-094F364DE3BA/Documents/com.zillow.zo.rpm.dev/7C3DBCAA-0DC9-4224-A4D2-26803F032644.jpg"

doing:

  let urlString = path as String
  let url = NSURL(string: urlString)! as URL

url.path gives "/var/mobile/Containers/Data/Application/50235058-BF69-4311-A668-67D13F1566CA/Documents/com.zillow.zo.rpm.dev/7C3DBCAA-0DC9-4224-A4D2-26803F032644.jpg"

// server down
{ Error: connect ECONNREFUSED 127.0.0.1:1337
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1061:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 1337 }
STATUS_CODES:
{ '100': 'Continue',
'101': 'Switching Protocols',
'102': 'Processing',
'103': 'Early Hints',
'200': 'OK',
'201': 'Created',
'202': 'Accepted',
'203': 'Non-Authoritative Information',
'204': 'No Content',
/**
* A caveat is that an observer, referentially, can ONLY subscribe to one type.
* I can fix this in the future, but for now, I don't have a need.
*
* @param {"connect" | "reconnect" | "disconnect"} type
* @param {Function} observer
* @param {Object<string, any>} options
* @param {boolean} [options.shouldMulti] - Set to true if you want the observer to stay subscribed after first trigger. By default, it will be removed after first trigger.
*
/**
* Convert a file size given in bytes to human readable sizes.
* Source: https://stackoverflow.com/a/18650828/1828637
*
* @param {number} bytes
* @param {number} decimals - Should be >= 0, if less than 0 it is adjusted to 0.
*/
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';