Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View tsertkov's full-sized avatar
🖐️
Say Hello

Aleks Tsertkov tsertkov

🖐️
Say Hello
View GitHub Profile
@tsertkov
tsertkov / nodejs-get-url-concurrency-control.js
Created May 2, 2018 09:47
NodeJs http get downloader with concurrency control
// example
const fetchUrl = fetchUrlFactory(2)
const { content, headers } = await fetchUrl('https://example.com')
// lib
const https = require('https')
function fetcUrlFactory ({ concurrency }) {
let running = 0
let queue = []
@tsertkov
tsertkov / s3-buckets-mass-remove.sh
Last active January 27, 2018 11:21
Mass remove s3 buckets based on name pattern
aws s3 ls \
| grep -e 'pr.*\.example\.com' \
| cut -d ' ' -f 3 \
| xargs -I {} -L 1 aws s3 rb s3://{} --force
@tsertkov
tsertkov / copy_dbschema_smart.sh
Created January 18, 2018 16:04
DB schema migration with heroku hosted postgres
#!/usr/bin/env bash
set -e
SOURCE_APP=web-app
TARGET_APP=$1
[ -z "$TARGET_APP" ] \
&& echo "usage: `basename $0` <TARGET_APP>" \
&& exit 1
@tsertkov
tsertkov / dashboard-rotator.html
Created January 18, 2018 15:50
Dashboard rotator
<!DOCTYPE HTML>
<html>
<head>
<title>Dashboard Rotator</title>
<script>
var dashboardDisplayTimeout = 120000;
var dashboards = [{
name: 'Tab1',
url: 'https://tab1.example.com'
}, {
@tsertkov
tsertkov / README.md
Last active May 17, 2023 14:06
Single-node kubernetes cluster cloud-config

Single-node kubernetes cluster cloud-config

Cloud-config files for setting up k8s single-node cluster with kubeadm on Ubuntu 16.04.3 LTS (Xenial Xerus)

cloud-config.minimal.yaml

Minimal installation of k8s with kubeadm.

cloud-config.full.yaml

@tsertkov
tsertkov / s3-routing-rules-generator.js
Created January 2, 2018 08:48
Generate AWS S3 redirecting routing rules
console.log('<RoutingRules>')
;[
['/url1/', '/url2/'],
['/url11/', '/url22/']
].forEach(([source, target]) => console.log(`
<RoutingRule>
<Condition>
<KeyPrefixEquals>${source}</KeyPrefixEquals>
</Condition>
@tsertkov
tsertkov / wp-json-importer.js
Created December 19, 2017 12:03
Import wp-json content using Wordpress REST API
const got = require('got')
async function authenticate (endpoint, username, password) {
try {
const response = await got(endpoint, {
json: true,
body: {
username,
password
}
@tsertkov
tsertkov / cloud-config.awslogs-auth.yaml
Last active December 16, 2017 18:44
Cloud-config for amzn2-ami provisioning docker env
#cloud-config
package_upgrade: true
packages:
- docker
- python2-pip
write_files:
- path: /etc/systemd/system/docker.service.d/aws-credentials.conf
content: |
[Service]
Environment="AWS_ACCESS_KEY_ID=<key>"
@tsertkov
tsertkov / curl-format.txt
Created December 11, 2017 19:48
Print request timing details and dump response headers with curl
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
----------\n
time_total: %{time_total}\n
@tsertkov
tsertkov / fn-uri-map-in-s3.js
Last active December 12, 2017 08:42
JS function using aws-sdk to download json map from s3 and use it to map request uri to redirect url
const AWS = require('aws-sdk')
const s3 = new AWS.S3()
function fetchJson (bucket, key) {
return new Promise((resolve, reject) => {
s3.getObject({ Bucket: bucket, Key: key }, (err, data) => {
if (err) return reject(err)
try {
const bodyString = data.Body.toString('utf8')