Skip to content

Instantly share code, notes, and snippets.

View Jianghao's full-sized avatar

Jianghao Wang Jianghao

View GitHub Profile
library(maps)
library(shiny)
library(stringr)
worlddf <- map("world")
# restrict selection to coutries only
locations <- worlddf$names
countries <-subset(locations,is.na(str_locate(locations,":")))
@Jianghao
Jianghao / install-ghost-theme
Created October 15, 2014 09:56
Install Perfetta-Free-Ghost-Theme
cd /srv/ghost/content/themes
rm -rf Perfetta-Free-Ghost-Theme/
git clone https://github.com/Jianghao/Perfetta-Free-Ghost-Theme.git
cd /srv/ghost/
forever restart index.js
@Jianghao
Jianghao / visual-pois
Created October 15, 2014 10:06
Visual full POIs in China
# --------------------------
# main
# --------------------------
### initial
library(plyr)
library(dplyr)
library(data.table)
setwd("~/path-to-folder/")
### Fast merge Rdata with FastMergeDF
@Jianghao
Jianghao / vis-worldclim
Created November 5, 2014 10:36
Visualize worldclim.org data
# title : 01-Visualize.R
# purpose : Visualize worldclim.org data
# reference : rasterVis package help page
# producer : Prepared by Jianghao Wang
# address : In IGSNRR, CAS, China
# ----------------------------------------------------------
library(plyr)
library(rasterVis)
library(rgdal)
@Jianghao
Jianghao / mailR
Created November 26, 2014 13:15
send email with R
# install.package("mailR")
library(mailR)
send.mail(from = "email address",
to = "email address",
subject = paste0(),
body = "",
smtp = list(host.name = "smtp.qq.com", port = 465,
user.name = "hellowangjh@qq.com", passwd = "passwd", ssl = TRUE),
authenticate = TRUE,
@Jianghao
Jianghao / mailRqq
Created March 26, 2015 12:27
send email via qq with R
if("mailR" %in% rownames(installed.packages()) == FALSE) install.packages("mailR")
library(mailR)
send.mail.qq <- function(subject, passwd, body="Hello World"){
mailR::send.mail(from = "hellowangjh@qq.com",
to = "hellowangjh@qq.com",
subject = subject,
body = body,
smtp = list(host.name = "smtp.qq.com", port = 465,
user.name = "hellowangjh@qq.com", passwd = passwd, ssl = TRUE),
authenticate = TRUE,
@Jianghao
Jianghao / hexo_config.yml
Last active August 30, 2015 12:38
_config.yml of hexo and next theme
# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Jianghao Wang
subtitle: Writing 1000 Words a Day Changes My Life
description: Walk steps step by step
author: Jianghao
# language: zh-Hans
@Jianghao
Jianghao / read_dta
Last active August 29, 2015 14:23
read stata 13 data files
setwd("D:/Cooperation/Caojing/Geocoding/")
# library(foreign)
# data <- read.dta("pollution_cen.dta")
# ## not a Stata version 5-12 .dta file
## on windows only
install.packages("haven")
require(haven)
df <- read_dta('pollution_cen.dta')
for(i in 1:ncol(df)){
library(data.table)
library(rgdal)
library(foreign)
setwd("C:/Users/Jianghao/Desktop/geocoding/")
data <- fread("geocoding.csv")
head(data)
coordinates(data) <- ~ lon + lat
proj4string(data) <- CRS("+proj=longlat +datum=WGS84")
writeOGR(obj = data, dsn = "geocoding.shp", layer = "geocoding", driver = "ESRI Shapefile")
write.dbf(dataframe = data@data, file = "geocoding.dbf")
#' Get the detail of ncdf4 file variable as a data.frame
#'
#' @param nc opened nc4 files
#' @return data.frame of variable information
#' @keywords nc attibute
#' @export
#' @examples
#' ncatt_get_df(nc)
ncatt_get_df <- function(nc, items=c("long_name", "units")){
options(stringsAsFactors=FALSE)