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 / README.md
Last active May 26, 2023 10:19
Http response time monitoring script (ruby)

http-monitor.rb

Simple ruby script to monitor http response times over a period of time.

% ruby http-monitor.rb https://google.com 20 3

2023-05-26 12:13:59 : (GET https://google.com) : 1.207913s
2023-05-26 12:14:02 : (GET https://google.com) : 0.102176s
2023-05-26 12:14:05 : (GET https://google.com) : 0.146981s
@tsertkov
tsertkov / acf-php-to-json.php
Last active February 4, 2020 11:04 — forked from ollietreend/acf-php-to-json.php
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
<?php
/**
* Plugin Name: Convert ACF PHP to JSON
* Description: Convert Advanced Custom Fields Pro configuration from PHP to JSON.
*/
namespace ConvertAcfPhpToJson;
/**
* Add submenu item under 'Custom Fields'
@tsertkov
tsertkov / acf-php-to-json.php
Created January 30, 2020 09:13 — forked from kisabelle/acf-php-to-json.php
Convert ACF Fields Registered by PHP to Importable JSON Format
$groups = acf_get_local_field_groups();
$json = [];
foreach ($groups as $group) {
// Fetch the fields for the given group key
$fields = acf_get_local_fields($group['key']);
// Remove unecessary key value pair with key "ID"
unset($group['ID']);
@tsertkov
tsertkov / javascript-array-tips-and-tricks.md
Last active October 22, 2019 09:30
JavaScript array tips & tricks

JavaScript array tips & tricks

// Array mapping with .from()

Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({key}) => key)
Array.from([{ 'key': 1, 'value': 'val1'}, { 'key': 2, 'value': 'val2' }], ({value}) => value)

// Get random value from array
@tsertkov
tsertkov / Gpg-agent-setup.md
Last active September 28, 2019 07:50
Setup GPG agent for ssh authentication and more
@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' \