Skip to content

Instantly share code, notes, and snippets.

View aluminiumgeek's full-sized avatar
🚷
🚳

Mikhail Mezyakov aluminiumgeek

🚷
🚳
View GitHub Profile
@aluminiumgeek
aluminiumgeek / number_to_georgian.py
Last active February 28, 2025 16:24
Number to Georgian (Amount/price to Georgian)
def number_to_georgian(amount, currency):
if currency == 'GEL':
main_unit = 'ლარი'
fractional_unit = 'თეთრი'
elif currency == 'USD':
main_unit = 'დოლარი'
fractional_unit = 'ცენტი'
elif currency == 'EUR':
main_unit = 'ევრო'
fractional_unit = 'ცენტი'
@aluminiumgeek
aluminiumgeek / monitor.py
Created January 30, 2020 09:09
[Python] Simple website downtime monitor (+ Pushover)
import time
from datetime import datetime
import requests
URL = 'https://example.com'
CHECK_SECONDS = 60
def monitor():
@aluminiumgeek
aluminiumgeek / utils.py
Last active February 16, 2016 18:16
This decorator caches returning value from a function/method
# I suggest you use memcached or redis as backend
import time
import json
from functools import wraps
def cached(timeout=1800):
def wrapper(f):
@wraps(f)
@aluminiumgeek
aluminiumgeek / .screenrc
Last active July 22, 2022 08:57 — forked from joaopizani/.screenrc
My .screenrc with comfortable layout and shortcuts
# the following two lines give a two-line status, with the current window highlighted
hardstatus alwayslastline
hardstatus string '%{= kG}[%{G}%H%? %1`%?%{g}][%= %{= kw}%-w%{+b yk} %n*%t%?(%u)%? %{-}%+w %=%{g}][%{B}%m/%d %{W}%C%A%{g}]'
# huge scrollback buffer
defscrollback 5000
# no welcome message
startup_message off
@aluminiumgeek
aluminiumgeek / utils.py
Last active February 16, 2016 18:14
Calculate distance between two coordinates (latitude/longitude) in meters
def coords_distance(coords_from, coords_to):
lat1, long1 = coords_from
lat2, long2 = coords_to
degrees_to_radians = math.pi / 180.0
phi1 = (90.0 - lat1) * degrees_to_radians
phi2 = (90.0 - lat2) * degrees_to_radians
theta1 = long1 * degrees_to_radians
@aluminiumgeek
aluminiumgeek / Vagrantfile
Last active June 1, 2017 11:43
Key auth for Vagrant VMs
require_relative '../vagrant/key_authorization'
Vagrant.configure('2') do |config|
config.vm.box = 'ubuntu/trusty64'
authorize_key_for_root config, '/home/mihail/.ssh/id_dsa.pub', '/home/mihail/.ssh/id_rsa.pub'
{
'db' => '192.168.33.10',
'elasticsearch'=> '192.168.33.11',
'app' => '192.168.33.12'
}.each do |short_name, ip|
@aluminiumgeek
aluminiumgeek / cinderella.txt
Last active August 29, 2015 14:14
Word counter
Cinderella
The wife of a rich man fell sick, and as she felt that her end
was drawing near, she called her only daughter to her bedside and
said, dear child, be good and pious, and then the
good God will always protect you, and I will look down on you
from heaven and be near you. Thereupon she closed her eyes and
departed. Every day the maiden went out to her mother's grave,
and wept, and she remained pious and good. When winter came
the snow spread a white sheet over the grave, and by the time the
spring sun had drawn it off again, the man had taken another wife.
@aluminiumgeek
aluminiumgeek / 125.py
Created September 8, 2014 15:37
1, 2, 5 formatter
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Форматирование словоформы "1, 2, 5" (посетитель/посетителя/посетителей)
import random
def choose_word_form(number, form1, form2, default):
mod10 = abs(number) % 10
@aluminiumgeek
aluminiumgeek / utils.py
Last active January 4, 2016 07:59
Tornado Client IP detection for production and development environments
def get_ip(request):
"""
Возвращает ip из HTTP-заголовков. Если там его нет, возвращает значение
атрибута remote_ip
@param request: экземпляр HTTPRequest
@return: строка, содержащая ip клиента
"""
if 'X-Real-Ip' in request.headers:
@aluminiumgeek
aluminiumgeek / nginx.conf
Last active September 20, 2020 12:01
Nginx forward real client ip
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://upstream_name;
}