Skip to content

Instantly share code, notes, and snippets.

View BeOleg's full-sized avatar

Oleg Belousov BeOleg

View GitHub Profile
@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

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' \