Archive for category Computing

Adding missing Keyboard Shortcuts to Mac OS X and OS X applications

There is a really cool feature in Mac OS X that enables you to add missing Keyboard shortcuts in OS X applications. For instance, I was missing a shortcut for Clearing the working environment in RStudio which removes the variables in the current workspace. To add this I added a keyboard shortcut for this in the App Shortcuts section in the System Preferences -> Keyboard -> Shortcuts section

Screen Shot 2014-01-24 at 19.31.14

If you want add shortcuts for sub-menu items you do this by using a “->” between the menu item names (see the File->New File->Text File example in the above screenshot).

I also very frequently select text and want to search for that on Google in a new Safari window, so I added a new shortcut for this in the Services section. The preferences for this look like this:

Screen Shot 2014-01-24 at 19.40.26

Tags:

Unix date on format “day month time CET year” to something that EXCEL interprets as a date

The below formula converts:

Unix Date: Tue Dec 10 13:18:11 CET 2013

In Excel cell A1 into an

Excel understandable date: 2013-12-10 13:18:11

Formula in B1:
=RIGHT(A1;4)&”-“&IF(LEN(MATCH(MID(A1;5;3);{“JAN”;”FEB”;”MAR”;”APR”;”MAY”;”JUN”;”JUL”;”AUG”;”SEP”;”OCT”;”NOV”;”DEC”};0))>1;MATCH(MID(A1;5;3);{“JAN”;”FEB”;”MAR”;”APR”;”MAY”;”JUN”;”JUL”;”AUG”;”SEP”;”OCT”;”NOV”;”DEC”};0);”0″&MATCH(MID(A1;5;3);{“JAN”;”FEB”;”MAR”;”APR”;”MAY”;”JUN”;”JUL”;”AUG”;”SEP”;”OCT”;”NOV”;”DEC”};0))&”-“&MID(A1;9;2)&” “&MID(A1;12;2)&”:”&MID(A1;15;2)&”:”&MID(A1;18;2)

In Sweden the argument separator in Excel is “;” while otherplace it can be “,” so you might have to change that in the formula.

Elegant! (Joke)

OSX Finder Quicklook preview hacks

Use OSX Finder Quicklook to preview all plain text files:
https://coderwall.com/p/dlithw

Copy text/code from OSX QuickLook directly:
https://coderwall.com/p/94rlia

Tags: ,

Index of elements in array that fulfils a condition in Julia

In Julia (julialang.org) if you are rather interested in finding the indices (indexes) of the elements in an array that fulfils a certain boolean condition then find is your friend, like so:


julia> probs = [0.1, 0.2, 0.3, 0.4, 0.5]
5-element Array{Float64,1}:
0.1
0.2
0.3
0.4
0.5

julia> find(x->x>0.2, probs)
3-element Array{Int64,1}:
3
4
5

Conditional Array indexing in Julia

Conditional array indexing is a really nice convenience when one wants to access array items that fullfills a certain boolean criteria. This is done in Julia in the following way:


julia> probs = [0.1, 0.2, 0.3, 0.4, 0.5]
5-element Array{Float64,1}:
0.1
0.2
0.3
0.4
0.5

julia> probs[probs.>0.2]
3-element Array{Float64,1}:
0.3
0.4
0.5

Observe the “.” in the .> operator which signifies elemetwise comparison.
If you omit the “.” you will get the following error:


probs[probs>0.2]
ERROR: no method isless(Float64,Array{Float64,1})
in > at operators.jl:19

Tags:

Telldus tellstick causes temporary trackpad freeze on Macbook Pro

Telldus tellstick service causes temporary trackpad freeze on macbook pro.

For a solution that worked for me, please see:

https://discussions.apple.com/message/19640718#19640718

Multi-Hop SSH Tunnel from one host via another

It’s simple in its basic form!


$ ssh -L <local_port>:<host2>:<host2_port> -N <username>@<host1>

This sets up an SSH tunnel from the machine you are at to HOST 2 via HOST 1.

Tags: , , , ,

Embedding fonts in PDF’s – LaTeX whoes on Windows and Cygwin – Mac to the Rescue!

Of some reason Miktex 2.9 on my Windows installation refuses to embedd fonts eventhough the pdftexDownloadBase14 is set to true in the config file.

An easy fix for this is to print your document through PDF Creatorwhich will politely embed the fonts in the file it outputs! Thanks for that PDF Creator!!

Update: Unfortunately it seems that nowadays (I didn’t have this problem before) PDFCreator changes the layout of the page sightly (moving the text around on the paper) which causes the conference publishing system to reject the PDF.

The absolute simplest way seems to be to open the document in Preview on the Mac and save a copy, Preview will embed all fonts and not change the layout.

So to summarize, the way I got the PDF through the conference publishing machinery is to generate the document on windog$ with the following command:

pdflatex document.tex && bibtex document.aux

And run that command roughly four times, before LaTeX and friends has reached some kind of fix point. Now you have a document.pdf in the folder. To get the fonts embedded copy the document to a Mac, open it in Preview and save a copy, now you finally have a version with fonts embedded.

Emacsibilia

From the (X)Emacs Manual:

There are commands for placing point and the mark around a textual object such as a word, list, paragraph or page.

M-@
Set mark after end of next word (mark-word). This command and the following one do not move point.
C-M-@
Set mark after end of next Lisp expression (mark-sexp).
M-h
Put region around current paragraph (mark-paragraph).
C-M-h
Put region around current Lisp defun (mark-defun).
C-x h
Put region around entire buffer (mark-whole-buffer).
C-x C-p
Put region around current page (mark-page).

M-@ (mark-word) puts the mark at the end of the next word, while C-M-@ (mark-sexp) puts it at the end of the next Lisp expression. These characters sometimes save you some typing.

My comments:

Repeated M-@ extends the region forwards.

M-x describe-bindings
Lists all keybindings

Tags:

Extracting/Exporting a copy of a file from GIT

Sometimes I just want to get a copy of a file from GIT here’s how I do it:

git cat-file blob HEAD~25:src/experiment/BasicStacking.java

Can be combined with a redirect to a file

git cat-file blob HEAD~25:src/experiment/BasicStacking.java > BS.java