Skip to content

Instantly share code, notes, and snippets.

View anossov's full-sized avatar

Pavel Anossov anossov

View GitHub Profile
@anossov
anossov / bitap.py
Created December 6, 2015 17:11
Python implementation of exact-matching Bitap
def bitap_search(text, pattern):
"""
Returns position of pattern in text or -1 if it wasn't found.
text and pattern are strings.
>>> bitap_search("test text", "tex")
5
>>> bitap_search("test text", "z")
-1
//global
"ZreknarF":["cdn.frankerfacez.com/channel/global/ZreknarF.png"],
"LilZ":["cdn.frankerfacez.com/channel/global/LilZ.png"],
"BeanieHipster":["cdn.frankerfacez.com/channel/global/BeanieHipster.png"],
"ManChicken":["cdn.frankerfacez.com/channel/global/ManChicken.png"],
"YellowFever":["cdn.frankerfacez.com/channel/global/YellowFever.png"],
"YooHoo":["cdn.frankerfacez.com/channel/global/YooHoo.png"],
//00greenbean00
"BeanAhab":["cdn.frankerfacez.com/channel/00greenbean00/BeanAhab.png"],
"BeanHori":["cdn.frankerfacez.com/channel/00greenbean00/BeanHori.png"],
""" Dice rolling simulator, will ask user to press Enter to roll.
Will print a random number between 1 to 6. Will ask user if they want to roll again. """
import random
print "Welcome to the Dice Rolling Simulator!\n"
print "Press Enter to roll the dice."
begin = raw_input("")
""" function where random numbers are generated """
@anossov
anossov / config_parser.py
Created June 8, 2014 18:45
Config parser for github.com/acedrew/ubnt-mfi-py
import json
from collections import defaultdict
def parse_config(conf):
def Tree():
return defaultdict(Tree)
data = Tree()
@anossov
anossov / gist:8707420
Created January 30, 2014 12:25
cPython small integers
#ifndef NSMALLPOSINTS
#define NSMALLPOSINTS 257
#endif
#ifndef NSMALLNEGINTS
#define NSMALLNEGINTS 5
#endif
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
/* References to small integers are saved in this array so that they
can be shared.
The integers that are saved are those in the range
@anossov
anossov / gist:7927031
Created December 12, 2013 12:04
re.DEBUG
In [87]: re.compile(r'[A-Z]{2,}(?:\s+[A-Z]{2,})+', re.DEBUG)
max_repeat 2 65535
in
range (65, 90)
max_repeat 1 65535
subpattern None
max_repeat 1 65535
in
@anossov
anossov / test.py
Last active December 29, 2015 18:18
Panda3d: trying to use sampler2DArray in GLSL
import direct.directbase.DirectStart
from panda3d.core import *
vertex = '''
#version 330
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;
uniform mat4 p3d_ModelViewProjectionMatrix;
@anossov
anossov / test.py
Last active December 29, 2015 17:39
Panda3d 1.9dev: Broken textures with auto-shader and dynamic Geoms
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from panda3d.core import *
loadPrcFileData("", "dump-generated-shaders 1")
base.setBackgroundColor(0.5, 0.5, 0.5)
t = OnscreenText(text='asdallaskjf', scale=0.5)
class A(object):
def x(cls):
return cls.x.y
x.y = 123
x = classmethod(x)
@anossov
anossov / gist:5411655
Created April 18, 2013 10:12
method attributes
class A(object):
def x(self):
return self.x.y
x.y = 123
class B(object):
def x(self):
return B.x.y
x.y = 123