Skip to content

Instantly share code, notes, and snippets.

@yatsuta
yatsuta / indentr.pl
Created November 22, 2016 14:20
indent C headers for readability
$reserved = 0;
$indent = 0;
while (<>) {
if ($reserved) {
$indent++;
$reserved = 0;
}
if (/^#if/) {
@yatsuta
yatsuta / bind_c.patch
Created August 10, 2016 17:18
patch for R UTF8 problem of c function
--- bind.c.backup 2016-08-10 19:52:17.000000000 +0900
+++ bind.c 2016-08-11 01:24:41.000000000 +0900
@@ -496,6 +496,7 @@ static SEXP NewBase(SEXP base, SEXP tag)
/* This isn't strictly correct as we do not know that all the
components of the name were correctly translated. */
ans = mkCharCE(cbuf, CE_UTF8);
+ if (!ENC_KNOWN(base)) ans = mkCharCE(translateChar(ans), CE_NATIVE);
vmaxset(vmax);
}
else if (*CHAR(tag)) {
# > source("typedFunction.R")
#
# > cat(src)
# double calcPiLoop_typed() {
# int circle_in;
# int i;
# double l;
#
# circle_in = 0;
@yatsuta
yatsuta / TinyR.py
Created December 29, 2013 11:17
TinyR
from __future__ import division
from parser import read, ParseError
from util import *
from obj import *
def eval(exp, env):
global visible
visible = True
@yatsuta
yatsuta / buffertest.cpp
Created December 3, 2011 16:14
performance check for getline with various buffer sizes
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
// usage:
// time ./a.out [1G|1M|default] filename > /dev/null
void error(const char* p, const char* p2 = "")
{
@yatsuta
yatsuta / bv.py
Created August 27, 2011 23:18
source code for Tokyo.SciPy
from __future__ import division
import numpy as np
class _callableArray(np.ndarray):
def __call__(self, *arg):
return np.array([f(*arg) for f in self])
def carray(funcs):
@yatsuta
yatsuta / dicewars.R
Created August 26, 2011 08:10
DICEWARS by R
library(scatterplot3d)
p <- function(n) {
m <- matrix(0, ncol=n, nrow=n*6)
m[1:6, 1] <- 1/6
val <- function(i, j) if(i < 1) 0 else m[i,j]
for (j in 2:n) {
@yatsuta
yatsuta / gist:1047733
Created June 26, 2011 16:02
Lisp by R
opt <- options(warn=-1)
## ------------------------------------------------------------
## Test
## ------------------------------------------------------------
## > rm(list=ls()); source("Eval.R")
## > repl()
## rlisp > (<- make.counter (function (c) (function () (<<- c (+ c 1)))))
@yatsuta
yatsuta / grad.py
Created December 14, 2010 18:42
grad
from __future__ import division
def pderiv(f, i):
e = 1e-10
init_h = 0.1
def deriv_exp(arg, h):
return(f(*arg_h(arg, h)) - f(*arg)) / h
@yatsuta
yatsuta / gist:561953
Created September 2, 2010 06:27 — forked from kohta/gist:561754
f <- function(x){x**2}
fgen <- function(k){
k # for forcing arg k
return(function(x){
f(k*x)
})
}
generatedfuncs <- lapply(c(1:4),fgen)