Skip to content

Instantly share code, notes, and snippets.


Sators sators

View GitHub Profile
sators / json.php
Created Apr 24, 2015
Output JSON from PHP with proper Content -ype Header
View json.php
$data = /** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);
sators /
Last active Oct 13, 2018
Bash script to join a rabbitmq cluster of the same AWS autoscaling group
wget --quiet
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 / 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) =>
View npm-install-rescursive.js
const path = require('path')
const fs = require('fs')
const child_process = require('child_process')
const root = process.cwd()
// 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.
sators / connect.php
Last active May 17, 2021
PHP MySQLi Amazon Aurora RDS EC2 IAM Role Based Authentication
View connect.php
/********* CONFIG ********/
$clusterEndpoint = "";
$clusterPort = 3306;
$clusterRegion = "us-east-1";
$dbUsername = "";
$dbDatabase = "";
sators / arrayToCsv.js
Last active May 25, 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
* @modifiedBy sators
* @param {Array} 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"}) => {