Skip to content

Instantly share code, notes, and snippets.

Korakot Chaovavanich korakot

  • VISTEC
  • Bangkok, Thailand
View GitHub Profile
@korakot
korakot / selenium.py
Created Jul 11, 2020
Using selenium in Colab
View selenium.py
# start
!pip install kora
from kora.selenium import wd
# go to
wd.get(url)
wd.current_url # now here
# show screen
def show():
from IPython.display import Image
wd.save_screenshot('im.png')
@korakot
korakot / dataprep.eda.py
Created Jul 7, 2020
Use dataprep.eda in Colab
View dataprep.eda.py
# make plot(df) works
def _report_repr_html_(self):
from bokeh.io.notebook import load_notebook
from bokeh.embed.notebook import notebook_content
load_notebook(hide_banner=True)
(script, div, cell_doc) = notebook_content(self.to_render)
return f'{div}<script>{script}</script>'
from dataprep.eda.report import Report
@korakot
korakot / ete3.py
Created Jul 6, 2020
Using ete3 in Colab
View ete3.py
import os
os.system("pip install ete3 pyqt5")
os.environ['QT_QPA_PLATFORM']='offscreen'
from ete3 import Tree
t = Tree("(A:1,(B:1,(E:1,D:1):0.5):0.5);" )
t.render("%%inline")
@korakot
korakot / arrow_size.py
Created Jul 5, 2020
Change arrow size in pyvis
View arrow_size.py
for e in net.edges:
e['arrows'] = {'to': {'scaleFactor': 0.5}}
@korakot
korakot / pip_github.py
Created Jun 30, 2020
pip install from github
View pip_github.py
!pip install git+https://github.com/org/project_name
@korakot
korakot / rename_column.py
Created Jun 30, 2020
Rename pandas column
View rename_column.py
df = df.rename(columns={'old', 'new'})
@korakot
korakot / gitlab_search.py
Created Jun 19, 2020
Search Gitlab project for notebook files
View gitlab_search.py
from requests import get
project_id = '16454639'
def gen_items(project_id, path=''):
""" List all files in this folder """
url = f'https://gitlab.com/api/v4/projects/{project_id}/repository/tree'
params = {'page': page, 'per_page': 100}
if path:
params['path'] = path
@korakot
korakot / rustup.py
Created Jun 17, 2020
Install rustup (though rust somehow doesn't work properly)
View rustup.py
!wget https://sh.rustup.rs --content-disposition
!sh rustup.sh -y
@korakot
korakot / shortcut_blob.md
Created Jun 16, 2020
Colab.fan github shortcut
View shortcut_blob.md

For a file notebook.ipynb inside a project org/project_name

It's URL is typically

github.com/org/project_name/blob/master/notebook.ipynb

The Colab URL is correspondingly

colab.research.gooble.com/github/org/project_name/blob/master/notebook.ipynb
@korakot
korakot / value_counts.py
Created Jun 16, 2020
Count frequency using value_counts(), like a Counter. Display it as a proper dataframe.
View value_counts.py
(df.word.value_counts()
.rename_axis('word')
.reset_index(name='freq')
)
You can’t perform that action at this time.