Skip to content

Instantly share code, notes, and snippets.

View BeOleg's full-sized avatar

Oleg Belousov BeOleg

View GitHub Profile
@BeOleg
BeOleg / soduku.py
Created October 29, 2019 20:14
A simple Soduku validator class. part of the entry exam for Rocket Internet SE in the Berlin head-office (or at least used-to-be)
class SodukuValidator:
def __init__(self, size, input):
self.size = size
self.outer_size = self.size * self.size
self.solution = []
inner_idx = 0
for i in range(0, self.outer_size):
self.solution.append([])
for j in range(0, self.outer_size):
self.solution[i].append(input[inner_idx])
#!/bin/bash
RUNNING_CONTAINER=$(docker ps -q --filter "ancestor=$BOX_NAME" --filter name="wercker-pipeline-" --filter status=running)
function use_running_container {
coverage_cmd="coverage erase"
coverage_cmd="${coverage_cmd} && coverage run --source='.' manage.py test -v 3 --pattern='test_*.py'"
coverage_cmd="${coverage_cmd} && coverage report "
coverage_cmd="${coverage_cmd} && coverage html -d cover"
@BeOleg
BeOleg / wercker.yml
Created December 22, 2016 16:13
Example wercker file for django+postgres+redis
@pitervergara @BeOleg @Xpktro
RawBlameHistory
289 lines (279 sloc) 10.1 KB
box: pitervergara/geodjango:photobasa
services:
# TODO:
# This service will be used in production too.
# It's better to move this block into the "dev" pipeline
# so it aplies only there. Than set the posgtgres
# 1. Create a Python function that gets an integer between 1 - 12 (as an hour) and returns the exact time in hours
# and minutes at which the hands of the clock overlap at this hour
# (for example, for 1, the result will be close to 1:06)
# 2. create a unit test for this function, using 'assert', or the Python 'unittest' framework
# 3. [BONUS]
# a. add also seconds calculation to the return value of the function.
# b. calculate the angle of the hands in 360 degrees system
# taking 12:00 (noon, midnight) as a point of reference
# ATTENTION: You do not need to import any modules to implement this task
@BeOleg
BeOleg / comprehensions.md
Created March 27, 2016 18:21 — forked from bearfrieze/comprehensions.md
Comprehensions in Python the Jedi way

Comprehensions in Python the Jedi way

Beautiful is better than ugly. Explicit is better than implicit.

-- The Zen of Python

I frequently deal with collections of things in the programs I write. Collections of droids, jedis, planets, lightsabers, starfighters, etc. When programming in Python, these collections of things are usually represented as lists, sets and dictionaries. Oftentimes, what I want to do with collections is to transform them in various ways. Comprehensions is a powerful syntax for doing just that. I use them extensively, and it's one of the things that keep me coming back to Python. Let me show you a few examples of the incredible usefulness of comprehensions.

All of the tasks presented in the examples can be accomplished with the extensive standard library available in Python. These solutions would arguably be more terse and efficient in some cases. I don't have anything against the standard library. To me there is a certain

# 1. Create a Python function that gets an integer between 1 - 12 (as an hour) and returns the exact time in hours
# and minutes at which the hands of the clock overlap at this hour
# (for example, for 1, the result will be close to 1:06)
# 2. create a unit test for this function, using 'assert', or the Python 'unittest' framework
# 3. [BONUS]
# a. add also seconds calculation to the return value of the function.
# b. calculate the angle of the hands in 360 degrees system
# taking 12:00 (noon, midnight) as a point of reference
# ATTENTION: You do not need to import any modules to implement this task

Installing Python 3 compatible Fabric

Unfortunately, Fabric has not yet officilly been ported to Python 3. However, it is possible to get it to work. Here is how I did it.

First, create a virtual environment to run fabric in. (If you haven't set up virtual environments for Python, go ahead and do that now, then come back.) I have the [fink environment] (http://finkproject.org) installed on my Mac, and

@BeOleg
BeOleg / CopyAsanaTasks.php
Created February 14, 2016 12:47 — forked from mhdhejazi/CopyAsanaTasks.php
Copy/Move project to a new workspace in Asana
function asanaRequest($methodPath, $httpMethod = 'GET', $body = null)
{
$apiKey = 'ASANA_API_KEY_HERE'; /// Get it from http://app.asana.com/-/account_api
$url = "https://app.asana.com/api/1.0/$methodPath";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@BeOleg
BeOleg / test_suduko.py
Created February 12, 2016 15:47
test suite for suduko.py
import unittest
from suduko import SodukuValidator
class TestSodukuValidator(unittest.TestCase):
def test_validate_rows_return_true_when_rows_not_contains_duplicates(self):
test_input = '182543697' \
'965178342' \
'743962815' \
'374896521' \