Skip to content

Instantly share code, notes, and snippets.

View thirdwing's full-sized avatar
🏠
Working from home

Qiang Kou (KK) thirdwing

🏠
Working from home
View GitHub Profile
@thirdwing
thirdwing / ListBuilder.h
Created August 1, 2014 00:36
ListBuilder.h from Kevin Ushey
//
// Based on code sent by Kevin Ushey
// to Rcpp-devel on Tue, 8 Jul 2014
//
#ifndef LIST_BUILDER_H
#define LIST_BUILDER_H
#include <Rcpp.h>
using namespace Rcpp;
require(reshape2)
require(rgl)
plot_rgl_model <- function(fdata){
fdata <- fdata[order(fdata[, 1], fdata[, 2]), ]
orig_names <- colnames(fdata)
colnames(fdata) <- c("x", "y", "z")
fdata <- as.data.frame(fdata)

#mlpack on Windows

mlpack, while not designed with Windows as a specific target, can still be built and run on Windows with some configuration. This document details the steps necessary to get MLPACK compiled using MinGW64.

#Prerequisites

  • MinGW64: The compiler we use. Please add it into PATH
  • boost: This is the boost 1.56 static library compiled by myself using MinGW64. Static library is a better choice on Windows.
  • Armadillo
  • BLAS and lapack: Static BLAS and lapack library which are needed by Armadillo. Compiled using MinGW64
CFLAGS += -O3 -Wall -pipe -pedantic
CXXFLAGS += -O3 -Wall -pipe -Wno-unused -pedantic
VER=-4.8
CCACHE=ccache
CC=$(CCACHE) gcc$(VER)
CXX=$(CCACHE) g++$(VER)
SHLIB_CXXLD=g++$(VER)
FC=ccache gfortran$(VER)
F77=$(CCACHE) gfortran$(VER)
MAKE=make -j8
@thirdwing
thirdwing / ls_env.R
Created October 12, 2015 17:49
ls functions
find.funs <-function(pos = 1, ..., exclude.mcache = TRUE, mode = 'function') {
findo <- function(pos2) {
o <- named(lsall(pos = pos2, ...))
if (!length(o))
return(character(0))
# keep if exists
keep <- sapply(o, exists, where = pos2, mode = mode, inherits = FALSE)
if (!any(keep))
// boost graph serialization example
// g++ boost_graph_serialize.cpp -lboost_serialization -o test
#include <iostream>
#include <string>
#include <iostream>
#include <fstream>
#include <set>
require(RCurl)
require(XML)
webpage <- getURL("https://en.wikipedia.org/wiki/N-gram")
webpage <- readLines(tc <- textConnection(webpage)); close(tc)
pagetree <- htmlTreeParse(webpage, error=function(...){}, useInternalNodes = TRUE)
x <- xpathSApply(pagetree, "//*/p", xmlValue)
x <- unlist(strsplit(x, "\n"))
x <- gsub("\t","",x)
x <- sub("^[[:space:]]*(.*?)[[:space:]]*$", "\\1", x, perl=TRUE)
x <- x[!(x %in% c("", "|"))]
#!/bin/python
from collections import OrderedDict
def memo(f, k):
cache = OrderedDict()
def memoized(n):
if n not in cache:
cache[n] = f(n)
if len(cache) > k:
del cache[cache.keys()[0]]
@thirdwing
thirdwing / tcltk_demo.R
Created October 5, 2013 03:05
The demo for tcltk package in R
require('tcltk')
calcinp =''
mkput = function(sym){
function(...){
calcinp <<- paste(calcinp,sym,sep='')
tkconfigure(display,text=calcinp)
}
}
clearit = function(...){
@thirdwing
thirdwing / lsos.R
Last active December 30, 2015 13:39
# improved list of objects by Dirk
.ls.objects <- function (pos = 1, pattern, order.by,
decreasing=FALSE, head=FALSE, n=5) {
napply <- function(names, fn) sapply(names, function(x)
fn(get(x, pos = pos)))
names <- ls(pos = pos, pattern = pattern)
obj.class <- napply(names, function(x) as.character(class(x))[1])
obj.mode <- napply(names, mode)
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class)
obj.size <- napply(names, object.size)