Skip to content

Instantly share code, notes, and snippets.

View tmasjc's full-sized avatar
Strange Loop

Thomas Jc tmasjc

Strange Loop
  • Dumpling City
  • 04:00 (UTC +08:00)
View GitHub Profile
@tmasjc
tmasjc / reactiveVal.R
Last active January 24, 2018 09:27
Reactive value in Shiny #shiny
library(shiny)
ui <- fluidPage(
column(12,
# toggle between normal or uniform distribution
actionButton("rnorm", "Normal"),
actionButton("runif", "Uniform")
),
column(12,
plotOutput("plot")
@tmasjc
tmasjc / gcv_http.R
Last active January 24, 2018 13:24
A Simple Post Request to Google Cloud Vision API in R #rstats #google
#-- BASED ON https://cloud.google.com/vision/docs/request#json_request_format --#
# image url on Google Cloud Storage
imgURI <- "gs://vacation_room/dublin-001.jpg"
# Requests are POST requests to
endpoint <- "https://vision.googleapis.com/v1/images:annotate"
#### remember to set api token in ``options``
# options(gcv_api_token = "YOUR_API_TOKEN")
@tmasjc
tmasjc / repo_overview
Last active January 26, 2018 06:02
Common git commands put into a script to give an repo overview. #git #bash
#!/bin/bash
# Header
echo `date`
if [ -d .git ];then
echo -e "\n\033[0;42m **** Current Status ****\033[0m\n"
git status -s
echo -e "\n\033[0;43m **** Pending Issue ****\033[0m\n"
@tmasjc
tmasjc / awsFunctions
Created January 29, 2018 10:18
Simple shortcut to replace common AWS commands.
#!/bin/bash
function _awsSwitchProfile() {
# Check if argument exists
if [ -z $1 ]; then echo "Usage: _awsSwitchProfile <profilename>"; return; fi
# Check if profile exists
exists="$(aws configure get aws_access_key_id --profile $1)"
@tmasjc
tmasjc / unwto.R
Created February 2, 2018 13:27
Explore chinese outbound tourism data from UNWTO. #rstats #unwto
# China Outbound Tourism
library(readxl)
library(tidyr)
library(ggplot2)
library(broom)
# read data
cot <- read_excel("~/Downloads/outbound_tourism_china.xlsx", skip = 5)
# mod columns name
colnames(cot) <- c("country", "series", 1995:2016, "pct_chg_16_15")
@tmasjc
tmasjc / rename_files
Created February 8, 2018 05:05
Rename multiple files at once using regex. #bash
#!/usr/bin/env Rscript --vanilla
args <- commandArgs(trailingOnly = TRUE)
# List all files
items <- list.files(path = ".")
# See which matches argument (regex)
old <- items[grep(items, pattern = args[1])]
@tmasjc
tmasjc / cot_animate.R
Created February 8, 2018 12:02
Animate foreign exchange rate x outbound Chinese tourisism. #rstats #plotly
library(readxl)
library(tidyr)
library(ggplot2)
library(broom)
library(rvest)
library(plotly)
# Import data -------------------------------------------------------------
@tmasjc
tmasjc / openaq.R
Created February 11, 2018 09:18
Get data from OpenAq api. #rstats #httr
library(httr)
library(dplyr)
# Find out which cities are being covered in China
china <- "https://api.openaq.org/v1/cities?country=CN"
china_df <- GET(china) %>% content("parsed") %>% `[[`('results') %>% bind_rows()
# Main interest
cities <- c("Beijing", "Shanghai", "Guangzhou")
china_df %>% filter(city %in% cities)
@tmasjc
tmasjc / gdp_edu_cor.R
Last active February 13, 2018 10:01
Visualize GDP per capita ~ enrolment in sec education pct. #rstats #wdi #econs
# Mon Feb 12 16:48:40 2018 ------------------------------
library(tidyverse)
library(wbstats)
set.seed(1234)
# GDP per capita
gdp <- wb(indicator = "NY.GDP.PCAP.CD") %>% as.tibble()
skimr::skim(gdp)
@tmasjc
tmasjc / repo_struc.md
Created April 13, 2018 04:47
Standard repository structure and style.

Checklist

-	Does the project contain R script?
-	Does the project contain data?
-	Does the project contain a test script?
-	Do the scripts contain proper comments?
-	Is the project organised in proper structure? 
-	Do the scripts follow R style guide?
		http://style.tidyverse.org/
-	Does the README display the project structure?