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
## R code test | |
library(survival) | |
data(pbc) |
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
#' 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", |
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
;;; 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)) |
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
;;; 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 |
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
## 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?" = `==`, |
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
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) |
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
;; 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] |
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
#_(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] |
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
#!/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"]]) |
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
;;; 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] |
OlderNewer