Skip to content

Instantly share code, notes, and snippets.

View imankulov's full-sized avatar

Roman Imankulov imankulov

View GitHub Profile
@imankulov
imankulov / 00_README.md
Last active December 7, 2021 06:32
aio chat client and server examples

This is a simple implementation for TCP server and client. The server listens for the port 9090 of the localhost, receives messages from any connected clients, and sends them to all connected peers. The client is started with a username as an argument, reads in an infinite loop messages from the string, re-format them as "name > message\n" and send to the server. In a different async function it also waits for message from the server and prints the to the console.

Files:

  • aio_chat_client.py: client implementation
  • aio_chat_server.py: server implementation

Dependencies: Python 3.6+ and aioconsole

Install aioconsole

@imankulov
imankulov / so_survey.ipynb
Last active June 19, 2018 10:55
Linear regresssion to explore the dependency of job satisfaction from the language used
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@imankulov
imankulov / so_survey.ipynb
Created June 16, 2018 11:16
StackOverflow survery playground
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@imankulov
imankulov / craziness.py
Created April 7, 2018 15:41
Telegram chat bot replying with random "Trump-alike" messages to anything you write
import json
import glob
import requests
import markovify
from tqdm import tqdm
TELEGRAM_TOKEN = os.environ['TELEGRAM_TOKEN']
@imankulov
imankulov / pycoffee-2018-02-28.ipynb
Last active February 25, 2018 12:25
PyCoffee 2018-02-28 (Trump tweets / Bitcoin price correlation)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@imankulov
imankulov / pycoffee.py
Last active January 24, 2018 10:13
Print the date of the next PyCoffee meetup in Porto
from dateutil.rrule import rrule, WEEKLY
from datetime import datetime as dt
r = rrule(WEEKLY, interval=2, dtstart=dt(2018, 1, 27, 10))
print(r.after(dt.utcnow()).strftime('%A, %d %B at %H%p'))
@imankulov
imankulov / babel_example.py
Last active October 4, 2017 07:29
Sample script to convert timezone names to localized city names
from babel import Locale
es = Locale('es')
pt = Locale('pt')
ru = Locale('ru')
print es.time_zones['America/New_York']['city']
print pt.time_zones['America/New_York']['city']
print ru.time_zones['America/New_York']['city']
@imankulov
imankulov / browser_utils.py
Last active May 28, 2019 08:53
A MacOS python script to run Google Chrome or Firefox instance with given timezone settings. Requires pytz
import pytz
import os
def guess_timezone(city):
"""
Take the city name and try to guess the timezone
"""
tz_map = {tz.split('/')[-1].lower(): tz for tz in pytz.all_timezones}
try:
@imankulov
imankulov / chrome_moscow.sh
Created April 5, 2017 16:00
How to run a Google Chrome under Mac OS with a different timezone
#!/bin/bash
export TZ='Europe/Moscow'
exec open -na "Google Chrome" --args "--user-data-dir=$HOME/chrome-profile"
@imankulov
imankulov / timezone.php
Created March 1, 2017 14:35
Timezone magic to find the boundaries of the day
<?
$utc = new DateTimeZone('UTC');
$user_tz = new DateTimeZone('Europe/Moscow');
// current time in UTC
date_default_timezone_set('UTC');
$datetime = new DateTime();
// convert current time to user's local time
$datetime->setTimezone($user_tz);