This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from hashlib import md5 | |
def gfm(text): | |
# Extract pre blocks. | |
extractions = {} | |
def pre_extraction_callback(matchobj): | |
digest = md5(matchobj.group(0)).hexdigest() | |
extractions[digest] = matchobj.group(0) | |
return "{gfm-extraction-%s}" % digest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
else: | |
return partial(power_tail, x, a * a, n >> 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.01; | |
do { say "USAGE: $0 <postfix.txt>"; exit 0 } | |
unless $ARGV[0]; | |
# --------------- main ----------------- | |
my (@data, $char, $result, @stack); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define OPEN_BRACKET_STATE 1 | |
#define CLOSE_BRACKET_STATE 2 | |
#define NUMBER_STATE 3 | |
#define OPERATOR_STATE 4 | |
char OPERATORS[] = {'/', '*', '-', '+'}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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... > > // перестановка аргументов | |
{ | |
public: | |
typedef std::function< OUT_TYPE (IN_TYPES...) > FuncType; | |
typedef std::function< OUT_TYPE (typename GetNthType< INDEXES, TypeContainer<IN_TYPES...> >::Result...) > NewFuncType; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re | |
from timeit import timeit | |
import unittest | |
UNIQ_RE = re.compile(r'(.)(?=.*?\1)') | |
TESTS = { | |
'test': 'e', | |
'plperl': 'e', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
description "uWSGI starter {ricchan}" | |
start on (local-filesystems | |
and runlevel [2345]) | |
stop on runlevel [016] | |
respawn | |
exec /usr/local/bin/uwsgi --uid rei \ | |
-s 127.0.0.1:9001 -M -p 2 \ |
OlderNewer