This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
n <- 500 | |
z_all <- complex( | |
re = rep(seq(-2, 0.75, len = n), times = n), | |
im = rep(seq(-1.25, 1.25, len = n), each = n)) | |
# vectorized code for just counting | |
# http://www.everydayanalytics.ca/2014/12/the-mandelbrot-set-in-r.html | |
mndl_count <- function(z0, iter_max = 100) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
make.stack <- function() { | |
val <- list() | |
list( | |
push = function(x) { | |
val <<- c(val, list(x)) | |
}, | |
pop = function() { | |
len <- length(val) | |
res <- val[len] | |
val <<- val[-len] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace TransposeArray | |
{ | |
public static class MyClass | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IEnumerable<T> lscan<T>(Func<T, T, T> f, T init, IEnumerable<T> x) | |
{ | |
return x.Any() ? new[] { init }.Concat(lscan(f, f(init, x.First()), x.Skip(1))) : new [] { init }; | |
} | |
static IEnumerable<T> lscan1<T>(Func<T, T, T> f, IEnumerable<T> xs) | |
{ | |
return lscan(f, xs.First(), xs.Skip(1)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace CsvSerializer | |
{ | |
// see also | |
// http://blog.recyclebin.jp/archives/1731 | |
// http://stackoverflow.com/questions/1179816/best-practices-for-serializing-objects-to-a-custom-string-format-for-use-in-an-o | |
// http://nine-works.blog.ocn.ne.jp/blog/2011/05/post_13ea.html | |
public interface ICsvParser | |
{ | |
object AsConvertible(string str); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# execute on 32-bit(x86) version | |
# %windir%\sysWOW64\WindowsPowerShell\v1.0\PowerShell_ISE.exe | |
# C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe | |
Get-Location | Out-Host | |
(Get-ChildItem Env:\HOMEPATH).value | |
$FileName = "hoge.accdb" | |
$ConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$FileName" | |
# create access file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get_base_fun_name <- function(x) { | |
base_funs <- as.list(baseenv(), all = TRUE) | |
for (i in seq_along(base_funs)) { | |
if(identical(x, base_funs[[i]])) return(names(base_funs[i])) | |
} | |
NULL | |
} | |
s <- substitute | |
# > get_base_fun_name(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(lazyeval) | |
# for substitute | |
curry_special <- function(fun, p_f = parent.frame()) { | |
fun_env <- environment(fun) | |
if (is.null(fun_env)) fun_env <- .GlobalEnv | |
new_env <- new.env(parent = fun_env) | |
search_fun <- function(x) { | |
base_funs <- as.list(baseenv()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
replace_symbol <- function(expr, before, after) { | |
stopifnot(is.language(expr), is.symbol(before)) | |
eval(substitute(substitute(e, `names<-`(list(after), as.character(before))), list(e = expr))) | |
} | |
pp <- function(expr_, env_ = parent.frame()) { | |
right_bin_ops <- c("%>>%", "%|>%") | |
iter <- function(x) { | |
if (length(x) <= 1) x | |
else if (length(x) == 3 && as.character(x[[1]]) %in% right_bin_ops) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fib <- function(n) { | |
if (n <= 1) n | |
else fib(n - 1) + fib(n - 2) | |
} | |
fib_rec <- function(n, a = 0, b = 1) { | |
if (n <= 1) b | |
else fib_rec(n - 1, b, a + b) | |
} |
OlderNewer