Skip to content

Instantly share code, notes, and snippets.

View yaojenkuo's full-sized avatar

Yao-Jen Kuo yaojenkuo

View GitHub Profile
@yaojenkuo
yaojenkuo / get_github_activities.py
Last active November 29, 2017 15:37
get_github_activities
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import random
import pandas as pd
def get_github_activities(keywords):
'''
Getting search results of activities from GitHub
keywords: an iterable of the key-words to search on GitHub, e.g. ['TensorFlow', 'Pytorch']
@yaojenkuo
yaojenkuo / plotly_bar_w_dropdown.py
Created November 30, 2017 05:19
plotly_bar_w_dropdown
import plotly
plotly.offline.init_notebook_mode()
trace_rep = plotly.graph_objs.Bar(x = dl_activities.repositories, y = dl_activities.keyword, name = "Repositories", orientation = 'h', marker = dict(color = 'rgba(0, 0, 255, 1)'))
trace_commits = plotly.graph_objs.Bar(x = dl_activities.commits, y = dl_activities.keyword, name = "Commits", orientation = 'h', marker = dict(color = 'rgba(255, 165, 0, 1)'))
trace_issues = plotly.graph_objs.Bar(x = dl_activities.issues, y = dl_activities.keyword, name = "Issues", orientation = 'h', marker = dict(color = 'rgba(0, 255, 0, 1)'))
trace_wikis = plotly.graph_objs.Bar(x = dl_activities.wikis, y = dl_activities.keyword, name = "Wikis", orientation = 'h', marker = dict(color = 'rgba(255, 0, 0, 1)'))
data = [trace_rep, trace_commits, trace_issues, trace_wikis]
updatemenus = list([
dict(
@yaojenkuo
yaojenkuo / get_zipped_csv.R
Last active December 7, 2017 08:32
get_zipped_csv.R
library(RSelenium)
# Define function
get_zipped_csv <- function(x) {
for (indicator in x) {
remDr$navigate("https://data.worldbank.org/")
query_box <- remDr$findElement(using = 'css', "#selector")
# Keyboard input
query_box$sendKeysToElement(list(indicator))
Sys.sleep(5)
@yaojenkuo
yaojenkuo / get_tidy_df.R
Last active December 7, 2017 08:32
get_tidy_df.R
library(tidyr)
library(magrittr)
library(dplyr)
get_tidy_df <- function(x) {
setwd(x)
ex_dir <- paste0(x, "/world_bank_csv")
zipfiles <- c("API_NY.GDP.PCAP.CD_DS2_en_csv_v2.zip", "API_SP.DYN.LE00.IN_DS2_en_csv_v2.zip", "API_SP.POP.TOTL_DS2_en_csv_v2.zip")
for (zipfile in zipfiles) {
unzip(zipfile, exdir = ex_dir)
@yaojenkuo
yaojenkuo / ui.R
Created December 7, 2017 08:53
gapminder_replica/ui.R
region_list <- tidy_df$Region %>%
unique()
# Define UI for application that mimics a Gapminder visualization
shinyUI(fluidPage(
# Application title
titlePanel("Gapminder Replica"),
# Sidebar with a slider input for year
@yaojenkuo
yaojenkuo / server.R
Created December 7, 2017 08:56
gapminder_replica/server.R
# Define server logic required to draw a Gapminder visualization
shinyServer(function(input, output) {
tidy_data <- reactive(
tidy_df %>%
filter(Region %in% input$regions)
)
output$bubble <- renderPlotly({
# draw the bubble chart with the specified continents or year
@yaojenkuo
yaojenkuo / global.R
Created December 7, 2017 09:00
gapminder_replica/global.R
# global.R template for Plotly/Shiny apps
library(plotly)
library(shiny)
library(magrittr)
library(dplyr)
py <- plot_ly(username="rAPI", key="yu680v5eii")
tidy_df <- read.csv("data/tidy_df.csv", stringsAsFactors = FALSE)
bubble_radius <- sqrt(tidy_df$pop / pi)
@yaojenkuo
yaojenkuo / plotlyGraphWidget.R
Created December 7, 2017 09:02
gapminder_replica/plotlyGraphWidget.R
#This script is necessary in the app folder
#but the user should not have to edit it
#Output Graph Function
graphOutput <- function(inputId, width="100%", height="550px") {
tagList(
singleton(tags$head(
tags$script(src="plotlyGraphWidget.js")
)),
tags$iframe(id=inputId, src="https://plot.ly/~playground/7.embed",
@yaojenkuo
yaojenkuo / plotlyGraphWidget.js
Created December 7, 2017 09:03
gapminder_replica/www/plotlyGraphWidget.js
var binding = new Shiny.OutputBinding();
binding.find = function(scope) {
// not sure what this function does, or
// why its necessary...
console.log('binding.scope');
return $(scope).find('.graphs');
};
binding.renderValue = function(el, messages) {
@yaojenkuo
yaojenkuo / get_runner_record.py
Created December 21, 2017 12:22
taipei_marathon/get_runner_record.py
def get_runner_record(url):
driver.get(url)
odd_even_l = ['OL', 'EL']
odd_even_r = ['OR', 'ER']
runner_record = {
'bib_num': [],
'name': [],
'cate': [],
'official_time': [],
'rank_all': [],