Skip to content

Instantly share code, notes, and snippets.

View GlulkAlex's full-sized avatar
🏠
Working from home

Alex Glukhovtsev GlulkAlex

🏠
Working from home
View GitHub Profile
@GlulkAlex
GlulkAlex / test_assignment.py
Created September 9, 2017 05:30
PostgreSQL_XML_XSLT
#!/usr/bin/env python3
#!/usr/bin/python
from collections import namedtuple
import psycopg2
#from psycopg2 import sql
# note
# that we have to import the Psycopg2 extras library !
#import psycopg2.extras
from psycopg2 import extras
from psycopg2.extras import NamedTupleConnection
@GlulkAlex
GlulkAlex / LambdaTest_PF_Combo.scala
Created March 21, 2018 09:39
PartialFunction combination testing, using 47deg.github.io LambdaTest
//package ???
//import java.time.LocalDateTime
//
//import scala.language.implicitConversions
import scala.PartialFunction._
//
import akka.actor.{ Actor, ActorLogging, ActorRef, Props }
@GlulkAlex
GlulkAlex / merchants.py
Last active June 30, 2018 07:56
Game theory behaviour strategies simulation
#!/usr/bin/env python3.6
# -*- coding: utf-8 -*-
import sys
from pprint import pprint, pformat
import logging
from collections import namedtuple
import random
from random import randint
from array import array
from enum import Enum#, unique
@GlulkAlex
GlulkAlex / read_from_json.py
Created July 9, 2018 12:12
Example of web scraping with Python and PyMongo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#utf_8 U8, UTF, utf8
"""read_from_json.py:
Example:
of Python's
web scraping
@GlulkAlex
GlulkAlex / rotate_collection_clockwise.py
Last active February 1, 2023 13:34
To rotate list of items clockwise
>>> (l_s := len(l), l_r := list(reversed(l)), [(l_r[0:-l_s + i + 1][::-1], l[0:l_s - i - 1:]) for i in range(0, l_s - 1, 1)])
(5, [5, 4, 3, 2, 1], [([5], [1, 2, 3, 4]), ([4, 5], [1, 2, 3]), ([3, 4, 5], [1, 2]), ([2, 3, 4, 5], [1])])
# iteration using mod of list size
>>> [[l[5 - (r_i + i) % 5 - 1] for i in range(0, 5, 1)] for r_i in range(0, 5, 1)]
[[5, 4, 3, 2, 1], [4, 3, 2, 1, 5], [3, 2, 1, 5, 4], [2, 1, 5, 4, 3], [1, 5, 4, 3, 2]]
# counterclockwise
>>> [[l[(r_i + i) % 5] for i in range(0, 5, 1)] for r_i in range(0, 5, 1)]
[[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]]
# and clockwise