Skip to content

Instantly share code, notes, and snippets.

View rvasilevsk's full-sized avatar

Roman rvasilevsk

  • Minsk, Belarus
View GitHub Profile
@rvasilevsk
rvasilevsk / py_typing.py
Created July 5, 2020 15:06
[python typing] #python #typing
tuple # typing.Tuple
list # typing.List
dict # typing.Dict
set # typing.Set
frozenset # typing.FrozenSet
type # typing.Type
collections.deque
collections.defaultdict
collections.OrderedDict
collections.Counter
@rvasilevsk
rvasilevsk / arr_stuff.php
Created July 5, 2020 15:12
[arr_stuff.php] #php #array
function arrGet($arr, $key, $default = null)
{
return isset($arr[$key]) ? $arr[$key] : $default;
}
function arrAny()
{
foreach (func_get_args() as $arg) {
if ($arg) return $arg;
}
@rvasilevsk
rvasilevsk / str_to_int.php
Last active July 5, 2020 15:12
[str_to_int.php] #php #int
function realIntVal($s, $onEmptyStr=null, $onNonNumeric=null) {
if ($s === '') return $onEmptyStr;
return is_numeric($s) ? intval($s) : $onNonNumeric;
}
function testRealIntVal() {
$arr = ['', '0', '1', 'a', 'a123', '123a', null];
$res = [];
foreach ($arr as $v) {
$res[$v] = realIntVal($v);
@rvasilevsk
rvasilevsk / php_errors.php
Last active August 24, 2020 11:28
[php errors] #php #err
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
@rvasilevsk
rvasilevsk / pygame_draw.py
Created August 25, 2020 09:29
[pygame_draw.py] #python #2d #pygame
import pygame as pg
FPS = 30
WW = 800
WH = 600
BLUE = (0, 0, 255)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
@rvasilevsk
rvasilevsk / requirements.txt
Created August 25, 2020 09:30
[requirements.txt - polina] #polina #pip.requirements
pygame
#pycairo
p5
@rvasilevsk
rvasilevsk / polina.py
Last active August 25, 2020 09:31
[polina.py] #polina #python
def s_ring(r1, r2):
pi = 3.1415
s1 = pi * (r1 ** 2)
s2 = pi * (r2 ** 2)
s = s2 - s1
return s
def hyp(a, b):
return (a ** 2 + b ** 2) ** 0.5
@rvasilevsk
rvasilevsk / polina_equ2.py
Created August 25, 2020 09:36
[polina_equ2.py] #polina
def hr():
print('--------------------------------')
def equ2(a, b, c):
d = b * b - 4 * a * c
print('D =', d)
aa = a * 2
d_sqrt = d ** 0.5
@rvasilevsk
rvasilevsk / json_rows.py
Created August 25, 2020 13:49
[json_rows.py] #python #json #json_rows #cache
#!/usr/bin/env python
import datetime
import json
#######################################################################################################################
def replace_suffix(s, suffix, replace):
"""
replace suffix if exists
@rvasilevsk
rvasilevsk / python_doctests.py
Last active August 25, 2020 15:17
[python_doctests.py] #python #doctests
#!/usr/bin/env python
def fn_none():
"""
>>> fn_none() is None
True
"""
return None