Skip to content

Instantly share code, notes, and snippets.

Dan MacTough danmactough

Block or report user

Report or block danmactough

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View async_handle_request.js
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 {
@danmactough
danmactough / apple.sh
Last active Oct 20, 2018
Apple cli tweaks
View apple.sh
# Disable gesture navigation only in Chrome
# http://apple.stackexchange.com/a/80163/53921
defaults write com.google.Chrome.plist AppleEnableSwipeNavigateWithScrolls -bool FALSE
# Make Finder display "hidden" files and folders
# like ~/.ssh
defaults write com.apple.finder AppleShowAllFiles TRUE
# Apache in Mountain Lion
# http://reviews.cnet.com/8301-13727_7-57481978-263/how-to-enable-web-sharing-in-os-x-mountain-lion/
View movebrew
#!/bin/bash
# Get Homebrew in the new location
git clone git@github.com:Homebrew/homebrew.git ~/Homebrew
# Move all your installed packages to the new location
mv /usr/local/Cellar ~/Homebrew/Cellar
mv /usr/local/Library ~/Homebrew/Library
# Remove "root" directory files left behind
rm -rf /usr/local/.git /usr/local/{.gitignore,.yardopts,CODEOFCONDUCT.md,CONTRIBUTING.md,LICENSE.txt,README.md,SUPPORTERS.md}
@danmactough
danmactough / resolve.js
Created Apr 21, 2015
In any koa app, find the app root directory from any location.
View resolve.js
var path = require('path');
var appRoot = path.resolve(path.dirname(require.resolve('koa')), '..', '..', '..');
View cognito-notes.md

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 / add-collaborator.sh
Created Oct 12, 2015
I needed to add a read-only collaborator to many repositories, and doing it via the website was really tedious
View add-collaborator.sh
#!/bin/bash
GITHUB_TOKEN=$(git config --global github.token) # I've defined an API token in my git config -- ymmv
GITHUB_USER="" # the collaborator
REPO_OWNER="" # the owner of the repos
REPOS="" # space-delimited list of repositories
PERMISSION="pull" # may be one of "admin", "push" (i.e., read/write -- default), or "pull" (i.e., read-only)
for REPO in ${REPOS} ; do
curl -X PUT -i -d '{ "permission": "'${PERMISSION}'" }' \
-H 'Accept: application/vnd.github.ironman-preview+json' \
-H "Authorization: token ${GITHUB_TOKEN}" \
@danmactough
danmactough / do_boot2.sh
Created May 21, 2017 — 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)
View do_boot2.sh
#!/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.
@danmactough
danmactough / second-boot.sh
Created Jul 31, 2015
Setting up a gpu (nvidia) ec2 instance with ubuntu and electron for headless webgl rendering
View second-boot.sh
#!/bin/bash -xe
# Unload nouveau
sudo rmmod nouveau
# Load nvidia
sudo modprobe nvidia
# Configure X
sudo nvidia-xconfig --use-display-device=None --virtual=1280x1024 --output-xconfig=/etc/X11/xorg.conf --busid=PCI:0:3:0 --enable-all-gpus
View 20nginx-https-redirect.config
container_commands:
10redirect:
command: perl -0777 -pe 's#(listen 8080;\n)#$1\n if (\$request_uri = "/health") {\n set \$redirectFlag N;\n }\n\n if (\$http_x_forwarded_proto != "https") {\n set \$redirectFlag "\${redirectFlag}Y";\n }\n\n if (\$redirectFlag = "Y") {\n return 301 https://\$host\$request_uri;\n }#igms' -i /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
View write.js
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) {
You can’t perform that action at this time.