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 / nat-fwd.sh
Last active September 11, 2019 08:00
Forward ports through a Linux gateway with iptables
#!/usr/bin/env bash
i_in=en0
i_out=en1
dport=1234
dst=1.2.3.4
src=4.3.2.1
iptables -A FORWARD -i $i_in -o $i_out -p tcp --syn --dport $dport -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -i $i_out -o $i_in -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
@tsertkov
tsertkov / wp-remove-dashboard.php
Created December 18, 2018 12:33 — forked from chrisguitarguy/wp-remove-dashboard.php
Remove all the default WordPress dashboard widgets.
<?php
/*
Plugin Name: Remove Dashboard Meta Boxes
Plugin URI: http://pmg.co/category/wordpress
Description: Removes the default dashboard widgets from the WordPress admin.
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: GPL2
*/
@tsertkov
tsertkov / conditional-custom-tag-trigger.js
Created October 23, 2018 08:04
Conditionally triggering custom tag (loading remote js script) based on user geolocation and other conditions.
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script id="myScript" type="text/javascript">
(function (){
var excludeCountries = [
'Russia'
]
var timeout = 10000
var cookieValue = document.cookie.replace(/(?:(?:^|.*;\s*)no_ads\s*\=\s*([^;]*).*$)|^.*$/, '$1')
@tsertkov
tsertkov / send-slack-preformatted.sh
Created June 18, 2018 19:44
Send slack message with preformatted content (e.g. file, command output, etc.) from shell
#!/usr/bin/env bash
HOOK_URL="https://hooks.slack.com/services/XXX"
FILE="/etc/passwd"
MSG="Here is file content as preformatted text:"$'\n```\n'"$(< "$FILE")"$'\n```\n'
PAYLOAD="$(jq --raw-input --slurp '{text:.}' <<< "$MSG")"
curl \
-X POST \
-H 'Content-type: application/json' \
@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 / 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
}