Skip to content

Instantly share code, notes, and snippets.

View brianleroux's full-sized avatar
💚
You are now aware that you are breathing

Brian LeRoux brianleroux

💚
You are now aware that you are breathing
View GitHub Profile
@brianleroux
brianleroux / BeforeExitListener.js
Created September 12, 2019 22:04
Lambda NodeJS 10.x Default Runtime JavaScript
/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
"use strict";
/**
* The runtime has a single beforeExit function which is stored in the global
* object with a symbol key.
* The symbol is not exported.
* The process.beforeExit listener is setup in index.js along with all other
* top-level process event listeners.
*/
/**
* fixes begin/data for architect 6.x apps
*/
module.exports = function beginDataMacro(arc, cfn) {
if (!cfn.Resources.DataTable) {
// adds a dynamodb table for begin/data if @tables is missing 'data'
// adds a CRUD policy to Role for data table
}
let lambdas = Object.keys(cfn.Resources).filter(function isLambda(Name) {
let resource = cfn.Resources[Name]
@brianleroux
brianleroux / main.sh
Created August 11, 2019 20:33
arc6 quickstart
# setup a workspace
mkdir testarc6
cd testarc6
npm init -f
npm i @architect/architect@6.0.0-RC.1
# generate a hello world function
npx arc init
# modify .arc file @aws with a bucket property for deploying
@brianleroux
brianleroux / upgrade-vim.sh
Created April 18, 2019 23:17
upgrade vim on os x from scratch
git clone https://github.com/vim/vim.git
cd vim/src
./configure --enable-multibyte --enable-terminal --enable-gui=no --without-x
make
sudo make install
export PATH=~/.npm-global/bin:$PATH
export AWS_REGION=us-east-1
export AWS_PROFILE=smallwins
DGREY="\[\e[0;32m\]"
ENDCOLOR="\[\e[0m\]"
PS1="$DGREY#! $ENDCOLOR"
# allow vi nav on esc
set -o vi
@brianleroux
brianleroux / slack.js
Created February 22, 2019 15:12
how to sign in with slack
let tiny = require('tiny-json-http')
module.exports = async function slack(code) {
// trade the code for an access token
let result = await tiny.get({
url: `https://slack.com/api/oauth.access`,
data: {
client_id: process.env.SLACK_CLIENT_ID,
client_secret: process.env.SLACK_CLIENT_SECRET,
@brianleroux
brianleroux / index.js
Created February 1, 2019 00:44
maaaaabye this?
let next = require('../../front/.next/serverless/pages/index.js')
exports.handler = async function http(req) {
req.url = req.path
let res = {end(){},setHeader(){}}
return {type:'text/html; charset=utf8', body: next.render(req,res).html}
}
@brianleroux
brianleroux / arc.vim
Created October 19, 2018 18:41
put this in ~/.vim/syntax
syntax region arcAppSection start=/\v\@app/ skip=/\v\\./ end="\v\@="
syntax region arcHtmlSection start=/\v\@http/ skip=/\v\\./ end="\v\@="
syntax region arcJsonSection start=/\v\@queues/ skip=/\v\\./ end="\v\@="
syntax region arcJsonSection start=/\v\@static/ skip=/\v\\./ end="\v\@="
syntax region arcJsonSection start=/\v\@domain/ skip=/\v\\./ end="\v\@="
syntax region arcJsonSection start=/\v\@aws/ skip=/\v\\./ end="\v\@="
syntax region arcEventsSection start=/\v\@events/ skip=/\v\\./ end="\v\@="
syntax region arcTablesSection start=/\v\@tables/ skip=/\v\\./ end="\v\@="
syntax region arcIndexesSection start=/\v\@indexes/ skip=/\v\\./ end="\v\@="
syntax region arcScheduledSection start=/\v\@scheduled/ skip=/\v\\./ end="\v\@="
@brianleroux
brianleroux / watif.js
Last active September 18, 2018 22:29
what if I told u
import data from '@architect/data'
import App from '@architect/shared/app'
import render from 'preact-to-string'
import {h} from 'preact'
/**
* ssr preact from a lambda
* if, instead of index.js, you have index.jsx OR index.tsx arc will automatically transpile the code
*/
export async function handler(req) {
@brianleroux
brianleroux / src-html-get-index-index.js
Last active August 24, 2018 21:50
a function that returns text/javascript esmodules; a function that renders an html page..
let begin = require('@architect/functions')
function index(req, res) {
let html = `<script type=module src=/js/entry.mjs></script>`
res({html})
}
exports.handler = begin.html.get(route)