Skip to content

Instantly share code, notes, and snippets.

View imankulov's full-sized avatar

Roman Imankulov imankulov

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / quote.py
Created February 17, 2019 18:25
Generating documents from Google Sheets with Python
import pandas as pd
from docxtpl import DocxTemplate
SHEET_URL='https://docs.google.com/spreadsheets/d/1Kvb5bmm2qZWEH4I5hJYZMEuIBU-CCw_ivyv_jjB1w4w/export?exportFormat=csv'
TEMPLATE = 'quote.docx'
def save_quote(quote_id):
df = pd.read_csv(SHEET_URL, index_col='QuoteID')
context = dict(df.loc[quote_id])
doc = DocxTemplate(TEMPLATE)
@imankulov
imankulov / 00_stakoverflow_questions.py
Last active August 19, 2020 12:47
Analyze the percentage of the topic-specific StackOverflow questions for each programming language
#!/usr/bin/env python
"""
An ad-hoc script to analyze the percentage of the topic-specific questions for
each programming language.
For each language, the script downloads two pages and looks for the number of questions
in the title, like "NNN,NNN questions". For example, for "python" and
an extra tag "architecture", the script downloads
https://stackoverflow.com/questions/tagged/python and
https://stackoverflow.com/questions/tagged/python+architecture.
@imankulov
imankulov / cron.sh
Created December 16, 2020 15:47
A cron script to send Telegram notifications about the new menu
menu=$(curl -s 'https://www.facebook.com/SambaNaGrelha' | \
rg -o 'Bom dia estimados clientes hoje para prato do dia temos.*?Fazemos entregas ao domicílio' | \
head -n1 | html2text)
curl -s "https://api.telegram.org/bot$BOT_ID/sendMessage?chat_id=$CHAT_ID" -d text="$menu" > /dev/null