Friday, October 20, 2017

Mendeley Standalone Bibliography

If you want to create a bibliography, without having a document that has in-text citations, you can do so directly from Mendeley Desktop.
Select all the records you wish to add to your list, from your Mendeley Library, and then go to Edit and click on Copy. Once you have done this you can go to a text document, like Word, and simply click Paste. This will create a bibliography in your chosen citation style.

Src: http://guides.nyu.edu/c.php?g=277051&p=1846896

Monday, September 25, 2017

Batch explore and process dicom files

https://wiki.xnat.org/xnat-tools/dicombrowser

Wednesday, August 16, 2017

python matplotlib save svg with text as text

https://stackoverflow.com/questions/14600948/matplotlib-plot-outputs-text-as-paths-and-cannot-be-converted-to-latex-by-inks

The matplotlib documentation in http://matplotlib.org/users/customizing.html states that the default value for the parameter svg.fonttype is 'path', which means that characters will be converted to paths when exporting to svg format.
All I needed to do was add the following line in my script:
matplotlib.rcParams['svg.fonttype'] = 'none'
This way all characters are embedded correctly,


Another, more permanent option, is to put
svg.fonttype : none
in your matplotlibrc (~/.config/matplotlib/matplotlibrc, for example)

Friday, June 2, 2017

Ubuntu wipe directory

  1. Install the package 'secure-delete'
  2. Use the command 'srm -r pathname' to remove your folder and files
The default settings are for 38 (!!!) passes of overwrites which is extreme overkill imho (see more info about this here:
For my usage, I only want a single pass of random data so I use 'srm -rfll pathname'

Src:  https://askubuntu.com/questions/122549/how-to-shred-a-folder

Monday, May 8, 2017

Compare revisions of latex files using latexdiff

Acquire latexdiff package (depends on OS)­. Also available on CTAN.

run:

$ latexdiff draft.tex revision.tex > diff.tex

Compile diff.tex using your favorite sequence.

In order to take into account for \input and \include,
use the --flatten option.
The includes will point to their respective directories.
 
NOTE: the diff can take a long time for large document, like a PhD thesis :D 

Friday, April 21, 2017

format float to string converstion using C

Example of use:

float val = 123.456789123 ;
char output[11];
snprintf(output, 11, "%f", val);

src: http://stackoverflow.com/questions/7228438/convert-double-float-to-string

Friday, March 31, 2017

bibtex bst abbreviated first names (initials) without spaces

Now, find the line in the BST file that formats author names. Again, you already did this if you followed the advice in the previous question. In the case of abbrvnamed.bst, it looks like this:

{ s nameptr "{f.~}{vv~}{ll}{, jj}" format.name$ 't :=
 
Change it to this:

{ s nameptr "{f{.}.~}{vv~}{ll}{, jj}" format.name$ 't :=
 
That extra {.} tells the built-in BibTeX function format.name$ to replace the default “.␣” that appears between initials within the abbreviated first name with “.”. And that’s all there is to it!
If you’d like to learn how to hack BST files yourself, there’s a nice guide called Tame the BeaST.

Src: http://tex.stackexchange.com/questions/124990/abbreviated-first-names-without-spaces-in-between

Wednesday, March 29, 2017

ITK call crashes without message

If an ITK API call crashes without a message, it is likely that the necessary includes were not put in the source code. CMake will make the code compile anyways, but no runtime error messages will be displayed, complicating (already complex) debugging tasks.

Tuesday, March 21, 2017

bash find all directories matching substring

# find 'here' the directories matching "foo" and display, max search depth 10
find . -maxdepth 10 -type d -name '*foo*' -print

Src: http://stackoverflow.com/questions/16344365/use-bash-to-find-a-folder-name-that-contains-a-string

Friday, March 17, 2017

python one-liner to find the upper directory for a path

import os
 
updir = os.path.dirname(currentdir.rstrip(os.sep))

Friday, February 24, 2017

use CMake to get build-time svn revision

http://stackoverflow.com/questions/3780667/use-cmake-to-get-build-time-svn-revision

This is more of a pain to do than it needs to be. You can run a program at build time to extract the version information from subversion. CMake itself can be used as this program using its scripting language. You can run any CMake script using the -P command line flag. The piece of code to do this would be (To be placed in file getsvn.cmake):
# the FindSubversion.cmake module is part of the standard distribution
include(FindSubversion)
# extract working copy information for SOURCE_DIR into MY_XXX variables
Subversion_WC_INFO(${SOURCE_DIR} MY)
# write a file with the SVNVERSION define
file(WRITE svnversion.h.txt "#define SVNVERSION ${MY_WC_REVISION}\n")
# copy the file to the final header only if the version changes
# reduces needless rebuilds
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
                        svnversion.h.txt svnversion.h)
This extracts the subversion revision information and writes it to a header file. This header file is only updated when needed to avoid recompiling all the time. In your program, you would include that header file to get at the SVNVERSION define.
The CMakeLists.txt file that you would need to run the script would be something like this:
# boilerplate
cmake_minimum_required(VERSION 2.8)
project(testsvn)

# the test executable
add_executable(test main.c ${CMAKE_CURRENT_BINARY_DIR}/svnversion.h)

# include the output directory, where the svnversion.h file is generated
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# a custom target that is always built
add_custom_target(svnheader ALL
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/svnheader.h)

# creates svnheader.h using cmake script
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/svnheader.h
    COMMAND ${CMAKE_COMMAND} -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
                         -P ${CMAKE_CURRENT_SOURCE_DIR}/getsvn.cmake)

# svnversion.h is a generated file
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/svnversion.h
    PROPERTIES GENERATED TRUE
    HEADER_FILE_ONLY TRUE)

# explicitly say that the executable depends on the svnheader
add_dependencies(test svnheader)
You need to use add_custom_target and add_custom_command since there are no inputs to the svnheader.h file, it "appears from nowhere" to cmake. I already dealt with the issue of needless rebuilds in the getsvn.cmake file though, so rebuilding the "svnheader" target is basically a no-op if the subversion revision has not changed.
Finally, an example main.c file:
#include "svnversion.h"

int main(int argc, const char *argv[])
{
    printf("%d\n", SVNVERSION);
    return 0;
}

Thursday, February 2, 2017

Cross-Reference with custom text


With the package hyperref you can use the optional argument of \hyperref to reference a \label with arbitrary text:

\usepackage{hyperref}
 
 Reference to \hyperref[sec:hello]{this section}.
 
Src:  http://tex.stackexchange.com/questions/70143/cross-reference-with-custom-text

Friday, January 27, 2017

python pyplot graph margins

matplotlib.pyplot.margins(*args, **kw)
Set or retrieve autoscaling margins.
signatures:
margins()
returns xmargin, ymargin
margins(margin)

margins(xmargin, ymargin)

margins(x=xmargin, y=ymargin)

margins(..., tight=False)
 
  http://matplotlib.org/1.3.1/api/pyplot_api.html#matplotlib.pyplot.margins