Skip to content

Instantly share code, notes, and snippets.

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 August 14, 2018 00:49
combinations and permutations benchmark for 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 June 17, 2018 05:47
python inline profiling
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 05:37
python ctypes wctomb and mbtowc
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 April 26, 2018 03:44
LanguageHandler with custom Notification class
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 January 28, 2018 05:36
use PeekNamedPipe to check bytes available
#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 November 19, 2017 03:49
Rcpp: multidimensional integration via sourceCpp and cubature
// [[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;
@randy3k
randy3k / homebrew.mxcl.syncthing.plist
Created September 19, 2017 22:07
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>
@randy3k
randy3k / cie94.py
Created August 13, 2017 19:21
color metric
# https://gist.github.com/fikr4n/368f2f2070e0f9a15fb4
from math import sqrt
def _square(x):
return x * x
def rgb(x):
@randy3k
randy3k / open-pantheon.py
Last active June 20, 2021 08:30
open pantheon-terminal in Ubuntu nautilus
# -*- coding: UTF-8 -*-
# From https://github.com/gnunn1/tilix/blob/3f0a3d37f10f6ecfce30deca41636bb13020c2b3/data/nautilus/open-tilix.py
# Example modified for Pantheon Terminal
# Shortcuts Provider was inspired by captain nemo extension
from gettext import gettext, textdomain
from subprocess import PIPE, call
from urllib import unquote
from urlparse import urlparse