Skip to content

Instantly share code, notes, and snippets.

View scidam's full-sized avatar
💭
I may be slow to respond.

Dmitry E. Kislov scidam

💭
I may be slow to respond.
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scidam
scidam / calc.py
Created December 16, 2021 10:32
Raster calculator based on gdal's `gdal_calc` script for some environmental variables (CKI, WKI, IC, PWKI, PCKI)
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
Created Date: Saturday December 11th 2021
Author: Dmitry Kislov
E-mail: [email protected]
-----
Last Modified: Wednesday, December 15th 2021, 2:32:54 pm
Modified By: Dmitry Kislov
-----
@scidam
scidam / linkedin_checker.py
Created November 9, 2021 03:29
My solution to linkenin_checker challenge
from collections import namedtuple
import re
with open('specifications.txt', 'rt') as file:
specifications = file.read()
specs = namedtuple('specs', 'range regex')
#specs range builtin module
#specs regex from re.compile
@scidam
scidam / arg_checker.py
Created November 8, 2021 15:59
My solution (as is) to arg_checker challenge
from functools import wraps
def arg_checker(*arg_types):
'''An argument checker decorator that checks both:
- The number of variables that you use for a function
- The type of each variable.
Raises a TypeError if either of these fail'''
def wrapper(func):
@scidam
scidam / medals.py
Created November 8, 2021 15:41
My solution to Medal challenge
from collections import namedtuple
with open('olympics.txt', 'rt', encoding='utf-8') as file:
olympics = file.read()
medal = namedtuple('medal', ['City', 'Edition', 'Sport', 'Discipline', 'Athlete', 'NOC', 'Gender',
'Event', 'Event_gender', 'Medal'])
medals = [medal(*line.split(';')) for line in olympics.split('\n')[1:] if line]
@scidam
scidam / calculator.py
Created November 8, 2021 15:30
My solution to calculator with context manager
class Calculator:
def __init__(self, *excps):
self.exceptions = excps
self.error = ''
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, traceback):
@scidam
scidam / age_slowest_race.py
Created November 8, 2021 15:09
Get slowest race
# Source of data: https://www.arrs.run/
# This dataset has race times for women 10k runners from the Association of Road Racing Statisticians
# Assume a year has 365.25 days
from datetime import datetime
def prefil_globals():
global T_INDX, AT_INDX, RD_INDX, DB_INDX, LOC_INDX
with open('10k_racetimes.txt', 'rt') as file:
@scidam
scidam / pairwise_offset.py
Created November 8, 2021 12:15
Offset and fill with '*' by default
def pairwise_offset(sequence, fillvalue='*', offset=0):
sequence = list(sequence)
a = sequence + [fillvalue] * offset if offset > 0 else [fillvalue] * offset + sequence
b = [fillvalue] * offset + sequence if offset > 0 else sequence + [fillvalue] * offset
return list(map(tuple, zip(a, b)))
@scidam
scidam / average_race_time.py
Created November 8, 2021 07:06
Average race time (my solution)
# Source of data: https://www.arrs.run/
# This dataset has race times for women 10k runners from the Association of Road Racing Statisticians
import re
import datetime
def get_data():
"""Return content from the 10k_racetimes.txt file"""
with open('10k_racetimes.txt', 'rt') as file:
content = file.read()
@scidam
scidam / get_areas.py
Last active October 3, 2021 19:17
Getting area from tiffs file (SDM model)
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 7 07:07:17 2020
@author: dmitry
"""
from osgeo import gdal
import numpy as np
def get_area(filename='',maskfile='', third=None, threshold=0.8):