Skip to content

Instantly share code, notes, and snippets.

@RaD
RaD / .emacs
Last active April 25, 2016 19:38
My .emacs
;;
;; Определение операционной системы
;;
(defun system-is-linux()
(string-equal system-type "gnu/linux"))
(defun system-is-windows()
(string-equal system-type "windows-nt"))
;;
;; Информация о пользователе
@RaD
RaD / who_faster.py
Created March 25, 2016 11:39
To remember dump question about mutable types.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
python who_faster.py
step 1
check_list 5.89978313446
check_set 0.0123991966248
check_dict 0.063777923584
step 2
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Implement a console script that solves the standard Queens puzzle:
* Take an argument – size of the board (N).
* Place N chess queens on an N×N chessboard so that no two queens threaten each other.
* Print the number of possible solutions.
* Print the time that was required to solve the problem.
@RaD
RaD / normalize-names.ulp
Created December 29, 2013 23:14
Eagle CAD: Скрипт нормализации подписей компонентов на плате
#usage "<b>Snap silkscreen text on grid</b><hr/>\n"
"<author>Author: Ruslan Popov (ruslan.popov@gmail.com)</author>"
#require 6.05
string VERSION = "1.0";
int result = 0; // dialog result
string str; // temporary string
string cmd = "SET UNDO_LOG OFF;\n"; // script command to execute
@RaD
RaD / cairo.py
Created December 6, 2013 21:12
PyCairo Usage Example
from StringIO import StringIO
from cairo import ImageSurface, Context
from cairo import FORMAT_ARGB32, FONT_SLANT_NORMAL, FONT_WEIGHT_NORMAL
imagesize = (512,128)
surface = ImageSurface(FORMAT_ARGB32, *imagesize)
cr = Context(surface)
# paint background
@RaD
RaD / frontend_tags.py
Created October 15, 2013 08:18
django in_group template tag
# -*- coding: utf-8 -*-
from django import template
from django.utils.encoding import force_unicode
register = template.Library()
@register.filter
def in_group(user, groups):
@RaD
RaD / monokai-theme.el
Created August 28, 2013 21:55
Sublime Monokai Theme I just have fixed color for regions.
;;; monokai-theme.el --- REQUIRES EMACS 24: Monokai Color Theme for Emacs.
;; Copyright (C) 2012 Lorenzo Villani.
;;
;; Author: Lorenzo Villani <lorenzo@villani.me>
;; URL: https://github.com/lvillani/el-monokai-theme
;; Version: 0.0.10
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@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 "
@RaD
RaD / gist:1156930
Created August 19, 2011 14:29
Function to calculate the count of defined week day in date range
def days_count_for_date_range(index, begin, end):
"""
Метод для вычисления количества появлений определённого дня недели
внутри указанного диапазона дат, включительно.
@type index: integer
@param index: Индекс дня недели, понедельник=0.
@type begin: datetime.date
@param begin: Дата начала диапазона.
@type end: datetime.date
@RaD
RaD / weekday_iterator.py
Created July 12, 2011 11:01
This iterator generates the names of week day starting from `start` day.
def weekday_iterator(start=0):
""" This iterator generates the names
of week day starting from `start` day. """
names = ('mo', 'tu', 'we', 'th', 'fr', 'sa', 'su',)
maximum = len(names)
i = 0
while i < maximum:
index = (start + i) % maximum
value = names[index]
i += 1