Skip to content

Instantly share code, notes, and snippets.

View markwylde's full-sized avatar

Mark Wylde markwylde

View GitHub Profile
@markwylde
markwylde / index.js
Created September 19, 2019 10:05
Bigger stack traces on promises
/*
Magic to get bigger stack traces
*/
const asyncHooks = require('async_hooks')
const stackTraces = new Map()
function init (asyncId) {
let capturedStackTrace = {}
Error.captureStackTrace(capturedStackTrace)
stackTraces.set(asyncId, capturedStackTrace.stack)
@markwylde
markwylde / README.md
Last active October 25, 2019 23:34
Create a container deployment service

Deploy King

Create an new SSH key

We need to create a new SSH key that we will give GitHub for the CI jobs.

user@computer.local api % ssh-keygen       
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/user/.ssh/id_rsa): /Users/user/.ssh/github-do-marriage_rsa
Enter passphrase (empty for no passphrase): 
@markwylde
markwylde / httpRequest.js
Created November 11, 2019 05:26
Make an http request natively in nodejs
const http = require('http')
const https = require('https')
function httpRequest (options, callback) {
const uri = new URL(options.url)
const httpOrHttps = uri.protocol === 'https:' ? https : http
const opts = {
headers: options.headers || {},
method: 'GET',
@markwylde
markwylde / index.js
Created November 12, 2019 11:09
Promise replacement with Righto
async function syncCollectionOnServer (collectionName, server) {
const schema = await fetch({
url: 'http://manager.example.test/products'
})
const collection = await fetch({
method: 'post',
data: schema,
url: `${server}/${collectionName}`
})
@markwylde
markwylde / index.js
Created November 19, 2019 03:54
Create a simple https server with letsencrypt
const https = require('https');
const http = require('http');
const fs = require('fs');
const options = {
key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
cert: fs.readFileSync('/etc/letsencrypt/live/example.com/cert.pem'),
ca: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};
@markwylde
markwylde / README.md
Created November 21, 2019 05:51
Create a Weave Docker

DOCKER

sudo apt-get update
sudo apt-get -y install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common
buildInsertStatement = require('./common/buildInsertStatement')
await db.run(`DELETE FROM "settings" WHERE "key" = 'acmeDirectoryUrl'`)
statement = buildInsertStatement('settings', {
key: 'acmeDirectoryUrl',
value: JSON.stringify('https://acme-v02.api.letsencrypt.org/directory')
})
await db.run(statement.sql, statement.parameters)
@markwylde
markwylde / npm-ls-output.txt
Last active December 27, 2020 07:12
List of dependencies node-sass brings
tmp@1.0.0 /tmp
└─┬ node-sass@5.0.0
├── async-foreach@0.1.3
├─┬ chalk@1.1.3
│ ├── ansi-styles@2.2.1
│ ├── escape-string-regexp@1.0.5
│ ├─┬ has-ansi@2.0.0
│ │ └── ansi-regex@2.1.1
│ ├─┬ strip-ansi@3.0.1
│ │ └── ansi-regex@2.1.1 deduped
@markwylde
markwylde / index.js
Created December 30, 2020 01:17
server rendered mithril
const fs = require('fs');
const http = require('http');
const handler = require('serve-handler');
const render = require('mithril-node-render');
const htmlTemplate = fs.readFileSync('./index.html', 'utf8');
const ui = require('./js/ui');
const server = http.createServer(async function (request, response) {
@markwylde
markwylde / setupNotifications.js
Created March 29, 2021 05:12
Cordova notifications
function checkNotificationPermission (requested) {
FirebasePlugin.hasPermission(function (hasPermission) {
if (hasPermission) {
console.log('Remote notifications permission granted')
// Granted
getToken()
} else if (!requested) {
// Request permission
console.log('Requesting remote notifications permission')
FirebasePlugin.grantPermission(checkNotificationPermission.bind(this, true))