Skip to content

Instantly share code, notes, and snippets.

Avatar

Sators sators

View GitHub Profile
View npm-install-rescursive.js
const path = require('path')
const fs = require('fs')
const child_process = require('child_process')
const root = process.cwd()
npm_install_recursive(root)
// Since this script is intended to be run as a "preinstall" command,
// it will do `npm install` automatically inside the root folder in the end.
console.log('===================================================================')
@sators
sators / Extend AppSync API Key Expiration Date.js
Last active Sep 17, 2020
Set all App Sync API Key Expiration Dates to 365 Days from <Today> to support Public / Guest APIs
View Extend AppSync API Key Expiration Date.js
var AWS = require('aws-sdk');
async function asyncForEach(array, callback)
{
for (let index = 0; index < array.length; index++) {
await callback(array[index], index, array);
}
}
exports.handler = async (event) =>
@sators
sators / join_rabbitmq_cluster.sh
Last active Oct 13, 2018
Bash script to join a rabbitmq cluster of the same AWS autoscaling group
View join_rabbitmq_cluster.sh
#!/bin/bash
wget --quiet http://s3.amazonaws.com/ec2metadata/ec2-metadata
sudo chmod u+x ec2-metadata
INSTANCE_ID=$(./ec2-metadata | grep instance-id | awk 'NR==1{print $2}')
AG_NAME=$(aws autoscaling describe-auto-scaling-instances --instance-ids ${INSTANCE_ID} --query AutoScalingInstances[].AutoScalingGroupName --output text)
echo ===================================
echo Searching for cluster in ${AG_NAME}
echo ===================================
echo Local Instance ID: ${INSTANCE_ID}
for ID in $(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names ${AG_NAME} --query AutoScalingGroups[].Instances[].InstanceId --output text);
@sators
sators / arrayToCsv.js
Last active Mar 10, 2021
Convert Array of Objects to CSV with Javascript
View arrayToCsv.js
/**
* Take an array of objects of similar structure and convert it to a CSV.
* @source https://halistechnology.com/2015/05/28/use-javascript-to-export-your-data-as-csv/
* @modifiedBy sators
* @param {Array} options.data Array of data
* @param {String} options.columnDelimiter Column separator, defaults to ","
* @param {String} options.lineDelimiter Line break, defaults to "\n"
* @return {String} CSV
*/
export default ({data = null, columnDelimiter = ",", lineDelimiter = "\n"}) => {
@sators
sators / connect.php
Last active Apr 8, 2021
PHP MySQLi Amazon Aurora RDS EC2 IAM Role Based Authentication
View connect.php
<?php
/********* CONFIG ********/
$clusterEndpoint = "";
$clusterPort = 3306;
$clusterRegion = "us-east-1";
$dbUsername = "";
$dbDatabase = "";
/*************************/
@sators
sators / json.php
Created Apr 24, 2015
Output JSON from PHP with proper Content -ype Header
View json.php
<?PHP
$data = /** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);