Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / get_session_token.sh
Created December 1, 2020 04:31
AWS get session token with OTP
#!/bin/bash
SERIAL_NUMBER=$1
OTP=$2
PROFILE=$3
CREDENTIALS=$(aws sts get-session-token \
--serial-number ${SERIAL_NUMBER} \
--token-code ${OTP} \
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \
--output text)
@franzwong
franzwong / MyTest.java
Created January 8, 2021 11:35
Bloomberg event creation for unit test (BLPAPI)
public class MyTest {
// Only work for Blpapi Java 3.16.1 and above
@Test
public void myTest() {
Service service;
try (InputStream is = getClass().getResourceAsStream("/marketDataSchema.xml")) {
service = TestUtil.deserializeService(is);
}
SchemaElementDefinition elementDef = service.getEventDefinition(new Name("MarketDataEvents"));
@franzwong
franzwong / synology_cloud_sync_s3.tf
Last active July 3, 2022 01:34
Terraform configuration for Synology Cloud Sync with AWS S3
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.0"
}
}
required_version = "~> 1.0.0"
}
@franzwong
franzwong / add_generic_password.c
Last active November 12, 2022 05:24
Add generic password to MacOS Keychain with C
// Build: gcc -framework Security -framework Foundation -o add_generic_password add_generic_password.c
// Usage: ./add_generic_password <service name> <username> <password>
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
int main(int argc, const char* argv[]) {
if (argc < 4) {
fprintf(stderr, "Usage: ./add_generic_pasword <service name> <username> <password>");
return 1;
@franzwong
franzwong / get_generic_password.c
Last active November 12, 2022 08:31
Get generic password from MacOS Keychain with C
// Build: gcc -framework Security -framework Foundation -o get_generic_password get_generic_password.c
// Usage: ./get_generic_password <service name>
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
OSStatus getCredentialByServiceName(const char *serviceName, CFTypeRef *credential) {
CFStringRef cfServiceName = CFStringCreateWithCString(kCFAllocatorDefault, serviceName, kCFStringEncodingUTF8);
const void* keys[] = { kSecClass, kSecAttrService, kSecReturnAttributes, kSecReturnData, kSecMatchLimit };
@franzwong
franzwong / README.md
Last active November 19, 2022 16:13
Run SonarQube on local machine

Run SonarQube on local machine

Build docker image for Mac M1

There is only amd64 docker image for SonarQube. We need to build by ourselves if we want to run it on Mac M1.

mkdir sonarqube_local
cd sonarqube_local
PROJECT_DIR=$(PWD)