Skip to content

Instantly share code, notes, and snippets.

View kaz-yos's full-sized avatar
💭
I may be slow to respond.

Kazuki Yoshida kaz-yos

💭
I may be slow to respond.
View GitHub Profile
@kaz-yos
kaz-yos / test.R
Last active August 29, 2015 13:57
test
## R code test
library(survival)
data(pbc)
#' R implementation of `cond` from Lisp
#' allows for arbitrary numbers of conditionals without ugly nested if statements
#' conditionals are entered as pairs of expressions (clauses),
#' first the expression to be evaluated and second the return value if the expression is true
#' @param ... an even number of expressions as pairs (see example)
#' @param true the `else` expression (Taken from the Lisp (T resultN) see http://www.cis.upenn.edu/~matuszek/LispText/lisp-cond.html)
#' @return The paired value of the first true conditional expression or the value of true
#' @examples
#' x <- runif(1)
#' cond(x < 0.2, "lower tail",
@kaz-yos
kaz-yos / emacsclient.el
Created September 24, 2014 16:52
Solution for "Buffer named *helm* not found" issue on invoking emacsclient
;;; Handle *helm* buffer not found issue 2014-09-24
;; It is caused by helm--maybe-update-keymap remaining in post-command-hook.
;; helm--maybe-update-keymap requires *helm* to be present.
;; It should be remove-hook'ed, but it does not happen when doing *.Rnw editing.
;; The main problem is emacsclient hits this error and die.
;; Magit uses emacsclient for COMMIT messages, so it does not work.
;;
;; Define a function to remove helm--maybe-update-keymap from post-command-hook
(defun remove-helm--maybe-update-keymap ()
(remove-hook 'post-command-hook 'helm--maybe-update-keymap))
;;; Twelve boxes question
;; https://global-math.com/pr/quiz/6
;; Twelve boxes with numbers exist.
;; All neighboring 4 sum to 50.
;; What goes into the 6th box?
;; |15| |10| | |? | | | | | |20|
;;; Define condition checkers
;; sum checker skeleton
@kaz-yos
kaz-yos / lispr.R
Last active August 29, 2015 14:12 — forked from igjit/lispr.R
## Scheme Interpreter in R
## (more R-ish implementation of "lisp.R")
addGlobals <- function(env) {
procs <- list("+" = sum,
"*" = prod,
"-" = function(...) Reduce(`-`, list(...)),
"/" = function(...) Reduce(`/`, list(...)),
"=" = `==`,
"eq?" = `==`,
@kaz-yos
kaz-yos / file0.txt
Last active August 29, 2015 14:12
eval-in-repl.el: Consistent ESS-like eval interface for various REPLs in Emacs ref: http://qiita.com/kaz-yos/items/bb8016ec79cfbbf328df
eval-in-repl-ielm.el for Emacs Lisp (via ielm)
eval-in-repl-cider.el for Clojure (via cider.el)
eval-in-repl-slime.el for SLIME (via slime.el)
eval-in-repl-geiser.el for Racket/Scheme (via geiser.el)
eval-in-repl-racket.el for Racket (via racket-mode.el)
eval-in-repl-scheme.el for Scheme (via scheme.el and cmuscheme.el)
eval-in-repl-python.el for Python (via python.el)
eval-in-repl-shell.el for Shell (via essh.el)
eval-in-repl-sml.el for Standard ML (via sml-mode.el and ess.el)
eval-in-repl-ruby.el for Ruby (via ruby-mode.el, inf-ruby.el, and ess.el)
@kaz-yos
kaz-yos / happy-new-year-2015.clj
Last active August 29, 2015 14:12
Happy New Year 2015
;; https://sites.google.com/site/unclebobconsultingllc/home/articles/clojure-prime-factors
(defn factors [n]
(let [candidates (range 1 (inc n))]
(filter #(zero? (rem n %)) candidates)))
(defn prime? [n]
(or (= n 2)
(= 2 (count (take 3 (factors n))))))
(defn prime-factors [n]
#_(defdeps ;; Need to be at line 1
[[org.clojure/clojure "1.6.0"]
[bigml/sampling "3.0"]])
;; lein oneoff script.clj to run
;; https://github.com/mtyaka/lein-oneoff
;; Namespace
(ns oneoff
(:require [clojure.string :as cstr]
[clojure.set :as cset]
#!/usr/bin/env lein-exec
;; Can run as a shell script if proper configurations have been done
;; https://github.com/kumarshantanu/lein-exec#executable-scripts
;;; Getting dependencies from within script
;; https://github.com/kumarshantanu/lein-exec#getting-dependencies-from-within-script
;; Usually run by lein exec script.clj
(use '[leiningen.exec :only (deps)])
(deps '[[org.clojure/clojure "1.6.0"]
[bigml/sampling "3.0"]])
@kaz-yos
kaz-yos / pi.clj
Created March 13, 2015 17:09
Pi Day
;;; pi calculation in Clojure
(defn square
"Square a number"
[n]
(* n n))
(defn seq-of-numerators
"Sequence of numerators up to n-th element"
[n]