Skip to content

Instantly share code, notes, and snippets.

View vlad-ds's full-sized avatar

Vlad Gheorghe vlad-ds

View GitHub Profile
@vlad-ds
vlad-ds / deploy_telegram_aws.md
Last active May 27, 2026 21:07
How to deploy a Telegram bot on AWS EC2

Remote setup (AWS EC2)

If you run your Telegram bot locally, it will stop working when you close the terminal. The alternative is to host the bot somewhere.

There are many ways to do this. I chose AWS EC2 as it's a cheap and easy option.

Create an AWS account and start an EC2 instance. Install pip, git and github cli. If you use an Amazon Linux image (which is what the free tier offers) you can run the commands in this gist.

Connect to your GitHub account with gh auth login and clone this repo. Create the .env

@vlad-ds
vlad-ds / knowledge_compound_growth.ipynb
Created June 16, 2022 19:12
knowledge_compound_growth.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
-- data for 1 day: 479 MB scanned
SELECT *
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE refresh_date = DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY);
-- data for 2 days: 955 MB scanned
SELECT *
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE refresh_date > DATE_SUB(CURRENT_DATE, INTERVAL 3 DAY);
@vlad-ds
vlad-ds / bq_query_1.sql
Created May 11, 2022 16:09
BigQuery SQL 1
SELECT term,
rank,
AVG(score) AS avg_score
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE refresh_date = DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY)
AND country_name = "United Kingdom"
GROUP BY term, rank
ORDER BY rank ASC;
@vlad-ds
vlad-ds / fizzbuzz.py
Created April 7, 2021 08:28
A Cooler Fizzbuzz
def fizzbuzz(n):
return [('' + 'Fizz' * (not x % 3) + 'Buzz' * (not x % 5)) or x for x in range(1, n+1)]
@vlad-ds
vlad-ds / SETUP_DAY.md
Created January 11, 2021 11:51
Starting my coding journey...
@vlad-ds
vlad-ds / SETUP_DAY.md
Created January 8, 2021 09:47
Starting my coding journey...
from pandas import DataFrame
def main():
path = 'input/mail.mbox'
mails = get_mails(path)
unsub_links = add_unsubscribe(mails)
df = DataFrame(unsub_links).T
df = df.sort_values(by='count', ascending=False)
df.to_csv('output.csv')
@vlad-ds
vlad-ds / unsub.py
Last active February 3, 2020 16:33
import re
def add_unsubscribe(mails: List, unsub_links: dict = {}) -> dict:
for mail in mails:
#getting sender
sender_line = mail.split('\n')[0] #first line of the mail
sender_words = sender_line.split(' ')[1:] #removes the 'From: ' part
sender = ' '.join(sender_words) #recreates the name string
if 'Q?' in sender:
sender = re.findall('.Q.?(.*?)\?', sender)[0] #removing some char coding
@vlad-ds
vlad-ds / unsub.py
Last active February 3, 2020 16:43
from typing import List
def get_mails(path: str, limit: int = None) -> List[str]:
'''Extract emails from an .mbox file.'''
mails = []
c = -1
mail = str()
with open(path, 'r', encoding = 'UTF-8') as file:
for line in file: #read every line
if c == limit: break