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 / 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
@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 / 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 / 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 / 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 / digital_Circuit_Logic_Gates.scala
Created March 4, 2017 12:17
Exercise from Discrete Event Simulation Lecture of Functional Program Design In Scala course
#!/usr/bin/env scala
// for The `bash` `shell script` './script.sh'
// but App main object warper must be disabled|excluded
import scala.io.AnsiColor._
// it is imported twice in the same scope by
//import scala.Console._
//
//
/*object digital_Circuit_Logic_Gates extends App */{
/* A digital circuit is composed
@GlulkAlex
GlulkAlex / balanced_Binary_Search_Tree.js
Created March 3, 2017 13:33
An AVL tree (Georgy Adelson-Velsky and Landis' self-balancing binary search tree, named after the inventors)
"use strict";
//
var binary_Search_Tree_Name_Space = {};
//
// Done: implement `get_UnBalanced_Sub_Tree`
// recursive, but not @tail recursive | stack safe
// traversal from top to bottom
/** it must return:
- [unBalanced_Sub_Tree object, balance_Factor] if any
- or [null, 0] if not found|search fails
@GlulkAlex
GlulkAlex / binary_Tree__Build_N_Print.scala
Created February 3, 2017 14:12
binary tree creation|building|deserialization|unmarshalling, traversal, representation, serialization|marshalling
#!/usr/bin/env scala
// for The `bash` `shell script` './script.sh'
//
//import scala.math.{log, ceil}
import io.AnsiColor._
// or
//import Console.{GREEN, RED, RESET, YELLOW_B, UNDERLINED}
//
//
// ? Is something wrong with:
@GlulkAlex
GlulkAlex / hackerRank_IO_handler.scala
Created July 10, 2016 05:58
handles IO operations for hackerRank challenges in Scala
object Solution extends App{
import scala.annotation.tailrec
import scala.io.StdIn
import scala.util.{Try, Success, Failure}
import scala.math.pow//{abs, pow, ceil, floor}
// as replacement of this Java styled code
/*
@GlulkAlex
GlulkAlex / Capitalize.py
Created June 26, 2016 08:15
string Capitalization
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#utf_8 U8, UTF, utf8
"""Capitalize.py:
interactive Python sessions for doctest
must be in the `right` place
in order to be executed