Skip to content

Instantly share code, notes, and snippets.

я котик пур-пур mvasilkov

Block or report user

Report or block mvasilkov

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
import re
from hashlib import md5
def gfm(text):
# Extract pre blocks.
extractions = {}
def pre_extraction_callback(matchobj):
digest = md5(
extractions[digest] =
return "{gfm-extraction-%s}" % digest
mvasilkov /
Created Nov 20, 2011
Tail recursive power function
from functools import partial, wraps
def power_tail(x, a, n):
assert n >= 0
if n == 0:
return x
elif n & 1:
return partial(power_tail, x * a, a, n - 1)
return partial(power_tail, x, a * a, n >> 1)
mvasilkov /
Created Jan 19, 2012 — forked from Ky6uk/
postfix to infix
#!/usr/bin/env perl
use 5.01;
do { say "USAGE: $0 <postfix.txt>"; exit 0 }
unless $ARGV[0];
# --------------- main -----------------
my (@data, $char, $result, @stack);
View generate_infix.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBER_STATE 3
char OPERATORS[] = {'/', '*', '-', '+'};
mvasilkov /
Created Jan 27, 2012
RestfulView from libanimuchan
from django.shortcuts import render
class RestfulView(object):
allowed_methods = ["GET", "POST"]
def __call__(self, request, *args, **kwargs):
if request.method not in self.allowed_methods or not hasattr(self, request.method):
return self.method_not_allowed(request)
return getattr(self, request.method)(request, *args, **kwargs)
View locale.c
#include <locale.h>
#include <stdio.h>
#include <wchar.h>
int main() {
wchar_t name[10];
wcscpy(name, L"жажа");
setlocale(LC_CTYPE, "en_US.UTF-8");
wprintf(L"%S\n", name);
View hell.cxx
template< class, class >
class Permutation;
template< class OUT_TYPE, class... IN_TYPES, uint32_t... INDEXES >
class Permutation<
std::function< OUT_TYPE (IN_TYPES...) >, // тип целевой функции
UintContainer< INDEXES... > > // перестановка аргументов
typedef std::function< OUT_TYPE (IN_TYPES...) > FuncType;
typedef std::function< OUT_TYPE (typename GetNthType< INDEXES, TypeContainer<IN_TYPES...> >::Result...) > NewFuncType;
mvasilkov /
Created Feb 9, 2012
Return first non-repeating (unique) symbol in the string. With tests and timeit.
#!/usr/bin/env python
import re
from timeit import timeit
import unittest
UNIQ_RE = re.compile(r'(.)(?=.*?\1)')
'test': 'e',
'plperl': 'e',
mvasilkov / foo.c
Created Feb 14, 2012
Single-malloc char** allocation.
View foo.c
#include <stdio.h>
#include <stdlib.h>
#define N (3)
const size_t offset = sizeof(char *) * N,
length = (sizeof(char *) + sizeof(char) * N) * N;
int main(int argc, char **argv) {
char **foo = (char **)malloc(length);
mvasilkov / uwsgi.conf
Created May 19, 2012
Ricchan ( uWSGI config
View uwsgi.conf
description "uWSGI starter {ricchan}"
start on (local-filesystems
and runlevel [2345])
stop on runlevel [016]
exec /usr/local/bin/uwsgi --uid rei \
-s -M -p 2 \
You can’t perform that action at this time.