Skip to content

Instantly share code, notes, and snippets.

@RaD
RaD / diskinfo.py
Created November 22, 2014 09:14
Simple wrapper for OS utilities
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import platform
import re
import subprocess
import sys
import tempfile
@RaD
RaD / make-a-dict.py
Created November 30, 2014 12:18
Есть два списка разной длины. В первом содержатся ключи, а во втором значения. Напишите функцию, которая создаёт из этих ключей и значений словарь. Если ключу не хватило значения, в словаре должно быть значение None. Значения, которым не хватило ключей, нужно игнорировать.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a = ['a', 'b', 'c']
b = [1, 2, 3]
c = ['a', 'b']
d = [1 , 2]
def myzip(keys, values):
d = {}
@RaD
RaD / login-check.py
Created November 30, 2014 12:20
В системе аутентификации есть ограничение: логин должен начинаться с латинской буквы, состоять из латинских букв, цифр, точки и минуса, но заканчиваться только латинской буквой или цифрой; минимальная длина логина — один символ, максимальная — 20. Напишите код, проверяющий соответствие входной строки этому правилу.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
a = 'a'
b = 'a12-4b'
c = '1234vvv'
d = 'afdf23-'
e = 'asd1_2a'
f = 'abcdeffwcflszsafdibcawerxbweiowberqwrrwrxe'
@RaD
RaD / mdadm.log
Created December 16, 2014 22:25
Пытаюсь починить массив
[22244.117869] ata5.00: exception Emask 0x0 SAct 0xf SErr 0x0 action 0x0
[22244.117876] ata5.00: irq_stat 0x40000008
[22244.117881] ata5.00: failed command: READ FPDMA QUEUED
[22244.117890] ata5.00: cmd 60/00:00:b2:0d:70/04:00:db:00:00/40 tag 0 ncq 524288 in
[22244.117890] res 41/40:00:40:11:70/00:00:db:00:00/40 Emask 0x409 (media error) <F>
[22244.117894] ata5.00: status: { DRDY ERR }
[22244.117897] ata5.00: error: { UNC }
[22244.124956] ata5.00: configured for UDMA/133
[22244.124990] sd 4:0:0:0: [sda] Unhandled sense code
[22244.124994] sd 4:0:0:0: [sda]
@RaD
RaD / sound.py
Created January 4, 2015 23:51
Test framework
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from wavebender import *
from itertools import *
formanta = [0, 10, 19, 28, 36, 44, 50, 55, 60, 62, 64, 64, 62, 60, 55, 50, 44,
36, 28, 19, 10, 0, -10, -19, -28, -36, -44, -50, -55, -60, -62,
-64, -64, -62, -60, -55, -50, -44, -36, -28, -19, -10]
@RaD
RaD / nuke-buffers.el
Created February 20, 2015 07:19
Kill almost all buffers in Emacs but keep some alive.
(defun nuke-all-buffers ()
"kill all buffers, leaving only limited set of buffers"
(interactive)
(let* ((keep-them-alive '("*scratch*" "*Messages*" "*Pymacs*")))
(mapcar (lambda (x)
(unless (member (buffer-name x) keep-them-alive)
(kill-buffer x)))
(buffer-list))))
@RaD
RaD / cura-backport.diff
Last active August 29, 2015 14:17
Backport filament weight/price/length from Cura version 15.02.1 to 14.12.1.
--- sliceEngine.py 2015-03-23 21:36:07.000000000 +0300
+++ sliceEngine.p 2015-03-28 23:33:43.000000000 +0300
@@ -89,16 +89,22 @@
def getPrintTime(self):
if self._printTimeSeconds is None:
return ''
- if int(self._printTimeSeconds / 60 / 60) < 1:
- return _('%d minutes') % (int(self._printTimeSeconds / 60) % 60)
- if int(self._printTimeSeconds / 60 / 60) == 1:
- return _('%d hour %d minutes') % (int(self._printTimeSeconds / 60 / 60), int(self._printTimeSeconds / 60) % 60)
@RaD
RaD / linesender.py
Created June 4, 2015 08:48
Sends the file to STDOUT in a line by line manner.
import argparse
import time
import sys
def read_by_line(input, delay, is_recourse):
while True:
input.seek(0)
for line in input:
sys.stdout.write(line)
@RaD
RaD / .gitconfig
Last active September 27, 2021 09:26
Git Global Config
[gui]
encoding = utf-8
[alias]
#visual = gitk
last = log -1 HEAD
st = status
shorty = status --short --branch
# git unstage - убрать всё из индекса (чтобы например добавить/закоммитить сначала что-то другое)
unstage = reset HEAD --
up = !(git add . && git stash && git pull --rebase >&2) | grep -v \"No local changes to save\" && git stash pop
@RaD
RaD / panelize.ulp
Last active October 10, 2015 08:03
PCB panelization script
#usage "<b>Generate name layers to panelize board</b>\n"
"<p>"
"Generates a command sequence which copies the name texts (support spin-flag) "
"of all elements of your layout into newly generated layers (125 and 126). "
"After running the ULP you can GROUP, CUT and PASTE your layout "
"to get an array of several boards. Make sure all layers are displayed before."
"<p>"
"The duplicated name texts in the new layers will not be changed. "
"Please notice that you have to deactivate layers 25 and 26 if you use "
"the CAM processor e.g. for generating gerber data. Instead, you have to activate "