Skip to content

Instantly share code, notes, and snippets.

@ViktorovEugene
ViktorovEugene / temp_dir.py
Created February 2, 2016 13:00
Work with temporary files. Python 2.
from __future__ import print_function
import os.path
import tempfile
import shutil
import file_encryptor
def func(source_file):
source_file_name = source_file.name
@ViktorovEugene
ViktorovEugene / mock_open.py
Last active July 4, 2021 11:55
mocking of builtins (python2/3)
"""
This is the example of mocking the builtin `open` function in python 2/3.
"""
from __future__ import print_function
import sys
import unittest
if sys.version_info.major == 3:
from unittest import mock
else:
@ViktorovEugene
ViktorovEugene / temp_file.py
Last active February 18, 2016 15:28
Test module with examples and pitfails of using temporary files from ``tempfile`` standart library module.
"""
Study python3's ``tempfile`` library.
"""
from __future__ import print_function
import os
import tempfile
import unittest
import sys
import subprocess
@ViktorovEugene
ViktorovEugene / days_counter.html
Last active March 22, 2016 13:23
JS - get the day's number since the 0001-01-01 and conversely - get the date object by the day's number.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Date</title>
</head>
<body>
<script>
console.log('\nFrom date to ordinal:\n');
@ViktorovEugene
ViktorovEugene / this_decode.py
Last active April 25, 2016 18:12
The challenge of decryption the "this.s"
from __future__ import print_function
import this
print('\n-------------------------\n'
'DECRYPTION OF the this.s:'
'\n-------------------------\n')
def decrypt(s, d):
@ViktorovEugene
ViktorovEugene / gevent_learn.py
Last active April 29, 2016 14:12
Councurent execution with dalay
"""
Will not fail until the `value` in gevent.sleep(<value>) will be more than
timeout value.
"""
from __future__ import print_function
import time
import gevent
from gevent import Timeout
seconds = 1
@ViktorovEugene
ViktorovEugene / tools.py
Created May 17, 2016 12:47
Structure inserted dict
import datetime
import random
import json
def get_rand_dates_list(amount):
return [
datetime.datetime(random.randint(2010, 2016), random.randint(1, 12), 1)
for i in range(amount)]
@ViktorovEugene
ViktorovEugene / vertical_align.html
Created September 22, 2016 17:34
Vertical centering with `vertical-align: middle;`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
font-size: 16px;
margin: 0;
}
@ViktorovEugene
ViktorovEugene / test.html
Created September 29, 2016 18:50
Make up the row of responsive blocks with spacing. These blocks have an equal width and spaces between each other, but at the same time are glued to the boundary of the outer container.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body {
background-color: #585858;
}
.outer-wrapper {
@ViktorovEugene
ViktorovEugene / list_ironing.py
Created November 8, 2016 18:29
Utility function that accepts list with nested structure and returns flat list.
def flatten_list(list_to_flatten):
flat_list = []
for item in list_to_flatten:
if type(item) != list:
flat_list.append(item)
else:
flat_list += flatten_list(item)
return flat_list