Skip to content

Instantly share code, notes, and snippets.

@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
@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 / middleware.py
Created August 6, 2012 21:20
Keep user sorting and filtering settings of models with Django's admin site
# -*- coding: utf-8 -*-
import re
from django.shortcuts import redirect
PREF_VAR = 'ADMIN_PER_USER_PREF'
ORDER_VAR = 'o'
FILTER_TAIL = '__exact'
PATH = '/admin/storage/'
@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 / .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 / 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 / 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 / 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
/*
Buffer visualisation thread.
*/
static WORKING_AREA(visual_wa, 128);
static msg_t visual(void *arg) {
(void) arg;
uint8_t col = 0;
chRegSetThreadName("display_refresh");
palWriteGroup(GPIOA, 0b11111111, 0, 0b00000000);
@RaD
RaD / hobbed_support.scad
Last active August 29, 2015 13:56
Hobbed Bolt Magic Device
// Hobbed Bolt Support
// Authors: Alexander, http://vk.com/linuxbashev
// Ruslan Popov, http://vk.com/id19523249
// Original: http://www.thingiverse.com/thing:151669
// Requires: http://curriculum.makerbot.com/daily_lessons/february/openscad_write.html
// Usage:
// * to generate all on one model:
// openscad -o all-in-one.stl hobbed_support.scad
// * to generate a particular model use 0, 1, or 2 as N:
// openscad -D only=N -o hobbed_N.stl hobbed_support.scad