Skip to content

Instantly share code, notes, and snippets.

View zviryatko's full-sized avatar
😱
Kill beavers - save tree!

Oleksandr Davyskiba zviryatko

😱
Kill beavers - save tree!
  • Ukraine, Kiev
View GitHub Profile
@zviryatko
zviryatko / BetweenColumns.php
Created April 24, 2014 08:24
Zend framework 2 sql predicate that provide between columns clause.
<?php
/**
* @file
* Provide sql expression where the value between columns
*
* @copyright Copyright (c) 2014 HTML&CMS (http://html-and-cms.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace HTMLandCMS\Db\Sql\Predicate;
@zviryatko
zviryatko / script.js
Created January 9, 2015 16:12
Sisyphus.js don't save uncheckable radio buttons
(function($) {
$(document).ready() {
var $forms = $('form');
$forms.find(':radio').change(function() {
var sisyphus = Sisyphus.getInstance();
var name = $(this).attr("name");
var $form = $(this).parents('form');
if (!$form.find(':radio[name="' + name + '"]:checked').length) {
var prefix = (sisyphus.options.locationBased ? sisyphus.href : "") + $form.attr("id") + $form.attr("name") + name + sisyphus.options.customKeySuffix;
sisyphus.saveToBrowserStorage(prefix, '', false);
@zviryatko
zviryatko / switch-master-channel
Created June 19, 2015 08:29
Switch PulseAudio master channel between multiple sound cards
#!/bin/bash
# Switch PulseAudio master channel between multiple sound cards
ENABLED=$(pacmd list-sinks | grep -A1 '* index' | grep 'name' | awk '{print $2}' | tr -d '<->')
DEVICE=$(pacmd list-sinks | grep 'name:' | awk '{print $2}' | tr -d '<->' | grep -v $ENABLED)
pactl set-default-sink $DEVICE
pactl set-default-source "$DEVICE.monitor"
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
for i in ${INPUTS[*]}; do pacmd move-sink-input $i $DEVICE &> /dev/null; done
qdbus org.kde.kmix /Mixers org.kde.KMix.MixSet.setCurrentMaster "PulseAudio::Playback_Devices=:1" "$DEVICE" 2>&1 > /dev/null
@zviryatko
zviryatko / fix_image_uploader.css
Last active August 29, 2015 14:26
Drupal: filefield_sources + visual_select_file + multiupload_imagefield_widget = ❤️, see https://makeyoulivebetter.org.ua/node/625
.filefield-source.filefield-source-reference {
float: right;
overflow: hidden;
}
.filefield-source.filefield-source-reference > .form-item {
padding: 0;
}
@zviryatko
zviryatko / screenshot.sh
Last active October 15, 2016 08:50
Take screenshot and save to Dropbox
#!/bin/bash
FILE="$HOME/Dropbox/Public/screenshot/screenshot-$(date +%F_%H:%M:%S).png"
import $FILE && dropbox sharelink $FILE | parcellite -c
# Or use xclip instead of parcellite
# import $FILE && dropbox puburl $FILE | xclip -selection clipboard
# For Kde4 & Klipper use this bash-script
# https://github.com/milianw/shell-helpers/blob/master/clipboard
@zviryatko
zviryatko / change-governor
Created October 7, 2015 22:38
Change governor
#!/bin/bash
# Put this file to any your local $PATH directory.
let n=$((`nproc` - 1))
if [[ $(cpufreq-info --governors) =~ $1 ]]
then
for i in `seq 0 $n`
do
`sudo cpufreq-set -c $i -g $1`
done
<?php
/**
* Implements hook_menu_alter().
*/
function familink_custom_menu_alter(&$items) {
$items['user/%user/cancel']['access callback'] = 'familink_custom_user_admin_access';
$items['user/%user/cancel']['access arguments'] = array(1, 'user_cancel_access');
$items['user/%user/cancel/confirm/%/%']['access callback'] = 'familink_custom_user_admin_access';
@zviryatko
zviryatko / README.md
Last active July 22, 2021 10:40
Nginx config to catch all .devel sites

This little gist help you to catch all *.devel domain and open localhost for it.

First you need to set up local DNS server and add it to resolv conf.

sudo apt-get install bind9 dnsutils resolvconf

bind9 - DNS server

resolvconf - help you to manage you /etc/resolv.conf file automatically independs on network configuration

@zviryatko
zviryatko / custom.theme.php
Created December 15, 2015 13:19
Add title to breadcrumbs in Drupal 8
<?php
/**
* Implements hook_process_HOOK().
*/
function custom_preprocess_breadcrumb(&$variables) {
/** @var \Drupal\Core\Controller\TitleResolverInterface $title_resolver */
$title_resolver = \Drupal::service('title_resolver');
/** @var \Drupal\Core\Routing\CurrentRouteMatch $current_route */
$current_route = \Drupal::service('current_route_match');
@zviryatko
zviryatko / bashrc
Last active December 29, 2015 14:21
Allow drush to run above the drupal root directory
function drush {
DRUSH=$(which drush)
PWD=$(pwd)
if [ -f 'drush/drushrc.php' ];
then
$DRUSH -c ./drush/drushrc.php "$@";
elif [ -d "$PWD/web" ];
then
$DRUSH --root="$PWD/web" "$@";
else