Skip to content

Instantly share code, notes, and snippets.

View nvbn's full-sized avatar

Vladimir Iakovlev nvbn

View GitHub Profile
@nvbn
nvbn / example.py
Created September 14, 2015 09:51
python 3.5 matrix multiplication operator in use
from io import BytesIO
from PIL import Image, ImageDraw, ImageFont
import requests
def get_x(img, draw, font, text):
img_w, _ = img.size
text_w, _ = draw.textsize(text, font=font)
return int((img_w - text_w) / 2)
@nvbn
nvbn / nvbn.zsh-theme
Created October 8, 2015 21:28
nvbn.zsh-theme
local ret_status="%(?:%{$fg_bold[white]%}🔧 :%{$fg_bold[red]%}🗡 %s)"
PROMPT='%{$fg_bold[green]%}%p%{$fg[cyan]%}%c $(git_prompt_info)$(virtualenv_prompt_info)% ${ret_status} %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$reset_colori%}"
ZSH_THEME_VIRTUALENV_PREFIX="%{$fg_bold[blue]%}"
ZSH_THEME_VIRTUALENV_SUFFIX="%{$reset_color%} "
@nvbn
nvbn / freeze.py
Last active April 29, 2016 23:06
from google.appengine.api import datastore_types
from mock import patch
from freezegun import freeze_time as _freeze_time
from freezegun.api import FakeDatetime
class freeze_time(object):
def __init__(self, *args, **kwargs):
self._gae_patch = patch(
'google.appengine.ext.db.DateTimeProperty.data_type',
import pyparsing as pp
token = pp.Word(pp.alphanums + '_-.')
command = pp.OneOrMore(token)
separators = ['1>>', '2>>', '>>', '1>', '2>', '>', '<', '||',
'|', '&&', '&', ';']
separator = pp.oneOf(separators)
@nvbn
nvbn / partial_and_pipe.py
Created August 9, 2016 11:44
Partial application and piping without magic
from functools import wraps
class Partial:
def __init__(self, fn, args, kwargs):
self._fn = fn
self._args = args
self._kwargs = kwargs
def __call__(self, replacement):
@nvbn
nvbn / partial_and_pipe_2.py
Created August 10, 2016 14:20
Partial application and piping with AST transformation
import ast
class EllipsisPartialTransform(ast.NodeTransformer):
def __init__(self):
self._counter = 0
def _get_arg_name(self):
"""Return unique argument name for lambda."""
try:
(ns math-6.core
(:require [clojure.math.numeric-tower :refer [abs]]))
(def boundaries (range -100 100))
(defn- get-cs-after-second
[c-before-before c-before]
(when-let [c (mod c-before-before c-before)]
(if (zero? c)
[0]
@nvbn
nvbn / complexity.py
Created March 17, 2017 13:51
Primitive complexity analyzer
from collections import namedtuple
import timeit
import matplotlib.pyplot as plt
ComplexityLogEntry = namedtuple('ComplexityLogEntry', ('size', 'time'))
class BaseComplexityAssumption(object):
title = ''
@nvbn
nvbn / validator.cpp
Created April 5, 2017 13:11
validator
#include <iostream>
#include <sstream>
#include <regex>
using namespace std;
class Validator {
public:
Validator(istream &in) : in_(in) {}
@nvbn
nvbn / out.py
Last active May 1, 2017 18:58
py-backwards result
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
def _py_backwards_merge_dicts(dicts):
result = {}
for dict_ in dicts:
result.update(dict_)