Skip to content

Instantly share code, notes, and snippets.

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;
View homebrew.mxcl.syncthing.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.syncthing</string>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key>
<string>/Users/Randy</string>
View cie94.py
# https://gist.github.com/fikr4n/368f2f2070e0f9a15fb4
from math import sqrt
def _square(x):
return x * x
def rgb(x):