Skip to content

Instantly share code, notes, and snippets.

@danmactough
danmactough / bashisms.md
Last active July 31, 2023 18:24
Bash Basics

Manipulating Strings

# safety
set -euo pipefail

# root directory
ROOT_DIR="$(cd $(dirname $0)/.. ; pwd)"

# directory of this script
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
"module": "none" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"allowJs": true /* Allow javascript files to be compiled. */,
"checkJs": true /* Report errors in .js files. */,
"noEmit": true /* Do not emit outputs. */,
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"skipLibCheck": true /* Skip type checking of declaration files. */,
const fetch = require('node-fetch');
function request (options, cb) {
fetch(options)
.catch(cb)
.then(res => {
return res.body()
.then(body => {
cb(null, res, body);
}, cb);
@danmactough
danmactough / move-music.sh
Last active April 14, 2020 22:16
Move your entire music library from one directory to another
#!/bin/bash
set -euo pipefail
set -x
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
# set OLD_DIRECTORY and NEW_DIRECTORY
# OLD_DIRECTORY=/Users/your_username/Music
# NEW_DIRECTORY=/Volumes/your_external_drive/Music
OLD_DIRECTORY=
@danmactough
danmactough / GIF-Screencast-OSX.md
Created February 2, 2020 16:03 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

const Layer = require('express/lib/router/layer');
Layer.prototype.handle_request = async function handle(req, res, next) {
var fn = this.handle;
if (fn.length > 3) {
// not a standard request handler
return next();
}
try {

Notes on using Cognito with Serverless

  • event.requestContext.identity.cognitoIdentityId should be the user id
  • Cognito User Pools are for handling user registration, authentication, and account recovery
  • Cognito Identity Pools (or Cognito Federated Identities) are a way to authorize users to directly use the various AWS services in your account, such as S3, DynamoDB, and, most relevant for APIs, API Gateway

CloudFormation in serverless.yml

resources:
@danmactough
danmactough / do_boot2.sh
Created May 21, 2017 22:50 — forked from leucos/do_boot2.sh
Bootstrap your DO infrastructure unsing Ansible without dynamic inventory (version for Ansible v2.0+ and DO API v2.0)
#!/bin/bash
#
# What is that
# ============
#
# This script will help you setting up your digital ocean
# infrastructure with Ansible v2.0+ and DO API v2
#
# Usually, when working with DO, one is supposed to use digital_ocean.py
# inventory file, and spin up instances in a playbook.
var fs = require("fs");
var path = require("path");
var outfile = path.resolve(__dirname, "appPrefs.json");
var lockfile = outfile + ".lock";
var data = "some data or other";
// obtain an exclusive read/write file handle on the semaphore file
fs.open(lockfile, "wx+", function (err, fd) {
if (err) {

Tweet help

  • Great @NodeDC meetup @socialtables ty @NodeSource @Hired_HQ for sponsoring
  • ty @socialtables @NodeSource @Hired_HQ for sponsoring @NodeDC

Links

Use these links! Sign up for Hired if you haven't already!