Skip to content

Instantly share code, notes, and snippets.

Avatar
🖐️
Say Hello

Aleksandr Tsertkov tsertkov

🖐️
Say Hello
View GitHub Profile
@tsertkov
tsertkov / acf-php-to-json.php
Last active Feb 4, 2020 — forked from ollietreend/acf-php-to-json.php
Convert Advanced Custom Fields Pro configuration from PHP to JSON.
View acf-php-to-json.php
<?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 Jan 30, 2020 — forked from kisabelle/acf-php-to-json.php
Convert ACF Fields Registered by PHP to Importable JSON Format
View acf-php-to-json.php
$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 Oct 22, 2019
JavaScript array tips & tricks
View javascript-array-tips-and-tricks.md

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 Sep 28, 2019
Setup GPG agent for ssh authentication and more
@tsertkov
tsertkov / nat-fwd.sh
Last active Sep 11, 2019
Forward ports through a Linux gateway with iptables
View nat-fwd.sh
#!/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 Dec 18, 2018 — forked from chrisguitarguy/wp-remove-dashboard.php
Remove all the default WordPress dashboard widgets.
View wp-remove-dashboard.php
<?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 Oct 23, 2018
Conditionally triggering custom tag (loading remote js script) based on user geolocation and other conditions.
View conditional-custom-tag-trigger.js
<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 Jun 18, 2018
Send slack message with preformatted content (e.g. file, command output, etc.) from shell
View send-slack-preformatted.sh
#!/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
NodeJs http get downloader with concurrency control
View nodejs-get-url-concurrency-control.js
// 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 = []