Skip to content

Instantly share code, notes, and snippets.

View comm1x's full-sized avatar

Pavel Shorokhov comm1x

View GitHub Profile
@comm1x
comm1x / translator.py
Last active December 18, 2015 10:56
Translate text in clipboard
import os
import gtk
from textblob import TextBlob
word = gtk.clipboard_get(selection="PRIMARY").wait_for_text()
if not word:
word = gtk.clipboard_get(selection="CLIPBOARD").wait_for_text()
if word:
source_lang = TextBlob(word).detect_language()
@comm1x
comm1x / jquery.touchclick.js
Created August 15, 2014 13:04
jQuery event touchclick
$.event.special.touchclick = {
setup : function(data) {
var elt = $(this);
elt.data($.extend({
sens : 25 // Available touch offset in pixels
}, data));
elt.bind("touchstart", $.event.special.touchclick.onTouchstart);
elt.bind("touchend", $.event.special.touchclick.onTouchend);
@comm1x
comm1x / pt.sh
Created March 14, 2016 09:49
PT - alias wrapper for apt-get, apt-cache commands
#!/bin/bash
cmd=$1
arguments=${@:2}
if [[ $cmd = "install" ]]; then
command sudo apt-get install $arguments
exit 0
fi
@comm1x
comm1x / httpdump
Created March 16, 2016 20:10
HTTPDump - bash wrapper for TCPDump
#!/usr/bin/env bash
if [ $# -eq 0 ]; then
echo 'HTTPDump - wrapper for TCPDump'
echo 'Usage: httpdump [HOST|any]'
exit 0
fi
host=$1
host_cond=""
@comm1x
comm1x / git-brst
Created April 11, 2016 14:12
git-brst - utility for display details about commits for branch
#!/usr/bin/env bash
# Check is in git repo
if ! [ -d .git ] || ! git rev-parse --git-dir > /dev/null 2>&1; then
echo "Git repository not found";
exit 1;
fi
branch=${1};
commits_limit=5
@comm1x
comm1x / getByDotNotation.php
Last active April 13, 2016 13:09
PHP: get access for array via dot notation
<?php
/**
* Get access to array via dot notation, for example:
* 'user.names.first'
* @param array $array Source array
* @param string $path Path in dot notation
*/
function getByDotNotation($array, $path) {
foreach (explode('.', $path) as $part) {
@comm1x
comm1x / getParamsByRegex.php
Created April 13, 2016 17:56
PHP function getParamsByRegex
<?php
/**
* Получает параметры из строки по регулярному выражению, например:
* getParamsByRegex('/<controller:\w+>/<id>/<action>', '/user/5/login') вернет массив
* [
* 'controller' => 'user',
* 'id' => 5,
* 'action' => 'login
* ]
@comm1x
comm1x / jsonlint
Created May 30, 2016 20:56
JsonLint - bash utility for linting input json
#!/usr/bin/env php
<?php
$file = fopen('php://stdin', 'r');
$lines = '';
while ($line = fgets($file)) {
$lines .= $line;
}
$array = json_decode($lines, true);
echo json_encode($array, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
@comm1x
comm1x / convert-tint
Last active October 28, 2017 00:06
Imagemagick script for tinting images. Replace all color with given.
#!/usr/bin/env bash
if [ $# -le 2 ]; then
echo 'convert-tint - script for tinting images, replace any color with given.'
echo 'Usage: convert-tint source.jpg "#FF0000" target.jpg'
exit 0
fi
source=$1
color=$2
@comm1x
comm1x / dsh
Created January 18, 2018 22:34
Docker exec helper with interactive mode
#!/usr/bin/env bash
if [ $# -eq 1 ] && [ "$1" == "-h" ]; then
echo 'dsh - wrapper for "docker exec -it CONTAINER bash".'
echo 'Usage: dsh # interactive mode'
echo ' dsh CONTAINER # bash'
echo ' dsh CONTAINER cmd # run cmd'
exit 0
fi