Skip to content

Instantly share code, notes, and snippets.

View adieuadieu's full-sized avatar
🤷‍♂️

Marco Lüthy adieuadieu

🤷‍♂️
View GitHub Profile
@adieuadieu
adieuadieu / handler.js
Last active May 27, 2024 19:07
AWS OpenSearch Cluster with Serverless Framework
const aws4 = require('aws4')
const host = process.env.OPENSEARCH_ENDPOINT
module.exports.default = async function handler(
event,
context,
) {
const fetch = (await import('node-fetch')).default
const indexName = 'example'
@adieuadieu
adieuadieu / build.js
Last active January 25, 2022 03:36
Using esbuild in your Serverless Framework Project
const fs = require('fs')
const cloudformationSchema = require('@serverless/utils/cloudformation-schema')
const esbuild = require('esbuild')
const yaml = require('js-yaml')
const rimraf = require('rimraf')
const SERVERLESS_YML_PATH = './serverless.yml'
const OUT_DIR = './dist'
// ref: https://esbuild.github.io/api/#simple-options
@adieuadieu
adieuadieu / create-tables-locally.js
Last active May 5, 2023 01:58
Using DynamoDB Locally in a Serverless Framework Project
const fs = require('fs')
const DynamoDB = require('aws-sdk/clients/dynamodb')
const yaml = require('js-yaml')
const cloudformationSchema = require('@serverless/utils/cloudformation-schema')
const SERVERLESS_CONFIG = __dirname + '/serverless.yml'
const ddb = new DynamoDB({
accessKeyId: 'fake-key',
endpoint: 'http://localhost:8001',
@adieuadieu
adieuadieu / handler.js
Last active September 6, 2023 21:57
AWS Elasticsearch Cluster with Serverless Framework
const aws4 = require('aws4')
const fetch = require('node-fetch')
const host = process.env.ELASTICSEARCH_ENDPOINT
module.exports.default = async function handler(event, context) {
const indexName = 'example'
const options = aws4.sign({
host,
@adieuadieu
adieuadieu / promise_monad.md
Created March 24, 2018 23:11 — forked from VictorTaelin/promise_monad.md
async/await is just the do-notation of the Promise monad

async/await is just the do-notation of the Promise monad

CertSimple just wrote a blog post arguing ES2017's async/await was the best thing to happen with JavaScript. I wholeheartedly agree.

In short, one of the (few?) good things about JavaScript used to be how well it handled asynchronous requests. This was mostly thanks to its Scheme-inherited implementation of functions and closures. That, though, was also one of its worst faults, because it led to the "callback hell", an seemingly unavoidable pattern that made highly asynchronous JS code almost unreadable. Many solutions attempted to solve that, but most failed. Promises almost did it, but failed too. Finally, async/await is here and, combined with Promises, it solves the problem for good. On this post, I'll explain why that is the case and trace a link between promises, async/await, the do-notation and monads.

First, let's illustrate the 3 styles by implementing

@adieuadieu
adieuadieu / webpage-save-svg-to-raster.js
Last active January 27, 2018 21:23
Grabs all SVGs matching a query selector from a webpage's DOM and converts them to a raster format (PNG), then downloads them
/*
Grabs all SVGs matching a query selector from a webpage's
DOM and converts them to a raster format (PNG), then downloads them.
I wanted to grab an <svg /> from a webpage.
Then, I realised I wanted it as a PNG.
So I wrote this script. Paste it into your browser's console.
*/
((svgQuerySelector = 'svg', saveType = 'image/png', saveQuality = 1) => {
const svgElements = document.querySelectorAll(svgQuerySelector)
@adieuadieu
adieuadieu / keybase.md
Created June 9, 2017 15:07
keybase.md

Keybase proof

I hereby claim:

  • I am adieuadieu on github.
  • I am adieuadieu (https://keybase.io/adieuadieu) on keybase.
  • I have a public key ASDyGEeNbQQjhYFD1N9_2CKP7uyRpsays3yRE7UeQfJ8VAo

To claim this, I am signing this object:

@adieuadieu
adieuadieu / handler.js
Last active December 6, 2018 08:43
Serverless-framework handler.js for headless Chrome (for this story: https://medium.com/@marco.luethy/running-headless-chrome-on-aws-lambda-fa82ad33a9eb )
'use strict'
require('./buffer-polyfill')
const childProcess = require('child_process')
const os = require('os')
const path = require('path')
const cdp = require('chrome-remote-interface')
const get = require('got')
@adieuadieu
adieuadieu / circle.yml
Last active February 10, 2017 10:48
Collecting test metadata in CircleCI with Ava
test:
override:
- mkdir -p $CIRCLE_TEST_REPORTS/reports
- eslint --format junit src/ > $CIRCLE_TEST_REPORTS/reports/eslint.xml
- ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/reports/ava.xml
@adieuadieu
adieuadieu / README.md
Last active February 28, 2019 22:53
A simple command line script to grab screenshots of a URL in multiple screen widths (desktop, tablet, mobile, or Twitter Bootstrap breakpoints) using PhantomJS.

Speelycaptor-lite

What is it

A simple command line script to grab screenshots of a URL in multiple screen widths (desktop, tablet, mobile, or Twitter Bootstrap breakpoints) using PhantomJS. Useful for quickly generating images of websites or in-the-browser design processes to share with team members of a client.

Prerequisites

  • OS with bash
  • You'll need to install PhantomJS. On OS X, the easiest way to do this is with Brew. $ brew install phantomjs should do it.

Try it