Skip to content

Instantly share code, notes, and snippets.

@jchip
jchip / nginx-upload-setup-mac.md
Last active February 22, 2022 23:40
nginx upload file setup on mac using homebrew
"use strict";
const Http = require("http");
class SimpleServer {
constructor({ port, name }) {
this._config = { port, name };
this._routes = {};
}
<html>
<head>
<script>
var baseUrl = "http://localhost:3000";
var launchedWindow;
function load() {
// window.location = "${baseUrl}";
console.log("launching")
@jchip
jchip / package.json
Created October 19, 2018 16:31
package.json fails with cb() never called
{
"name": "x2",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
@jchip
jchip / pos-to-line.js
Created June 17, 2018 08:16
position to line/column
function posToLine(template, pos) {
const lines = template.split("\n");
let run = 0;
let x;
for (x = 0; x < lines.length; x++) {
const line = lines[x];
if (run + line.length < pos) {
run += line.length + 1;
} else {
// Place your settings in this file to overwrite default and user settings.
{
"editor.tabSize": 2,
"editor.wordWrapColumn": 200,
"editor.wordWrap": "wordWrapColumn",
"editor.detectIndentation": false,
"editor.formatOnSave": false,
"typescript.format.enable": false,
"javascript.format.enable": true,
"json.format.enable": false,
"use strict";
const Tar = require("tar");
const Path = require("path");
const Fs = require("fs");
const Promise = require("bluebird");
const logger = require("./logger");
const defer = require("./util/defer");
const { fork } = require("child_process");
@jchip
jchip / dirmap.js
Created December 7, 2017 00:56
dirmap
class DirMap {
constructor() {
this._map = { _: {} };
}
set(dir, data) {
const splits = dir.split(path.sep);
let map = this._map;
let i;
for (i = 0; i < splits.length; i++) {

TL;DR Promise tutorial:

  1. Know how to create promise.
  • new Promise( (resolve, reject ) => { })
  • Promise.resolve(<resolved_value>) Where <resolved_value> can be any value, even another promise.
  • Promise.reject(<error_value>)
  1. promise.then( resolved_value => return <x> ) Where <x> either becomes the new resolved_value for next .then or if it's a promise, it becomes the new promise in the chain. Remember to return your promise!

Corollary:

FILES=".babelrc .eslintignore .eslintrc .gitignore .npmignore .travis.yml LICENSE README.md gulpfile.js lib package.json test"
TARGET=packages/electrode-react-webapp
git filter-branch --tree-filter "for f in $FILES; do if [ -e \$f ]; then mkdir -p $TARGET; mv \$f $TARGET; fi; done"