Skip to content

Instantly share code, notes, and snippets.

@mutolisp
mutolisp / count_teaching_skills.r
Created December 1, 2019 14:23
count_teaching_skills.r
library(request)
library(rvest)
library(urltools)
library(dplyr)
library(data.table)
setwd('/Volumes/GoogleDrive/My Drive/生資系系務/系所評鑑資料/參考資料/analysis/系所評鑑分析/')
grepSyllabusURL <- function(year, term, lecturer){
httr::set_config(httr::user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Safari/605.1.15"))
@mutolisp
mutolisp / proc1098.r
Last active August 30, 2019 15:59
proc1098.r
library(data.table)
# shell, split file by empty lines
system('mkdir workspace')
system('cd workspace; split -p "^$" ../1098.txt')
files <- list.files('./workspace', pattern = '^x', full.names = TRUE)
n <- floor(length(files)/5)
for ( i in 0:(n-1) ){
@mutolisp
mutolisp / r_calc_wi.r
Last active May 5, 2020 06:00
使用 R raster 來計算溫量指數
library(raster)
library(rgdal)
rasterFiles <- list.files('../temp/', pattern = '.tif',
full.names = TRUE)
rs <- raster::stack(rasterFiles)
# calculate warmth index
# 1. create an empty raster layer and fill it with zero
wi <- rs[[1, ]]*0
@mutolisp
mutolisp / rmarkdown_xetex.rmd
Created March 27, 2019 07:00
rmarkdown_xetex.rmd
---
title: "Untitled"
author: "your name"
date: "3/27/2019"
header-includes:
- \usepackage{fontspec}
- \usepackage{xeCJK}
- \setCJKmainfont{Songti TC} # change to your font names
output:
pdf_document:
@mutolisp
mutolisp / 20181228_rvest.r
Created December 28, 2018 03:12
R 爬蟲範例
# load rvest package
library(rvest)
prefix <- 'http://www.ncyu.edu.tw'
acaLawPage <- 'http://www.ncyu.edu.tw/academic/law_list.aspx?pages='
totalPageCount <- paste(acaLawPage, 0, sep = "") %>%
read_html() %>% # use read_html to read out URL
html_nodes(xpath = '//span[@id="pagecount"]') %>% # find the path of pagecount
html_text() %>% # convert it into plain text
@mutolisp
mutolisp / ncyu_aca_downloader.R
Created December 23, 2018 08:36
下載教務法規彙編爬蟲
library(rvest)
library(curl)
prefix <- 'http://www.ncyu.edu.tw'
acaLawPage <- 'http://www.ncyu.edu.tw/academic/law_list.aspx?pages='
acaLawPage1 <- read_html('http://www.ncyu.edu.tw/academic/law_list.aspx?pages=0')
# get page counts
totalPages <- acaLawPage1 %>% html_nodes(xpath = '//span[@id="pagecount"]') %>%
@mutolisp
mutolisp / ex1_5.csv
Created October 19, 2018 03:40
生態資訊學課程範例資料1
plot species individuals
DG01 印度牛膝 5
DG01 大花咸豐草 15
DG01 烏面馬 1
DG01 短穎馬唐 2
DG01 綠珊瑚 1
DG01 酢漿草 10
DG01 野莧菜 3
DG01 銀合歡 20
DG01 馬櫻丹 12
@mutolisp
mutolisp / mothurwrapper.R
Created August 8, 2018 05:07
mothur wrapper example
mothurDir <- '~/Downloads/mothur/'
fastaFile <- './1060501B_cut3_without_N.fas'
phylipFile <- paste(strsplit(fastaFile, '.fas')[1], '.phylip.dist', sep='')
listFile <- paste(strsplit(fastaFile, '.fas')[1], '.phylip.fn.list', sep='')
mothur(mothurDir, subfunc='dist.seqs',
fasta=fastaFile, calc='onegap', cutoff=0.03, countends=F, output='lt')
mothur(mothurDir, subfunc='cluster',
phylip=phylipFile,
@mutolisp
mutolisp / calcWI_tmp.sh
Created August 3, 2018 13:37
用 gdal_calc.py 計算 wi
#!/usr/bin/env sh
calcWI_tmp() {
for (( i=1; i<=12; i++ ))
do
if [ ${i} -lt 10 ] ; then
num=0${i}
else
num=${i}
fi
gdal_calc.py --format=GTiff --overwrite -A tif/tavg${num}.tif --NoDataValue=-9999 \
@mutolisp
mutolisp / gpx.fmt
Created August 1, 2018 08:54
gpx format for exiftool
# Original GPS format from https://www.sno.phy.queensu.ca/~phil/exiftool/geotag.html
#
#[HEAD]<?xml version="1.0" encoding="utf-8"?>
#[HEAD]<gpx version="1.0"
#[HEAD] creator="ExifTool $ExifToolVersion"
#[HEAD] xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
#[HEAD] xmlns="http://www.topografix.com/GPX/1/0"
#[HEAD] xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
#[HEAD]<trk>
#[HEAD]<name>航跡:2018-07-31</name>