Skip to content

Instantly share code, notes, and snippets.

@dtelaroli
dtelaroli / script.sh
Last active Nov 12, 2020
mac osx enable and disable aac aptx codecs
View script.sh
#read
sudo defaults read bluetoothaudiod
# disable
sudo defaults write bluetoothaudiod "Enable AAC codec" -bool false
sudo defaults write bluetoothaudiod "Enable AptX code" -bool false
# restart
# enable
sudo defaults write bluetoothaudiod "Enable AAC codec" -bool true
@dtelaroli
dtelaroli / elastisearch.json
Created Sep 4, 2020
ElasticSearch error Fielddata is disabled on text fields by default. Set fielddata=true on [field] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
View elastisearch.json
PUT <index>/_mapping/doc
{
"properties": {
"field": {
"type": "text",
"fielddata": true
}
}
}
@dtelaroli
dtelaroli / policy.json
Created Aug 23, 2020
AWS ElasticSearch Service policy
View policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<accountId>:role/<authRoleArn>"
},
"Action": "es:*",
"Resource": "<ESDomainArn>/*"
@dtelaroli
dtelaroli / lambda-get-identity-id.js
Created Aug 4, 2020
How to get identity id from cognito with jwt token
View lambda-get-identity-id.js
// npm install await-to-js
const { to } = require("await-to-js");
const { CognitoIdentity } = require("aws-sdk");
const identity = new CognitoIdentity();
const IDENTITY_POOL_ID = "<your identity pool id>";
exports.handler = async (event) => {
const { issuer } = event.identity;
@dtelaroli
dtelaroli / amplify-create-subdomain.js
Created Jul 14, 2020
Creates an amplify subdomain with aws javascript sdk
View amplify-create-subdomain.js
const { to } = require("await-to-js");
const { Amplify } = require("aws-sdk");
const amplify = new Amplify();
const config = {
AMPLIFY_FRONTEND_APP_ID: "your_app_id",
AMPLIFY_FRONTEND_DOMAIN: "your_domain.com",
AMPLIFY_FRONTEND_BRANCH: "your_branch_env"
};
@dtelaroli
dtelaroli / joi-cpf-cnpj.js
Created Jul 13, 2020
Joi Validator validate cpf-cnpj field
View joi-cpf-cnpj.js
const { cpf, cnpj } = require('cpf-cnpj-validator');
const Joi = require("@hapi/joi");
const JoiDoc = Joi.extend((joi) => ({
base: joi.string(),
type: "string",
messages: {
'document.invalid': '"{{#label}}" is invalid'
},
rules: {
@dtelaroli
dtelaroli / update.js
Last active Apr 9, 2020
Lambda to update all DynamoDB data to force reindex ElasticSearch AppSync Amplify
View update.js
const { DynamoDB } = require("aws-sdk");
const ddb = new DynamoDB.DocumentClient();
/**
* @param event.TableName required - DynamoDB table name
* @param event.ExclusiveStartKey optional - Last Id if you want continue previeus execution
* Permissions to lambda:
* - dynamodb:Scan
* - dynamodb:BatchWriteItem
**/
@dtelaroli
dtelaroli / README.md
Last active Feb 3, 2020
AWS CodePipeline SAM Project CD with Bitbucket
View README.md

Cloudformation Sam Pipeline Example

Template Parameters

env: environment name
region: aws region
codestarConnection: codestar connection arn https://docs.aws.amazon.com/cli/latest/reference/codestar-connections/create-connection.html
branch: bitbucket branch to continuous deployment
repo: bitbucket repo with pattern username/repository_name
@dtelaroli
dtelaroli / CustomResources.json
Created Oct 23, 2019
Amplify Cloudformation Example - AppSync HTTP Datasource
View CustomResources.json
{
...
"Resources": {
"EmptyResource": {
"Type": "Custom::EmptyResource",
"Condition": "AlwaysFalse"
},
"MyDataSource": {
"Type": "AWS::AppSync::DataSource",
"Properties": {
@dtelaroli
dtelaroli / README.md
Last active Jun 19, 2019
How to activate Macbook TouchID in the Terminal
View README.md
  1. Open the sudo file:
sudo vim /etc/pam.d/sudo
  1. Add the line above in the first line of the sudo file
auth sufficient pam_tid.so
You can’t perform that action at this time.