Skip to content

Instantly share code, notes, and snippets.

@lmwang9527
lmwang9527 / gist:48386437de1574aac45cb27725f129c7
Created October 15, 2019 05:14
classInt installation error
[docker@a715cb8d440c /]$ R
> install.packages("classInt")
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/e1071_1.7-2.tar.gz'
Content type 'application/x-gzip' length 583003 bytes (569 KB)
==================================================
downloaded 569 KB
trying URL 'https://cran.cnr.berkeley.edu/src/contrib/classInt_0.4-1.tar.gz'
Content type 'application/x-gzip' length 19048 bytes (18 KB)
==================================================
"C:\Program Files\R\R-3.5.1\bin\Rscript.exe" "thisfile.R"
ECHO *** Press Any Key to Continue ***
PAUSE >NUL
## copied from https://github.com/r-lib/rprojroot/blob/master/R/thisfile.R
thisfile_rscript <- function() {
cmd_args <- commandArgs(trailingOnly = FALSE)
if (!grepl("^R(?:term|script)(?:|[.]exe)$", basename(cmd_args[[1L]]), ignore.case = TRUE)) {
return(NULL)
}
cmd_args_trailing <- commandArgs(trailingOnly = TRUE)
leading_idx <-
seq.int(from = 1, length.out = length(cmd_args) - length(cmd_args_trailing))
@lmwang9527
lmwang9527 / patchFlexTables
Created October 14, 2017 20:39
A hack by behrica to embed flextable in Rmd file in rendered Word output file
## Author: behrica
##' url{https://github.com/davidgohel/ReporteRs/issues/68}
##' Creates a docx file with the FlexTable objecta and a caption
##'
##' @param ft The FlexTable to add to the doxc file
##' @param docxFile Path of the docx file to create
##' @param caption The caption text to put above the table
##' @export
makeDocxWithFt <- function(ft,docxFile,caption) {
@lmwang9527
lmwang9527 / spatial_join.R
Last active October 16, 2018 23:16
point-polygon spatial join with R
require(rgdal)
require(sp)
#' Overlay x,y coordinate (longitude, lattitude) with a polygon shapefile (shpfile) to get polygon id (id_name)
#'
#' @param xy.df A data frame with x and y columns for longitude and lattitude.
#' @param shpfile Full path name of a polygon shapefile.
#' @param id_name Name of the polygon shapefile id attribute
#' @param xy.epsg EPSG of the x, y coordinate
#! /usr/bin/env python
"""
This module provides classes for querying Google Scholar and parsing
returned results. It currently *only* processes the first results
page. It is not a recursive crawler.
"""
# Version: 1.3 -- $Date: 2012-02-01 16:51:16 -0800 (Wed, 01 Feb 2012) $
#
# ChangeLog
# ---------
#! /usr/bin/env python
from random import randint
def random_chromosome():
return [randint(0, 1) for i in range(32)]
def calc_fitness(chromo):
return sum(chromo)
-- 1. change storage engine for existing tables
-- reference: http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html
ALTER TABLE t ENGINE = MYISAM;
ALTER TABLE t TYPE = BDB;
-- 1. median()
-- http://www.postgresonline.com/journal/archives/67-Build-Median-Aggregate-Function-in-SQL.html
CREATE OR REPLACE FUNCTION array_median(numeric[])
RETURNS numeric AS
$$
SELECT CASE WHEN array_upper($1,1) = 0 THEN null ELSE asorted[ceiling(array_upper(asorted,1)/2.0)] END
FROM (SELECT ARRAY(SELECT ($1)[n] FROM
generate_series(1, array_upper($1, 1)) AS n
WHERE ($1)[n] IS NOT NULL
ORDER BY ($1)[n]