Skip to content

Instantly share code, notes, and snippets.

@trung85
trung85 / curlpool.sh
Created December 26, 2022 08:08 — forked from g105b/curlpool.sh
Pool 100 parallel curl requests at a time
#!/bin/bash
target=${1:-http://example.com}
while true # loop forever, until ctrl+c pressed.
do
for i in $(seq 100) # perfrom the inner command 100 times.
do
curl $target > /dev/null & # send out a curl request, the & indicates not to wait for the response.
done
wait # after 100 requests are sent out, wait for their processes to finish before the next iteration.
@trung85
trung85 / splitByMonths.php
Created July 15, 2022 08:58 — forked from andejoni89/splitByMonths.php
split date range into months ranges
<?php
function getMonthRanges($start, $end)
{
$timeStart = strtotime($start);
$timeEnd = strtotime($end);
$out = [];
$milestones[] = $timeStart;
$timeEndMonth = strtotime('first day of next month midnight', $timeStart);
while ($timeEndMonth < $timeEnd) {
@trung85
trung85 / .env
Created July 4, 2022 06:59 — forked from mtilson/.env
how to rebuild your web app container on every commit with local 'docker-compose' and 'post-commit' git hook [docker] [docker-compose] [git]
APPNAME=myapp
APPVERSION=latest
@trung85
trung85 / heroku_env_copy.sh
Created January 11, 2022 02:34 — forked from nabucosound/heroku_env_copy.sh
Script to copy environment variables from an existing heroku app to another one
#!/bin/bash
# Source: http://blog.nonuby.com/blog/2012/07/05/copying-env-vars-from-one-heroku-app-to-another/
set -e
sourceApp="$1"
targetApp="$2"
while read key value; do
@trung85
trung85 / ukcloudpro-lambda-sns-slack.js
Last active January 11, 2022 02:15 — forked from ukcloudpro/ukcloudpro-lambda-sns-slack.js
AWS Lambda node.js code to pass SNS messages to Slack Webhook
var https = require('https');
var util = require('util');
var SLACK_CHANNEL = process.env.SLACK_CHANNEL;
var SLACK_PATH = process.env.SLACK_PATH;
exports.handler = function(event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
@trung85
trung85 / 1) build_and_push.sh
Last active September 20, 2021 06:55 — forked from TylerBrock/build_and_push.sh
Amazon ECS Deploy Script -- for public use
#!/usr/bin/env bash
set -e
status() {
echo -e "[DEPLOY]: ${1}"
}
# Set the version to the branch name by default
ver_tag=${CIRCLE_BRANCH}
@trung85
trung85 / nginxproxy.md
Created September 11, 2021 08:01 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@trung85
trung85 / index.js
Created August 19, 2021 07:21 — forked from jeroenvollenbrock/aws-cloudfront-basic-auth.js
AWS-CloudFront-basic-auth
var USERS = {
protecteddir: [{
username: 'user',
password: 'pass',
}],
};
//Response when auth is not valid.
var response401 = {
statusCode: 401,
@trung85
trung85 / lambda-basic-auth.js
Created August 19, 2021 07:06 — forked from lmakarov/lambda-basic-auth.js
Basic HTTP Authentication for CloudFront with Lambda@Edge
'use strict';
exports.handler = (event, context, callback) => {
// Get request and request headers
const request = event.Records[0].cf.request;
const headers = request.headers;
// Configure authentication
const authUser = 'user';
const authPass = 'pass';
@trung85
trung85 / self-signed-ssl-mongo.sh
Created May 21, 2021 10:54 — forked from exAspArk/self-signed-ssl-mongo.sh
Self-signed SSL Certificate with OpenSSL on MacOS | MongoDB
openssl genrsa -out CAroot.key 2048
openssl req -new -key CAroot.key -out CAroot.csr # CN should be different from the certificates below
openssl req -x509 -days 1825 -key CAroot.key -in CAroot.csr -out CAroot.crt
cat CAroot.crt CAroot.key > CAroot.pem
openssl genrsa -out mongod.key 2048
openssl req -new -key mongod.key -out mongod.csr
openssl x509 -req -days 1825 -in mongod.csr -CA CAroot.pem -CAkey CAroot.key -CAcreateserial -out mongod.crt
cat mongod.crt mongod.key > mongod.pem