Skip to content

Instantly share code, notes, and snippets.

@brake
brake / TalkingClock.js
Created September 7, 2014 13:42
Utility functions for Tasker (famous automation tool for Android). Provides correct time as text for use with Russian speaking TTS.
// Для использования в Android с программой Tasker.
// Формирует текущее время в текстовом виде для передачи любой русскоговорящей системе TTS.
// Решает проблему некорректного произношения времени, например 0:00, или 20:00.
// Проверен с русскими голосами Acapella и SVOX.
var hours = {
"час": [1, 21],
"часа": [2, 3, 4, 22, 23],
"часов": [0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
}
@brake
brake / argparse_demo.py
Created March 7, 2015 19:32
2.5 argparse tricks (sample code)
# -*- coding: UTF-8 -*-
"""
CLI скрипт, поддерживающий две ветви параметров:
userdb.py append <username> <age>
userdb.py show <userid>
Заглушка предусматривает, что:
пользователь с именем admin уже существует
по userid = 1 всегда возвращается User(name='admin', age=20)
@brake
brake / gpgd.bat
Created April 2, 2015 09:43
Start gpg for decrypting file in a batch mode (ask password in a GUI window)
@echo off
if "%~1" == "" (
echo Usage: %0 [file to decrypt]
) else (
gpg --batch %1
)
@brake
brake / swap_nibbles.py
Created April 3, 2015 08:16
Swap nibbles python
def swap_nibbles(s):
"""Swap nibbles in a hex string.
len(s) must be even otherwise ValueError will be raised.
"""
if len(s) % 2:
raise ValueError()
return ''.join([y+x for x,y in zip(*[iter(s)] * 2)])
@brake
brake / int_bytes.py
Created April 3, 2015 08:18
Swap between list of bytes and integer value
def bytes2int(b):
"""Convert list/tuple of two bytes to integer value"""
if len(b) != 2: raise ValueError('b must have exactly 2 items')
return (b[0] << 8) + b[1]
def int2bytes(i):
"""Convert integer value to list of bytes"""
if i > 0xFFFF:
raise ValueError()
@brake
brake / gist:2b0b9ac746aaf12edced
Last active January 19, 2016 15:05 — forked from sgergely/gist:3793166
Some MidnightCommander keyboard shortcuts
----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
@brake
brake / filelist2clip.pyw
Created June 26, 2015 19:27
Преобразование списка файлов из параметров командной строки в список имен файлов (без расширений), разделенный запятыми.
"""Преобразование списка файлов из параметров командной строки в список имен
файлов (без расширений), разделенный запятыми. Результат копируется в буфер
обмена
Пример:
было ['aaa.zip.pgp', 'bbb.zip.pgp', 'ccc.zip.pgp']
стало 'aaa, bbb, ccc'
"""
from sys import argv
from os import path
from Tkinter import Tk
@brake
brake / numbers_to_ranges.clj
Last active January 19, 2016 15:03
Turns sorted sequence of integers into list of number ranges in Clojure
(def a [1 2 3 4 6 8 9 11 12 13 14 20 21 23 24 25])
(loop [sq (rest a) fv (first a) lv (first a) res []]
(if (empty? sq)
(conj res [fv lv])
(if (= (- (first sq) lv) 1)
(recur (rest sq) fv (first sq) res)
(recur (rest sq) (first sq) (first sq) (conj res [fv lv])))))
=> [[1 4] [6 6] [8 9] [11 14] [20 21] [23 25]]
@brake
brake / rconst.clj
Created January 30, 2016 18:59
Create and print sequence of 5 random integers from 0 to (inclusive) 127
(doseq [n (repeatedly 5 #(rand-int 128))]
(printf "%02X (%d)\n" n n))
@brake
brake / create_symlink.scpt
Created May 22, 2016 13:27
Create symlink for file selected in Finder