Skip to content

Instantly share code, notes, and snippets.

@franzwong
franzwong / handler.js
Last active March 22, 2020 03:33
HowTo: Integrate Google reCAPTCHA with AWS Cognito
const axios = require('axios');
// Please replace the property values
const config = {
recaptcha: {
secretKey: '<Your reCAPTCHA secret key>',
},
};
exports.handler = async (event) => {
@franzwong
franzwong / index.js
Created March 22, 2020 03:28
HowTo: Integrate Google reCAPTCHA with AWS Cognito
const Auth = require('@aws-amplify/auth').default;
// Please replace the property values
const config = {
aws: {
region: '<Your aws region>',
cognito: {
userPoolId: '<Your Cognito user pool ID>',
userPoolWebClientId: '<Your Cognito user pool web client ID>',
},
@franzwong
franzwong / index.html
Last active March 22, 2020 03:08
HowTo: Integrate Google reCAPTCHA with AWS Cognito
<!DOCTYPE html>
<html>
<body>
<script src="https://www.google.com/recaptcha/api.js?render=Your_Recaptcha_Site_Key"></script>
<h2>Sign up</h2>
<form id="signup-form">
<div>
<input type="email" name="username" placeholder="Email">
</div>
@franzwong
franzwong / extract-json.js
Last active January 27, 2020 07:22
Extract json from plain text
/**
* Example
* Input: 'INFO Records: {"user": {"name": "luke", "type": "jedi"}}{"name": "leia"}, Record count: 2'
* Output: [
"INFO Records: ",
"{\n \"user\": {\n \"name\": \"luke\",\n \"type\": \"jedi\"\n }\n}",
"{\n \"name\": \"leia\"\n}",
", Record count: 2"
]
*/
@franzwong
franzwong / README.md
Last active August 19, 2019 02:02
YAML cheatsheet

Array of objects

Multiple properties

Yaml

- id: 123456
  name: Luke
 title: Jedi Knight
@franzwong
franzwong / gulpfile.js
Created July 27, 2019 05:43
Prepare lambda installation package with Gulp
const { src, dest, series, parallel } = require('gulp');
const install = require('gulp-install');
const del = require('del');
const zip = require('gulp-zip');
const BUILD_DIR = 'build';
const packageInfo = require('./package.json');
function clean() {
@franzwong
franzwong / index.js
Created July 20, 2019 07:48
Mac OS Keychain wrapper
const util = require('util');
const child_process = require('child_process');
const exec = util.promisify(child_process.exec);
function addPassword(serviceName, userName, password) {
return exec(`security add-generic-password -s ${serviceName} -a ${userName} -w ${password}`);
}
async function getPassword(serviceName, userName) {
@franzwong
franzwong / index.js
Last active November 10, 2022 08:28
Synology DownloadStation Task
const axios = require('axios');
const url = require('url');
if (process.argv && process.argv.length < 3) {
console.error('Invalid number of parameters');
process.exit(1);
}
const downloadLink = process.argv[2];
const domain = process.env.domain;
@franzwong
franzwong / index.ts
Created July 1, 2019 02:40
Screenshot capture script
import * as puppeteer from 'puppeteer';
interface PageInfoMap {
[key: string]: string;
}
const pageInfoMap: PageInfoMap = {
'はちま起稿': 'http://blog.esuteru.com/',
}
@franzwong
franzwong / tsconfig.json
Created July 1, 2019 01:51
Typescript config example
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "ES2018",
"moduleResolution": "node",
"module": "commonjs"
},
"include": [
"./src/**/*"