Skip to content

Instantly share code, notes, and snippets.

View VladSavitsky's full-sized avatar

Vlad Savitsky VladSavitsky

View GitHub Profile
@VladSavitsky
VladSavitsky / mon
Created March 17, 2024 19:16
Dual Monitors configuration from command line
#!/usr/bin/env bash
# Summary: Enables and disables monitors.
# Usage: mon <command:|e|i|l|r|m>
# Help:
# Params:
# <command>
# - e|external - Enable only external. Default.
# - i|internal - Enable only internal (built-in).
# - l|left - Enable both but left is primary.
#!/usr/bin/env bash
BAT=$(echo /sys/class/power_supply/BAT*)
BAT_STATUS="$BAT/status"
BAT_CAP="$BAT/capacity"
LOW_BAT_PERCENT=20
AC_PROFILE="performance"
BAT_PROFILE="balanced"
LOW_BAT_PROFILE="power-saver"

Found here by Stephan Farestam

Here is a bash-only YAML parser that leverages sed and awk to parse simple yaml files:

function parse_yaml {
   local prefix=$2
   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
   sed -ne "s|^\($s\):|\1|" \
        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \

-e "s|^($s)($w)$s:$s(.*)$s$|\1$fs\2$fs\3|p" $1 |

@VladSavitsky
VladSavitsky / caluclator.bash
Last active March 29, 2022 19:55
Tiny Pure BASH Calulator
# CLI Calculator.
#
# Install: Add to .bashrc.
#
# Usage: '$ = 10*33'
# See: https://askubuntu.com/questions/378661
#
# Installation: Put code to .bashrc or .bash_aliases.
#
# Functions:
@VladSavitsky
VladSavitsky / php-xdebug.log
Last active June 9, 2020 14:38
Vdebug and symlinks
bash-5.0# cat /tmp/php-xdebug.log
[85] Log opened at 2020-06-09 14:34:19
[85] I: Connecting to configured address/port: 172.17.0.1:9000.
[85] I: Connected to client. :-)
[85] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///var/www/html/index.php" language="PHP" xdebug:language_version="7.1.32" protocol_version="1.0" appid="85" idekey="ngl"><engine version="2.7.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2019 by Derick Rethans]]></copyright></init>
[85]
[85] <- context_names -i 1
[85] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="context_names" transaction_id="1"><context name="Locals" id="0"></context><context name="Superglobals" id="1"></context><context name="User defined constants" id="2"></context></response>
[85]
[85] <- feature_set -i 2 -n max_children -v 256
@VladSavitsky
VladSavitsky / gist:c03be6d5fb8e73e4286c758b41893a0b
Created December 14, 2018 07:43
buscentr.com.ua show only existing items
// Hides not available itms at ehttps://buscentr.com.ua
$('.not_exists').parents('.row.catalog_item').hide();
@VladSavitsky
VladSavitsky / disable_view
Created April 20, 2015 19:12
Disable views page programmatically
/**
* Disable workbench views
*/
function mymodule_update_7001() {
// a list of views (their view name) I want to disable
$viewnames = array(
'workbench_current_user',
);
к сожалению да, но там ничего сложного нету
в $form_state['storage'] хранишь кол-во полей
добавляешь поля в fieldset
так же создаешь кнопку с ajax callback
и в этом callback увеличиваешь счетчик в $form_state['storage']['count']
ну и в определении формы выводишь кол-во полей на основе этого значения
http://xandeadx.ru/blog/drupal/644
http://drupal.stackexchange.com/questions/18363/given-a-file-id-fid-how-can-i-get-the-html-that-represents-that-fid
@VladSavitsky
VladSavitsky / Drupal Image (Media) Field
Last active August 29, 2015 14:18
Drupal Form API
$form['image'] = array(
'#type' => 'media',
'#tree' => TRUE,
'#title' => t('Image'),
'#description' => t('Allowed formats: png, jpg, jpeg, gif.'),
'#media_options' => array(
'global' => array(
'file_extensions' => 'png jpg jpeg gif',
'max_filesize' => '20 MB',
'file_directory' => '',