Skip to content

Instantly share code, notes, and snippets.

View berkorbay's full-sized avatar
🏄

Berk Orbay berkorbay

🏄
  • Tideseed
  • Istanbul, Turkey
  • 22:21 (UTC +03:00)
View GitHub Profile
@berkorbay
berkorbay / read_xlsx_to_pandas_fast.py
Created August 3, 2021 18:49
Blazing fast of xlsx files into pandas
from datatable import fread
import pandas as pd
excel_path = "my_excel_file.xlsx"
df = fread(excel_path+"/sheet_name").to_pandas()
@berkorbay
berkorbay / mwe_fragment.Rmd
Created December 22, 2021 22:27
RMarkdown include an HTML fragment within an HTML fragment and how to solve <!DOCTYPE html> print problem.
---
output:
html_fragment:
self_contained: false
always_allow_html: true
---
```{=html}
<!DOCTYPE html>
```
@berkorbay
berkorbay / change_min_max_labels_shiny.R
Last active March 12, 2022 21:16
Changing the min/max labels in Shiny sliders
ui <- fluidPage(
tags$head(
#Using ionRangeSlider's javascript options you can hide/show selector labels and min/max labels
HTML("
<script>
$(document).ready(function(){
$(\".js-range-slider\").ionRangeSlider({
hide_min_max: false,
hide_from_to: true
@berkorbay
berkorbay / pandas_reorder_columns.py
Created April 18, 2022 14:37
Small function to reorder columns using Pandas. This is a quick and dirty approach. I'm pretty sure there are better alternatives.
import pandas as pd
def pd_reorder_cols(df, d):
"""
Reorders the position of columns with the given specs dictionary.
"""
cl = list(df.columns)
for k1, v1 in d.items():
k1_ix = cl.index(k1)
cl.pop(k1_ix)
@berkorbay
berkorbay / annoying_problems_python
Last active May 2, 2022 07:44
Unordered list of solutions to annoying problems with Python
## Skip failing installations on requirements.txt
## https://stackoverflow.com/a/54053100/3608936
cat requirements.txt | sed -e '/^\s*#.*$/d' -e '/^\s*$/d' | xargs -n 1 pip install
### Jupyter Notebook not working
## https://stackoverflow.com/a/59571314/3608936
python3 -m notebook
@berkorbay
berkorbay / r_highs_ompr_example.R
Created September 29, 2022 15:10
R example of modelling with HiGHS solver and ompr framework
#######
### This is a minimal example of using HiGHS solver in R with the help of ROI and ompr packages.
#######
## SETUP BEGIN
pti <- c("ompr.roi","ompr","highs","devtools")
pti <- pti[!(pti %in% installed.packages())]
if(length(pti) > 0){
install.packages(pti)
}
@berkorbay
berkorbay / os_sys_upper_directories.py
Created October 17, 2022 07:38
Getting to upper directories in Python
### This gist gives you the code snippet to reach upper directories
### so you can reach other functions in the document
### e.g. from mainfolder.subfolder.subfolder.examplefile import example_function
#### Include upper dirs start
dpath = os.path.dirname(os.path.abspath(__file__))
for i in range(4):
dpath = os.path.dirname(dpath)
sys.path.insert(1, dpath)
#### Include upper dirs end
@berkorbay
berkorbay / r_baslangic.R
Created February 8, 2019 07:44
R'a başlangıç için kurulması gereken paketler / R starter packages
## Önce aşağıdakiler linklerinden programlar indirilerek kurulmalı
# R https://cran.r-project.org/
# RStudio Desktop https://www.rstudio.com/products/rstudio/download/
# Pandoc https://pandoc.org/installing.html
# LaTeX https://www.latex-project.org/get/
# Kurulması gereken paket listesi
# Bütün kodu kopyala yapıştır ile R'a koyun Hata alınan paketler olursa bazı başka kütüphanelerin yüklenmesi gerekebilir (ör. openssl)
pti <- c("devtools","tidyverse","shiny","shinydashboard","readxl","writexl","lubridate","reticulate","stringr","openxlsx","ggiraph","rhandsontable","shinycssloaders","rmarkdown","DBI","RMySQL","shinyjs","promises","future","ggmap","rlist","anytime","xml2","jsonlite","data.table")
pti<-pti[!(pti %in% installed.packages())]
@berkorbay
berkorbay / cloud_run.md
Last active February 14, 2023 07:44
GCP (gcloud) ops cheat sheet
@berkorbay
berkorbay / relative_import.md
Created January 19, 2023 14:45
Relative import methods in Python
  1. Best way is editable pip packages (reference)

pip install --editable /path/to/package

You need to include a minimal setup.py

from setuptools import setup, find_packages

setup(