Skip to content

Instantly share code, notes, and snippets.

View CubexX's full-sized avatar
🐊
On vacation

Alexey Miroshnichenko CubexX

🐊
On vacation
View GitHub Profile
@CubexX
CubexX / plural.py
Created July 13, 2018 22:15
Python plural russian days / Склонение день/дня/дней
def plural_days(n):
days = ['день', 'дня', 'дней']
if n % 10 == 1 and n % 100 != 11:
p = 0
elif 2 <= n % 10 <= 4 and (n % 100 < 10 or n % 100 >= 20):
p = 1
else:
p = 2
modprobe zram num_devices=4
SIZE=1536
echo $(($SIZE*1024*1024)) > /sys/block/zram0/disksize
echo $(($SIZE*1024*1024)) > /sys/block/zram1/disksize
echo $(($SIZE*1024*1024)) > /sys/block/zram2/disksize
echo $(($SIZE*1024*1024)) > /sys/block/zram3/disksize
mkswap /dev/zram0
mkswap /dev/zram1
@CubexX
CubexX / login.py
Created March 10, 2018 13:28
Python flask login
CONFIG['password'] = 'PASS'
def login_required(func):
def wrapper(*args, **kwargs):
if not session or session['hash'] != generate_hash(CONFIG['password']):
return redirect('/login')
else:
return func(*args, **kwargs)
wrapper.__name__ = func.__name__
@CubexX
CubexX / today.py
Created March 2, 2018 12:12
Get today timestamp at 00:00 (start of the day)
def get_today_start():
t = datetime.today()
return int(datetime(t.year, t.month, t.day, 0).timestamp())
@CubexX
CubexX / vk.py
Created December 19, 2017 14:01
Get urls of all photo attachments from conversation
from vk_lplib import VK
# Used https://github.com/stroum/vk_lplib/
CONVERSATION_ID = 0
USER_ID = 0
TOKEN = ""
vk = VK(USER_ID, TOKEN)
start_from = 0
@CubexX
CubexX / cbr
Created April 12, 2015 17:02
php cbr
<?php
function getValute() {
$res = file_get_contents("http://www.cbr.ru/scripts/XML_daily.asp");
$values = new SimpleXMLElement($res);
$data = array();
$data["dollar"] = $values->Valute[9]->Value;
$data["euro"] = $values->Valute[10]->Value;
return $data;