# quickies

## Common Lisp

### SBCL come with very few built-in package.

To install additional ones, use asdf, e.g.

(require 'asdf)
(require 'asdf-install)
(asdf-install:install 'cl-ppcre)


will install Perl-style regular expression support. Then, when you restart SBCL, you'll need to load it with

(asdf:operate 'asdf:load-op :cl-ppcre)


### To get a full-featured version of CL Hyperspec in Emacs

Look at dpans2texi.el.

## Clojure

### To start Clojure REPL

We need to create a small startup script, say clj. The simplest one is something like:

#! /usr/bin/env bash
java -cp /usr/local/share/clojure/clojure.jar clojure.main


The problem is that we won't benefit from command-line history, backward search, etc. For that to be effective, we need to use JLine (rlwrap doesn't work on OS X, due to the lacking Readline library). Then, we just have to modify the above script with:

java -cp /.../jline-0.9.94.jar:/.../clojure.jar jline.ConsoleRunner clojure.main


where ... denotes actual path to related files. Alternatively, this could be setup using CLASSPATH, or by placing the jar file in the system-wide java extensions directory, e.g. /Library/Java/Extensions or /System/Library/Java/Extensions. The latter doesn't seem to be working as jline would be loaded by the extension classloader which is unaware of class path variable. Startup tips are described in http://clojure.org/getting_started, and on http://www.stackoverflow.com.

### In addition to the core distribution

It is recommended to install clojure.contrib which is a set of additional features (like common mathematical operations) that are not present in the base package. To install it, just grab a binary (jar) distribution and make it available for Java. For that purpose, we can use a custom CLASSPATH, e.g. in my .profile:

CLASSPATH=/usr/local/share/jars


or add an extra argument to -cp when invoking clojure.jar from Java.

To check that everything works well, we can use a simple script test.clj, like this:

(ns test
(:use clojure.contrib.math
clojure.test))
(deftest foo
(is (= 4 (sqrt 16))))
(run-tests)


that can be run under Clojure REPL. If it is ok, we should see something like:

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
{:type :summary, :test 1, :pass 1, :fail 0, :error 0}


Here is another example:

(ns test
(:use clojure.contrib.pprint))
(pprint (for [x (range 10)] (range x)))


### A better way to get a working clj starting script on OS X

is described at http://bit.ly/eda9IS. It is possible to add as many libraries as we want (e.g., incanter).

### To facilitate editing and stay within our familiar Emacs

environment, we can use slime. A specific port for Aquamacs is available for download.

### JVisualVM (jvisulavm comes with Java SDK) might help seeing

how much Java memory, cpu and threads Clojure actually uses. h/t http://www.fatvat.co.uk/2009/05/jvisualvm-and-clojure.html

### A good set of exercices to translate from Lisp to Clojure:

L-99 – Ninety-Nine Lisp Problems. There is also functional-koans on Github.

### Getting help

(doc histogram) brings a short description of the function with optional parameters (no pager though).

## Emacs

### To activate folding mode for code blocks

M-1 C-x $; to revert, C-x$ (See set-selective-display)

### To test whether we are running Aquamacs (or any other Emacs flavor),

try:

(when (featurep 'aquamacs) ... )


On OS X, this just has to be negated to address built-in emacs.

### Use M-x describe-bindings (or C-h b) to see

all shortcuts for current buffer.

### Something that is lacking in most editors

is the possibility of creating temp buffer on the fly. E.g., C-x b (aka switch-to-buffer) allows to switch to a temporary buffer.

### Managing multiple windows is a matter of 6 commands:

C-x 1 = delete-other-windows, C-x 2 = split-window-vertically, C-x 3 = split-window-horizontally, C-x + = balance-windows, C-x o = other-window, C-x C-b = list-buffers. Use M-x describe-bindings to view all the Buffer-menu key bindings.

### To remove all distractive UI stuff, just put in your .emacs:

(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))


### C-c ( allows to navigate between references

e.g. equations, figures, etc. (With reftex-mode enabled, it is C-=.)

### Spell-checking is done with ispell

Under OS X, an easy replacement of ispell is done with aspell. You need to populate /usr/local/lib/aspell-0.60/ with compiled dictionnaries. To check which dictionnaries are available on your system, type aspell dicts. A useful replacement of ispell-mode is the interactive flyspell-mode. To use it with LaTeX, just add in your .emacs file:

(add-hook ‘LaTeX-mode-hook ‘flyspell-mode)


### To repeat a specific pattern or character

just use C-u nn pp, where nn is the number of times character pp as to be repeated. For example, C-u 78 - put a pseudo line of length 78; it is useful to choose this length as the default fill column width. To check which one is currently defined, type fill-column in the scratch buffer and evaluate this expression (C-x C-e). Common values are less than 80, e.g. 68, 70, or 78.

### An 'annoying' (?) feature of ESS

is that R comment (#) are automagically tabbed to the right (40th column by default). To get ride of this, you can:

• use ## instead, which yields comments aligned to the current level of indentation;
• use ### instead, which results in comments aligned to the beginning of the line.

See http://ess.r-project.org/Manual/ess.html#Indenting. Another option is to put (setq ess-fancy-comments nil) in your .emacs file.

### The auto-fill-mode also works with comments

Just M-q (fill-paragraph) on the region of interest. Another option is to use newcomment.el which provides comment-auto-fill-only-comments.

(require 'newcomment)
(setq-default auto-fill-function 'do-auto-fill)


### Ido and Smex are two useful add-ons to Emacs

They help mastering buffers and provide enhanced completion.

### ELPA stands for Emacs Lisp Package Archive

It provides package.el which acts as a package manager for Emacs based on a repository of pre-packed Emacs Lisp code. http://tromey.com/elpa/

### To get ride of the automatic indentation of comments in ESS mode

upon pressing the Enter key or after C-M-\, use two or three '#'. E.g.,

# this is a comment that will be right-justified
## This one will not move


### To check what a combination of keys stands for

just type C-h k followed by the combination.

### Useful keybinding for ESS/Roxygen

C-c C-o (inside function body) generate help template

### To ease the navigation across tab

use tabbar or remap F5 (not used on Air OS X), e.g.:

(global-set-key (kbd "<f5>")   'tabbar-forward-tab)
(global-set-key (kbd "C-<f5>") 'tabbar-backward-tab)


### To view the current buffer in Safari

just use M-x browse-url-of-buffer

### To open a file as root

just C-x C-f and type /sudo::/path/file

C-@ set mark
C-x C-x exchange point and mark
C-x n n narrow down to the specified region (between mark and point)
C-x n w revert to full buffer editing
M-< go to the top of the buffer
M-> go to the end of the buffer
C-l center buffer
C-v scroll one page forward
M-v scroll one page backward


### Although Emacs highlights closing parenthesis (short blink)

you might prefer M-x show-paren-mode

### To customize a given font face

just C-u C-x = to get its name.

### In dired mode, instead of pressing Enter

use a: it won't open a new buffer for each directory you visit.

### To get a nice overview of some pattern matching in a source file

M-x occur

### In ESS mode,

C-c C-z will switch to the end of ess inferior buffer.

### See http://stackoverflow.com/a/8920373/420055 to correct weird characters

in Emacs term or ansi-term when using zsh. (See also http://stackoverflow.com/a/7437783/420055 for git prompt and unicode characters).

### To add a specific entry to the Info index page, check that your custom

Info dir are up to date, C-h v Info-directory-list, and use install-info to update the Info dir (linking or moving an Info file is not enough). E.g., we can put mu4e.info in /usr/local/share/info and use



### To change Dock appareance (switch from 3D to 2D theme),

$defaults write com.apple.dock no-glass -boolean YES$ killall Dock


To revert, use -boolean NO.

### There are three configuration files that can be used to customize the shell

(default to Bash): .bashrc, .bash_profile, and .profile. The first two are for non-interactive and interactive shell, respectively. The latter one is loaded when no .bash_profile exists, but its existence will supercedes .profile. The .bashprofile seems to be the recommended one (at least, according to Apple support). Some authors suggest to fill the .bash_profile with something like

if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi


so that everything goes into .bashrc. There are also two system-wide configuration files that are located under /etc: /etc/profile and /etc/bashrc.

### Apple's computers don't come with a true Readline library.

Instead, libedit is used a replacement, which might cause some troubles with applications relying on console. If necessary, it can be installed with a few steps:

$curl -O ftp://ftp.cwru.edu/pub/bash/readline-6.1.tar.gz$ tar xvf readline-6.1.tar.gz && cd readline-6.1
$./configure && make$ sudo make install


For Python, it is not really a problem as we can simply do

$sudo easy_install readline  and use the excellent ipython or bpython interactive shells. ### Adding colors in the Terminal can be done in (at least) two ways. First, we can just set an alias to ls, e.g. alias ls'ls -G'= (=ls --color=auto= don't under OS X, but we can use export LS_OPTIONS'–color=auto'= instead). Another option is to use CLI colors, that is: export CLICOLOR=1 export LSCOLORS=dxfxcxdxbxegedabagacad  The order matters: DIR, SYMLINK, SOCKET, PIPE, EXE, BLOCKSP, CHARSP, EXESUID, EXEGUID, DIRSTICKY, DIRWOSTICKY. Color codes read as follows: a = black, b = red, c = green, d = brown, e = blue, f = magenta, g = cyan, h = light gray, x = default. ### Parameter expansion is useful when we want to remove file extensions in shell scripts, e.g.${file%.*}. More generally, ${varname%pattern} allows to remove pattern at the end of a variable. h/t Jake Hofman ###${!#} gives the last command line argument

and !! gives the arguments of the previously-executed command.

### Instead of playing with diff

use comm (or grep -xF) to check for lines common to two files. h/t Jake Hofman

### To make a given file executable, use chmod +x or chmod 755.

we often find root (user) and wheel or admin (group). In fact, wheel is the system administrator group in BSD, while root is the system administrator user. It is common to add sudo permissions to users in the wheel group. The choice of wheel comes from the BSD UNIX group at UC Berkeley; "big wheel" means an influential or important person.

### Some useful search features in Gmail

has:attachment pdf after:2011/01/01 before:2011/01/20
has:attachment (*.ppt || *.pptx || *.pps)
label:Label1 | label:Label2 (case insensitive)
label:Label1 filename:pdf
from:John OR from:Joe cc: bcc:
subject:"match this exactly"
from:John (keyword1 OR keyword2) (remove OR to match both keys)
keyword1 -keyword2 (has key1 but not key2)
in:anywhere (Spam and Trash excluded)
is:starred


No solution for filtering large attachment, though. But see http://www.findbigmail.com or http://www.searchgmailbysize.com.

### To know if you are running the 'new awk' (nawk)

just try to add a custom function in an awk script. E.g., from the gawk manual

function changeit(array, ind, nvalue)
{
array[ind] = nvalue
}

BEGIN {
a[1] = 1; a[2] = 2; a[3] = 3
changeit(a, 2, "two")
printf "a[1] = %s, a[2] = %s, a[3] = %s\n",
a[1], a[2], a[3]
}


and test it:

$awk -f test_awk.awk  ### To view the latest files added to a directory use ls like this: $ ls -l -t /usr/bin | tail


The -c switch allows to view file sorted by modification date instead.

### Instead of creating an animated GIF with ImageMagick

e.g.:

$convert -delay 20 -loop 0 fig*.png spin_plot.gif  let's try to generate an SWF file thanks to the swftools: $ png2swf -r 2 fig*.png -o afig.swf


### We can enable summarize function for text

in Sytem Preferences > Keyboard > Services. Useful for counting words in an abstract.



### To show filesystems in human readable column format

and order by percentage used:



h/t climagic



h/t climagic

### Simply change file extensions from ex1 to ex2

$for f in *.ex1 ; do mv$f $( basename$f .ex1 ).ex2 ; done




### To find words that end in 'da'

$grep "da$" /usr/share/dict/words


h/t climagic



h/t climagic



h/t rmounce

### Uninstalling Applications is quite easy

but for Libraries it is often harder to tell what's been installed by a pkg. While events are logged in in /var/log/install.log, we won't find useful information there.

Solution 1 (easy):

• Run the pkg installer
• Look into "Show Files" just after installer has been launched

Solution 2 (harder):

• In /Library/Receipts there is everything we need, including an InstallHistory.plist where all packages are registered.
• Otherwise, you can just look at


we can use





### Instead of replicate, we can use rply to do something

when no return values is expected, e.g. for an animation

r_ply(10, plot(runif(50)))


better than which (colnames(d)="a")= or grep("^a$", colnames(df)) use match("a", names(d)) With huge data.frame, it's even better to use the fastmatch package (use fmatch instead of match). h/t Matthew Dowle, http://bit.ly/yFeDTT ### To update to a new version of R while keeping older installed programs we can use pkgutil to look for available versions on a Mac system: $ pkgutil --packages / | grep org.r-project


Mac versions usually include Leopard.fw.* in the installaed receipts. Then, we just have to tell the system to forget about a previous version, using e.g.,

$sudo pkgutil --forget org.r-project.R.Leopard.fw.pkga  ### Use page(d, method"print")= to view a long data frame d through a pager. ## Racket ### How to prevent void in output of list https://stackoverflow.com/q/41135630 On the use of the #:when clause in for/list form. ## TeX ### Using texdoc mathptmx show up a complete description of current font selection scheme for use with common PostScript fonts. Example of a nice title typesetted in Times New Roman (h/t tex.stackexchange.com, 8768) : \documentclass{article} \usepackage[T1]{fontenc} \usepackage{mathptmx} \begin{document} \noindent\fontsize{2cm}{2.2cm}\selectfont Geometric\\ Invariant Theory \end{document}  ### http://www.identifont.com is useful to try to identify a given typeface. ### http://detexify.kirelabs.org is a LaTeX symbol classifier where any symbol can be drawn by hand. ### An eps figure can be included in a pdftex or pdflatex document \usepackage[pdftex]{graphicx} \usepackage{epstopdf}  ### A tilde can be printed as ∼\!\! in math mode h/t Jake Hofman ### There are various spaces available in math mode \, = thin space; \; = medium space; \ = space; \quad = quad space; \! = negative space (useful with multiple integrands). ### To get a prefixed superscript on something use {}; i.e., {}_nC_k. h/t Jake Hofman ### tex2im is a useful replacement of LaTeXit to convert LaTeX formulas into high resolution pixmap graphics for inclusion in text processors or presentations. http://www.nought.de/tex2im.html ### If you're looking for anything to read before going to sleep try The LATEX2ε Sources (texdoc source2e). ### To see what documents are available through texdoc just run $ ls kpsewhich --var-value=TEXMFDIST/doc/latex


h/t tex.stackexchange.com, 4358

### We can use system font with TeX (yes, TeX, not LaTeX) too

say tex_ttf.tex is:

\font\1="Inconsolata"\1 hello
\bye


Compile with:

$xetex -no-pdf tex_ttf$ xdvipdfmx -vv tex_ttf


### It is possible to use a custom background on every page

of a (La)TeX document by using the atbegshi package.

### A lot of useful explanations on LaTeX

may be found at the following address: http://nitens.org/taraborelli/latex (Dario Taraborelli).

### A collection of fonts I like

Hoefler, Gentium, Fontin Sans, Myriad Pro, Minion Pro, Gill Sans, Inconsolota.

### A simple rendering of the TeX logo in HTML is

T<span style"position: relative; top: .2em">E</span>X=. A better solution is to directly embed relevant code into a CSS stylesheet, like proposed by Edward O’Connor's on his blog: http://edward.oconnor.cx/2007/08/tex-poshlet.

### There is no way to pass a range of citation as [1-5]

(instead of [1,2,3,4,5]), but here is a nice solution from http://tex.stackexchange.com (Credit: Martin Scharrer):

\usepackage{pgffor}
\makeatletter
\newcommand*\rcite[1]{%
\def\@gtempa{}%
\foreach \n in {#1} {%
\edef\@tempa{,bibitem\n}%
\expandafter{\@tempa}%
}%
\edef\@gtempa{{\expandafter\@gobble\@gtempa}}%
\expandafter\cite\@gtempa
}
\makeatother


Then, we can use things like

\rcite{3,...,10}      % 3-10
\rcite{2,5,6,...,10}  % 2, 5-10
\rcite{3,5,...,10}    % 3, 5, 7, 9


### To place all hyperlinks in dedicated footnote

\let\oldhref\href
\renewcommand{\href}[2]{\footnote{\oldhref{#1}{#2}}}


## Org

### To insert a non-breaking space

See this SO thread, or just use C-x 8 SPC.

## References

Generated by Emacs 28.1 (Org mode 9.5.2) on 2022-08-23 mar. 14:14 (chl@aliquote)