Skip to content

Instantly share code, notes, and snippets.

View gandroz's full-sized avatar

Guillaume Androz gandroz

View GitHub Profile
@gandroz
gandroz / ip_sender.py
Created March 14, 2021 20:57
IP sender script
import pickle
import os.path
import requests
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from email.mime.text import MIMEText
import base64
# If modifying these scopes, delete the file token.pickle.
@gandroz
gandroz / playing_q_table.py
Created March 14, 2021 02:24
Playing with the learnt Q-table
# Reset environment
state = env.reset()
# Render it
env.render()
time.sleep(0.5)
done = False
while not done:
# Choose the action with the max expected reward i.e. max Q-value
@gandroz
gandroz / q_learning.py
Created March 14, 2021 02:20
Q Learning implementation
import numpy as np
import gym
# Define the environment
env = gym.make("Taxi-v2").env
# Initialize the q-table with zero values
q_table = np.zeros([env.observation_space.n, env.action_space.n])
@gandroz
gandroz / to_north.py
Created March 13, 2021 21:59
go to the north
env.step(1)
@gandroz
gandroz / taxi_rendering.py
Created March 13, 2021 21:42
gym taxi rendering
import gym
env = gym.make("Taxi-v3").env
env.render()
@gandroz
gandroz / popular_tags_res.py
Created July 4, 2020 02:45
Result of the most popular tags
@gandroz
gandroz / popular_post_tag_scarping.py
Created July 4, 2020 02:40
Scrap the tag and number of claps of popular articles on medium
from bs4 import BeautifulSoup
import requests
def convert_to_num(s):
if isinstance(s, int):
return s
elif 'K' in s:
return int(1000 * float(s.replace('K','')))
else:
@gandroz
gandroz / popular_posts_scraping.py
Created July 4, 2020 02:33
Scrap popular posts
@gandroz
gandroz / graphql_first_query.py
Last active November 23, 2021 00:46
graphql client query
from python_graphql_client import GraphqlClient
client = GraphqlClient(endpoint="https://medium.com/_/graphql")
query = "query TopicHandler($topicSlug: ID!, $feedPagingOptions: PagingOptions, $sidebarPagingOptions: PagingOptions) {\n topic(slug: $topicSlug) {\n canonicalSlug\n ...TopicScreen_topic\n __typename\n }\n}\n\nfragment PostListingItemFeed_postPreview on PostPreview {\n post {\n ...PostListingItemPreview_post\n ...PostListingItemByline_post\n ...PostListingItemImage_post\n ...PostPresentationTracker_post\n __typename\n }\n __typename\n}\n\nfragment PostListingItemPreview_post on Post {\n id\n mediumUrl\n title\n previewContent {\n subtitle\n isFullContent\n __typename\n }\n isPublished\n creator {\n id\n __typename\n }\n __typename\n}\n\nfragment PostListingItemByline_post on Post {\n id\n creator {\n id\n username\n name\n __typename\n }\n isLocked\n readingTime\n ...BookmarkButton_post\n firstPublishedAt\n updatedAt\n status
@gandroz
gandroz / ridge_regression.py
Last active May 24, 2020 01:37
Ridge regression
def ridge_regression(data, predictors, alpha=None):
# Fit the model
if alpha is not None and predictors is not None:
model = Ridge(alpha=alpha, normalize=True, max_iter=1e8)
else:
model = RidgeCV(alphas=np.linspace(1e-4, 1e-3, 1000), fit_intercept=True, normalize=True)
model.fit(data[predictors],data['y'])
y_pred = model.predict(data[predictors])