Clojure

Leiningen

Download ~/bin/lein.bat and run to setup. lein.bat has a variable to indicate the version being used. This can be changed to up/downgrade. Keep old versions of clojure should an upgrade break things.

~/.m2 contains the repository.

cd into the project directory and $lein deps to install/upgrade dependencies.

run lein clean occasionally
lein clean - delete build artifacts
lein deps - download dependencies, including clojure
lein javac - compile java code in project

Clojure

Clojure-mode

Cider

Open core.clj
C-c M-j to cider-jack-in; repl prompt is XXX.core>

C-c C-e to evaluate an expression.

M-x occur ‘defn’ will open a new buffer with all method definitions listed. Click on one to go to it.

M-x imenu enter a regex to search method names with, code completion available.

Init.el

(require ‘cider)

;;from: http://blog.jenkster.com/2013/12/a-cider-excursion.html

(defun cider-namespace-refresh ()
(interactive)
(cider-interactive-eval
“(require ‘clojure.tools.namespace.repl)
(clojure.tools.namespace.repl/refresh)”))

;;also see http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded

(define-key clojure-mode-map (kbd “M-r”) ‘cider-namespace-refresh)

Miscellaneous

Clojure integration with R

Share

SQLite

Download and unzip SQLITE into a directory. I used c:\program files\sqlite3. This path will need to be referred to as c:\progra~1\sqlite3 in your lisp code and any batch files. Be sure to also download the associated executable file, which provides about 27 “dot” utility commands. Test that the systems works by creating a table and populating with data. To get started, create a batch file that starts SQLITE with the database name of interest, which is passed to the executable as a parameter. To create the database named “mydb”, the contents of sqlite.bat would be:

1
c:\progra~1\sqlite\sqlite3.exe mydb

At the sqlite prompt both dot and SQL commands can be submitted. To retain a record of the commands used to create your database, place them in a plain text file and then use the .read command to read that file into SQLITE. Here are the contents of my “create-tables.txt” file:

1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE ab ( 
ab_id INTEGER PRIMARY KEY AUTOINCREMENT,
names varchar(20),
antigen_species char(20),
host char(20),
supplier varchar(20),
catnum varchar(20),
isotype char(20),
specificity varchar(20),
application varchar(20),
epitope varchar(20));

To execute, read in create-tables.txt at the sqlite prompt:

1
sqlite> .read "create-tables.txt"

You can check that the table was created with the .schema command. Next insert a value. Either type it directly at the sqlite prompt, or read it from a file.

1
INSERT INTO ab VALUES ( NULL,'Tau 46', 'human', 'mouse', 'Santa Cruz', 'sc-32274', 'IgG1', 'hu;mu;rat', 'western;ip;if','unknown');

And query it out:

1
sqlite> SELECT * FROM ab;

If you retrieve your row, you are all set to move on. Note that the assigned value of ab_id is NULL. Let the database assign the autoincrement field.

init.el

;;__________________________________________________________________________
;;;; Programming - SQLite

(add-hook ‘sql-mode-hook
‘(lambda ()
(interactive)
(sql-set-product ‘sqlite)
(sql-product-interactive sql-product)
;;(sql-connect-preset ‘pool-a))
(define-key sql-mode-map [f5] ‘sql-send-region)
(define-key sql-mode-map [f4] ‘sql-send-buffer)))

;;(add-hook ‘sql-interactive-mode-hook
;; )

;;(add-hook ‘sql-set-sqli-hook
;;Hook for reacting to changes of sql-buffer
;; (setq sql-database “~/owncloud/misc/pm/pm.sqlite”)
;; )

(setq sql-connection-alist
‘((pool-a
(sql-product ‘sqlite)
(sql-server “1.2.3.4”)
(sql-user “me”)
(sql-password “mypassword”)
(sql-database “~/syncd/prog/plate-manager/pm.sqlite”))))

(defun sql-connect-preset (name)
“Connect to a predefined SQL connection listed in sql-connection-alist'" (eval (let ,(cdr (assoc name sql-connection-alist))
(flet ((sql-get-login (&rest what)))
(sql-product-interactive sql-product)))))

;; (add-hook ‘sql-interactive-mode-hook ‘my-sql-save-history-hook)

Share

sex

Men prefer debt-free virgins without tattoos

Explicates the problems of women going to college. “…Universities are definitely not safe places for women!…”

Interest in sex declining

Share

Woelcke Autark T5 Crosser Off Road

800 mile range
50 gallons water
Locking differential
~$3000 to ship to Halifax
7.5 foot width
Can navigate through 3 feet of water

Share

rethinkDB

This post will describe installation and interaction with rethinkDB using Javascript/Node.js. Ultimately I want to hook rethinkDB to Shiny. I am working on Debian/Jessie. Currently (August, 2017) rethinkDB will not install on Stretch.

Installation

1
2
3
4
#echo "deb http://download.rethinkdb.com/apt `lsb_release -cs` main" | tee /etc/apt/sources.list.d/rethinkdb.list
#wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | apt-key add -
#apt-get update
#apt-get install rethinkdb

Start the server with the command “rethinkdb” at a terminal prompt. By default administrative tools are available at localhost:8080/.

Client driver installation

cd to the working directory then install a node project

1
2
3
4
5
mbc@dc7700s: cd ./syncd/prog/shiny/music
mbc@dc7700s:~/syncd/prog/shiny/music$ npm init
mbc@dc7700s:~/syncd/prog/shiny/music$ npm install rethinkdb --save
mbc@dc7700s:~/syncd/prog/shiny/music$ node
>r = require('rethinkdb')

Set the conn variable and interact with the database

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mbc@dc7700s:~/syncd/prog/shiny/music$ node
>r = require('rethinkdb')
>var connection = null;
r.connect( {host: 'localhost', port: 28015}, function(err, conn) {
if (err) throw err;
connection = conn;
})


>r.db('shiny').table('music').run(connection, function(err, cursor) {
if (err) throw err;
cursor.toArray(function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));
});
});

Insert

1
2
3
4
5
6
7
8
r.db('shiny').table('music').insert([{artist:'Boston', 
songs: [ {title:'song1',genre:'rock',url:'https://www.youtube.com/watch?v=SSR6ZzjDZ94'},
{title:'song2',genre:'rock',url:'https://www.youtube.com/watch?v=SSR6ZzjDZ94'}]
}]).run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));
})

Update

1
2
3
4
5
6
7
8
9
r.db('shiny').table('music').
filter(r.row("artist").eq("Boston")).
update({songs:

[ {title:'song1',genre:'rock',url:'https://www.youtube.com/watch?v=SSR6ZzjDZ94'},
{title:'song2',genre:'rock',url:'https://www.youtube.com/watch?v=SSR6ZzjDZ94'},
{title:'song3',genre:'rock',url:'https://www.youtube.com/watch?v=SSR6ZzjDZ94'}]}).run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));})

Show all

1
2
3
r.db('shiny').table('music').distinct().run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));})

Delete all

1
2
3
r.db('shiny').table('music').delete().run(connection, function(err, result) {
if (err) throw err;
console.log(JSON.stringify(result, null, 2));})

Launch script

The ‘launch.browser’ option to runApp() deals with the random port assigned by Shiny.

music.sh
1
2
3
4
5
#!/bin/bash
rethinkdb -d /home/mbc/shiny/music/rethinkdb_data/ &

R -e "shiny::runApp(appDir='/home/mbc/shiny/music', launch.browser=TRUE)"

Share

Fermi's Paradox

Aestivation: Aliens are hibernating until the average temperature of the universe cools a bit more which will make their information processing more efficient.

Share

Behavioral Genetics

Five laws from JayMan

Direct evidence for transport of RNA from the mouse brain to the germline and offspring

Worm Parents Pass on Behaviors Epigenetically to Offspring

Heredity and behaviour in dog breeds

Share