Skip to content

Instantly share code, notes, and snippets.

View berkorbay's full-sized avatar
🏄

Berk Orbay berkorbay

🏄
  • Tideseed
  • Istanbul, Turkey
  • 13:53 (UTC +03:00)
View GitHub Profile
install.packages(c('tinytex', 'rmarkdown','blogdown'))
tinytex::install_tinytex()
@berkorbay
berkorbay / annoying_problems.R
Last active January 21, 2019 08:18
write this to terminal if you have LC problems
## Rule 0: strings as factors!!!
options(stringsAsFactors=FALSE)
## To avoid quaint time zone issues, set to UTC if you are working on a single timezone
Sys.setenv(TZ="UTC")
## on_sys_locale_problems
sudo defaults write org.R-project.R force.LANG en_US.UTF-8 #Mac Terminal
Sys.setlocale("LC_ALL", 'en_US.UTF-8') #Linux R Console
Sys.setlocale(locale="Turkish_Turkey.1254") #Windows
@berkorbay
berkorbay / mef_bda_503_2018_week_4.r
Last active April 3, 2019 12:20
Week 4 preparation
pti <- c("shiny","tidyverse","ggplot2movies")
pti <- pti[!(pti %in% installed.packages())]
if(length(pti)>0){
install.packages(pti)
}
##########
### Shiny starter code
##########
library(shiny)
@berkorbay
berkorbay / ibb_open_data_query_function.R
Created January 19, 2020 18:52
İBB Açık Veri Portalı'ndan veri çekme R fonksiyonu
## İlgili veri setinde önizleme'ye tıklayın çıkan url adresinde "/resource/"tan sonraki kodu kopyalayın (data_id)
ibb_data_pull <- function(data_id="e1e2b771-b4de-49d3-b779-17b4bba10fb7"){
ibb_query_url <- paste0("https://data.ibb.gov.tr/api/3/action/datastore_search_sql?sql=SELECT%20*%20from%20%22",data_id,"%22")
json_query_response <- jsonlite::fromJSON(ibb_query_url)
return_df <- json_query_response$result$records %>% rename_all(~gsub("^_","",.)) %>% rename_all(~gsub(" |\\(|\\)|/","_",.)) %>% tbl_df()
return(return_df)
@berkorbay
berkorbay / ibb_solar_panel_analysis.R
Created January 19, 2020 18:56
İBB Açık Veri Portalı İkitelli Güneş Enerjisi Santrali üretim verisi inceleme kodu
library(tidyverse)
library(lubridate)
library(jsonlite)
library(devtools)
#https://data.ibb.gov.tr/dataset/ikitelli-gunes-enerjisi-santrali-elektrik-uretim-miktarlari/resource/52afa9a3-2ea1-420b-a783-505cfe635ece
devtools::source_gist("https://gist.github.com/berkorbay/493e82b3d48245317c57a5d0c334492e")
raw_df <- ibb_data_pull("52afa9a3-2ea1-420b-a783-505cfe635ece")
wip_df <- raw_df %>% transmute(dt = as_datetime(Tarih),production=as.numeric(Uretim__kWh_))
@berkorbay
berkorbay / ibb_open_data_ispark_query.R
Created January 19, 2020 13:51
İBB Açık Veri APIsini kullanarak İSPARK lokasyonlarını bir data frame'e indirip tibble'a dönüştürme kodu
## Paketler yüklü değilse install.packages kullanın
## install.packages(c("tidyverse","jsonlite"),repos="https://cran.r-project.org")
library(tidyverse)
library(jsonlite)
ispark_query_url <- "https://data.ibb.gov.tr/api/3/action/datastore_search_sql?sql=SELECT%20*%20from%20%22c3eb0d72-1ce4-4983-a3a8-6b0b4b19fcb9%22"
raw_value <- fromJSON(ispark_query_url)
raw_df <- raw_value$result$records %>% rename_all(~gsub("^_","",.)) %>% rename_all(~gsub(" |\\(|\\)|/","_",.)) %>% tbl_df()
@berkorbay
berkorbay / parse_ys_gmail_threads.R
Last active May 24, 2020 11:58
Parses YS order emails and brings them under a single data frame
options(stringsAsFactors=FALSE)
library(tidyverse)
library(rvest)
library(gmailr)
## FOLLOW AUTH INSTRUCTIONS FROM HERE https://gmailr.r-lib.org/articles/gmailr.html
parse_order_table <-function(my_msg,full_info_list=FALSE){
my_info <- read_html(gm_body(my_msg)) %>% html_nodes(xpath="/html/body/table/tr/td/center/table[1]/tr[2]/td") %>% html_children() %>% `[[`(2)
@berkorbay
berkorbay / cognito_r_direct_query.R
Created February 17, 2021 07:35
AWS Cognito Simple Authentication with R
#######
#### This gist is a very quick way to implement just authentication function. This is a minimal example.
#### You need an AWS IAM account and your AWS Cognito User Pool set up.
#### Check the steps in the description of https://github.com/chi2labs/cognitoR
#### After creating your user pool on the left sidebar under General Settings, click on App clients
### Make sure "Enable username password based authentication (ALLOW_USER_PASSWORD_AUTH)" is checked
### Create a user from the interface for testing purposes. Let username be "usertest" and password be "passtest".
#######
#### Variables
@berkorbay
berkorbay / Dockerfile
Last active July 29, 2021 06:10
Minimal streamlit (v0.85) in Python 3.9.6 Dockerfile
FROM python:3.9.6
RUN pip install --no-cache-dir streamlit
EXPOSE 8501
ENTRYPOINT [ "streamlit" ]
CMD ["hello"]
## FOR ANY APPLICATION
ENTRYPOINT [ "streamlit", "run"]
CMD ["my_streamlit_file.py"]
@berkorbay
berkorbay / ortools_docker_run.sh
Created July 30, 2021 15:18
OR-Tools Docker OOM issue (Exit code 137)
# This is an example docker run command to run streamlit which will include an ortools model
# -m 12g will keep the memory at 12GB
# --oom-kill-disable will prevent the container to go under because of out of memory sigkill
docker run -dp 80:8501 --oom-kill-disable -m 12g <image_name>