Skip to content

Instantly share code, notes, and snippets.

View wush978's full-sized avatar
👶
Working with my baby

Wush Wu wush978

👶
Working with my baby
View GitHub Profile
@wush978
wush978 / check.sh
Created November 22, 2012 15:01
check script for R package
#!/bin/bash
# Program:
# Check Folder $1 with R
./roxygenize.R $1
rm -rf check
mkdir check
cp -r -H $1 check
cd check
find . -name .git -type d | xargs rm -rf
R CMD check --no-codoc --no-manual --no-examples --no-vignettes --no-rebuild-vignettes --check-subdirs=no --install-args=-d --install-args=--no-docs --install-args=--no-html --install-args=--no-help --install-args=--no-demo --install-args=--no-multiarch $1
@wush978
wush978 / install.sh
Created November 22, 2012 15:02
shell script for install R package
#!/bin/bash
# Program:
# Check Folder $1 with R
./roxygenize.R $1
rm -rf install
mkdir install
cp -r -H $1 install
cd install
find . -name .git -type d | xargs rm -rf
R CMD INSTALL $1
@wush978
wush978 / hex2str.R
Created December 3, 2012 07:08
hex to string in R
if (require(inline) && require(Rcpp)) {
hex2str <- cxxfunction(sig=c(Rinput="character"), plugin="Rcpp", body='
int hex2bintab[] = {
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
@wush978
wush978 / remove_unicode_escape.R
Created December 3, 2012 07:32
remove unicode escape
source("hex2str.R")
remove_unicode_escape <- function(src) {
start.set <- gregexpr("\\\\u[0-9a-fA-F]{4,4}", src, perl=FALSE, useBytes=TRUE)[[1]]
sub.list <- list()
for(start in start.set[length(start.set):1]) {
if (!is.null(sub.list[[substring(src, start, start+5)]])) next
pattern <- substring(src, first=start, last=start + 5)
hex <- substring(pattern, 3, 6)
result <- iconv(hex2str(hex), "UTF16BE", "UTF8")
cat(paste(hex, "-->", result, "\n"))
@wush978
wush978 / Rmd2md.R
Created December 4, 2012 06:50
Convert Rmd 2 md with knitr
argv <- commandArgs(TRUE)
if (!length(argv)) {
cat("Convert Rmd to md\n")
cat("Usage: <input> <output>\n")
quit("no")
}
if (!require(knitr)) {
stop("knitr is required")
}
opts_knit$set(upload.fun = image_uri, animation.fun = hook_r2swf)
# * 結構說明
#
# 群組
# 規則名稱
# Regex 字串
# 關鍵字跟位置的對應表
#
# match_any is a special string for resuing regex
---
_alias:
@wush978
wush978 / xts.inline.R
Created December 8, 2012 16:44
Demo of xts API with inline
library(xts)
data(sample_matrix)
x <- as.xts(sample_matrix)
library(inline)
library(Rcpp)
f <- cfunction(sig=c(Rxts="Rxts"), Rcpp=TRUE,
includes='
extern "C" {
#define class xts_class
@wush978
wush978 / normalize_xts.fun.R
Created December 8, 2012 17:18
Normalization of xts
library(xts)
library(inline)
library(Rcpp)
#' normalization
#'
#' This function will normalize the input \code{Rxts}.
#'
#' @param Rxts xts object which will be normalize
#' @return NULL
@wush978
wush978 / add_user.php
Created December 29, 2012 05:12
add ldap user Usage: ```sh php add_user.php <uid> <first-name> <last-name> <e-mail> <phone> ```
<?php
if (count($argv) != 6) {
echo "Usage: add_user.php <uid> <first-name> <last-name> <e-mail> <phone>\n";
exit(1);
}
$current_uid = shell_exec("ldapsearch -x -LLL -b dc=iis,dc=sinica,dc=edu,dc=tw 'uidNumber<=65534' uidNumber");
preg_match_all("/uidNumber.\\s(?P<uid_number>\\d+)/", $current_uid, $matches);
\documentclass[$if(fontsize)$$fontsize$,$endif$]{$documentclass$}
\usepackage{fontspec}
\setromanfont{WenQuanYi Micro Hei} %
\XeTeXlinebreaklocale "zh"
\XeTeXlinebreakskip = 0pt plus 1pt
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\ifxetex
\usepackage{fontspec,xltxtra,xunicode}
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}