Skip to content

Instantly share code, notes, and snippets.

Randy Lai randy3k

Block or report user

Report or block randy3k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@randy3k
randy3k / # rstudio-server - 2019-04-22_01-41-36.txt
Created Apr 22, 2019
rstudio-server on Ubuntu 16.04.6 LTS - Homebrew build logs
View # rstudio-server - 2019-04-22_01-41-36.txt
Homebrew build logs for rstudio-server on Ubuntu 16.04.6 LTS
Build date: 2019-04-22 01:41:36
@randy3k
randy3k / pre-commit
Created Aug 30, 2018
git pre-commit which unstages eol whitespaces
View pre-commit
#!/bin/sh
git diff --ignore-space-at-eol -U0 --cached > foo.patch
git reset
git apply --ignore-whitespace --unidiff-zero --cached foo.patch
rm foo.patch
View lsprlang.py
from LSP.plugin.core.handlers import LanguageHandler
from LSP.plugin.core.settings import ClientConfig
class LspRLangPlugin(LanguageHandler):
name = "rlang"
def __init__(self):
self._config = ClientConfig(
name=self.name,
binary_args=[
View lspcqueryr.py
from LSP.plugin.core.handlers import LanguageHandler
from LSP.plugin.core.settings import ClientConfig
class LspRcppPlugin(LanguageHandler):
name = "cquery-r"
def __init__(self):
self._config = ClientConfig(
name=self.name,
@randy3k
randy3k / benchmark.R
Created Aug 14, 2018
combinations and permutations benchmark for R
View benchmark.R
## All functions from other packages will be called
## using the double colon (::) (i.e. the scope operator)
# 1.
library(RcppAlgos)
library(arrangements)
library(microbenchmark)
options(digits = 4)
@randy3k
randy3k / profile.py
Created Jun 17, 2018
python inline profiling
View profile.py
import cProfile, pstats
pr = cProfile.Profile()
pr.enable()
pr.disable()
ps = pstats.Stats(pr).sort_stats('time')
ps.print_stats(10)
@randy3k
randy3k / wc.py
Created May 18, 2018
python ctypes wctomb and mbtowc
View wc.py
import rapi
rapi.start()
# let R to set the locale
import ctypes
from ctypes import wintypes
MultiByteToWideChar = ctypes.windll.kernel32.MultiByteToWideChar
MultiByteToWideChar.argtypes = [wintypes.UINT, wintypes.DWORD,
wintypes.LPCSTR, ctypes.c_int,
@randy3k
randy3k / plugin.py
Last active Apr 26, 2018
LanguageHandler with custom Notification class
View plugin.py
from LSP.plugin.core.handlers import LanguageHandler
from LSP.plugin.core.settings import ClientConfig
from LSP.plugin.core.rpc import Notification
import os
class LspClangRcppPlugin(LanguageHandler):
name = "clangd-rcpp"
@randy3k
randy3k / nb_available.c
Created Jan 28, 2018
use PeekNamedPipe to check bytes available
View nb_available.c
#include <windows.h>
#include <stdio.h>
#include <stdbool.h>
#define BUFSIZE 1024
int main(int ac, char** av) {
HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
DWORD rd;
@randy3k
randy3k / cubature.cpp
Created Nov 19, 2017
Rcpp: multidimensional integration via sourceCpp and cubature
View cubature.cpp
// [[Rcpp::depends(cubature)]]
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
#include <exp_cubature.h>
using namespace Rcpp;
const double log2pi = std::log(2.0 * M_PI);
arma::vec mu;
You can’t perform that action at this time.