Skip to content

Instantly share code, notes, and snippets.

View mhart's full-sized avatar

Michael Hart mhart

View GitHub Profile
@mhart
mhart / index.js
Created July 24, 2019 21:04
Log errors to Sentry from a Cloudflare Worker
// Get the key from the "DSN" at: https://sentry.io/settings/<org>/projects/<project>/keys/
// The "DSN" will be in the form: https://<SENTRY_KEY>@sentry.io/<SENTRY_PROJECT_ID>
// eg, https://[email protected]/123456
const SENTRY_PROJECT_ID = '123456'
const SENTRY_KEY = '0000aaaa1111bbbb2222cccc3333dddd'
// Useful if you have multiple apps within a project – not necessary, only used in TAGS and SERVER_NAME below
const APP = 'my-app'
// https://docs.sentry.io/error-reporting/configuration/?platform=javascript#environment
@mhart
mhart / removed.bin.txt
Last active March 6, 2020 09:49
Binaries and libraries removed from the Lambda 2019-05-14 update (refers to all runtimes except nodejs10.x which is opt-in to a completely new OS)
/bin/dash
/bin/dnsdomainname
/bin/domainname
/bin/dumpkeys
/bin/hostname
/bin/ipcalc
/bin/iptables-xml
/bin/kbd_mode
/bin/loadkeys
/bin/mountpoint
@mhart
mhart / bootstrap
Created December 4, 2018 02:15
Out-of-the-box AWS Lambda custom runtime (implemented in bash!)
#!/bin/sh
set -euo pipefail
# Handler format: <script_name>.<function_name>
# The script file <script_name>.sh must be located in
# the same directory as the bootstrap executable.
source $(dirname "$0")/"$(echo $_HANDLER | cut -d. -f1).sh"
while true
@mhart
mhart / steps.sh
Last active September 11, 2023 11:01
Get SCL (and GCC 7) working on Amazon Linux 2017.03
yum install -y iso-codes # Needed for scl-utils-build
curl -O http://vault.centos.org/6.5/SCL/x86_64/scl-utils/scl-utils-20120927-11.el6.centos.alt.x86_64.rpm
curl -O http://vault.centos.org/6.5/SCL/x86_64/scl-utils/scl-utils-build-20120927-11.el6.centos.alt.x86_64.rpm
curl -O http://mirror.centos.org/centos/6/extras/x86_64/Packages/centos-release-scl-rh-2-3.el6.centos.noarch.rpm
curl -O http://mirror.centos.org/centos/6/extras/x86_64/Packages/centos-release-scl-7-3.el6.centos.noarch.rpm
rpm -Uvh *.rpm # Had to run this twice? Get an error first time, maybe Docker related
rm *.rpm
var api = foo
api.foo = 1
api.bar = 2
export default api
Object.assign(foo, someThings)
export default foo
array.forEach(item => {
bar[item.key] = item.value
@mhart
mhart / activityStore.js
Created April 7, 2017 16:05
One way to manage React global state with EventEmitters
const EventEmitter = require('events')
class ActivityStore extends EventEmitter {
constructor() {
this.state = 'stopped' // Whether you need this or not...?
}
start() {
this.state = 'started'
this.emit('started', this.state)
}
<!doctype html>
<html lang="en">
<!-- Example HTML file for AWS Proxy Resource tutorial at: https://aws.amazon.com/blogs/compute/authorizing-access-through-a-proxy-resource-to-amazon-api-gateway-and-aws-lambda-using-amazon-cognito-user-pools/ -->
<!-- Fill out your UserPoolId, ClientId and apiGatewayEndpoint in JS further below -->
<!-- Then serve locally with a static file server, such as `python -m SimpleHTTPServer` and open http://localhost:8000 -->
<head>
<meta charset="utf-8">
@mhart
mhart / .block
Last active September 30, 2016 00:33 — forked from mbostock/.block
Blocks
license: gpl-3.0
@mhart
mhart / splitStream.js
Last active September 12, 2016 00:29
Split stream for Node.js >= 4.x
var stream = require('stream')
module.exports = split
function split(delim, emitTrailingIfEmpty) {
delim = delim || new Buffer('\n')
var trailing, delimLen = delim.length
return new stream.Transform({
readableObjectMode: true,
transform: function(chunk, enc, cb) {
var AWS = require('aws-sdk')
var dynamo = new AWS.DynamoDB({endpoint: 'http://localhost:4567'})
var params = {
AttributeDefinitions: [ // required
{
AttributeName: 'test_id', // required
AttributeType: 'N' // required
}, {