May 11, 2014 0

using find and grep to locate search strings

By in linux

clear && find . -name “*.tex” -exec grep -Hn <search string> {} \;

Tags: , ,

May 10, 2014 0

Python script to extract citation keys from latex files

By in latex, python


'''
Created on May 10, 2014

@author: thomas
”’

import fnmatch
import os”’
Created on May 10, 2014

@author: thomas
”’

import fnmatch
import os
import re

if __name__ == ‘__main__’:
directory = ‘/home/thomas/Ph.D/Projekter/057 2014-03-10 Database paper/latex-version/databasepaper’
matches = []
for root, dirnames, filenames in os.walk(directory):
for filename in fnmatch.filter(filenames, ‘*.tex’):
matches.append(os.path.join(root, filename))

print(matches)

pattern= re.compile(“cite{(?P[^{}]*)}”)
keyCollection=[]
for fname in matches:
with open(fname) as f:
fileContent = f.read()
#print(fileContent)
res = pattern.findall(fileContent)
print(res)
if res:
map(lambda x: keyCollection.append(x), res)

print(“,”.join(keyCollection).replace(‘,’,’ OR ‘))
import re

if __name__ == ‘__main__’:
directory = ‘/home/thomas/Ph.D/Projekter/057 2014-03-10 Database paper/latex-version/databasepaper’
matches = []
for root, dirnames, filenames in os.walk(directory):
for filename in fnmatch.filter(filenames, ‘*.tex’):
matches.append(os.path.join(root, filename))

print(matches)

pattern= re.compile(“cite{(?P[^{}]*)}”)
keyCollection=[]
for fname in matches:
with open(fname) as f:
fileContent = f.read()
#print(fileContent)
res = pattern.findall(fileContent)
print(res)
if res:
map(lambda x: keyCollection.append(x), res)

print(“,”.join(keyCollection).replace(‘,’,’ OR ‘))

Tags: , ,

March 26, 2014 0

finding text in files using find in linux

By in linux, ubuntu

Based on this stack-overflow response: http://stackoverflow.com/questions/16956810/finding-all-files-containing-a-text-string-in-linux
one way of searching for files containing a certain text patterns is:
grep -rnw ‘directory’ -e “pattern”

if you want to search relative to your current position replace “directory” with a . so:
grep -rnw . -e “pattern”

Tags:

February 10, 2014 0

Matlab: calling a function handle with parameters from a cell array

By in matlab

Having a function handle sometimes means that you want to be flexible regarding the number of input arguments.

having a function handle fhandle=@plot
means that you can call fhandle() but is you want to pass a variable number of arguments to fhandle that resides in a cell array, cparameters, containing e.g.: cparameters={[1:10],’resize’,’no’} you can do:
fhandle(cparameters{:}) which will result in e.g. plot([1:10],’resize’,’no’)

In the case where you want additional stuff to happen – e.g. add title to the plot you can do:

fhandle=@(data,titlestr,varargin) plot(data,varargin{:}) && title(titlestr)
cparameters={1:10,'test title','LineWidth',5}

fhandle(cparameters{:})

Will produce
plot(1:10,’LineWidth’,5) && title(titlestr)

Tags: , , ,

February 10, 2014 0

date string in matlab to autogenerate filenames

By in matlab

generate file names using the current date and time.

e.g.
filename=[datestr(now(),'yyyy-mm-dd HH:MM') ' preprocessed data.txt'];

generates:
2014-02-10 16:40 preprocessed data.txt

Tags: , ,

January 20, 2014 0

Python search path

By in python

It seems like that the search path that python searches for modules can be retrieved from sys.path

Tags: ,

January 20, 2014 0

installation of pygame for python3

By in python

The installation process that worked consisted of the following steps:

#install dependencies
sudo apt-get install mercurial python3-dev python3-numpy ffmpeg \
libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev \
libsdl1.2-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev

Download the latest pygame from repository: https://bitbucket.org/pygame/pygame/wiki/VersionControl
run: python3 config.py
run: 2to3 setup.py -w
run: python3 setup.py build
run: sudo checkinstall python3 setup.py install

Tags: , , ,

November 29, 2013 0

points on a sphere

By in geometry

nice link with formulas for relating points on a sphere to 3D points:
https://www.opengl.org/discussion_boards/showthread.php/159883-converting-a-3D-vector-into-three-euler-angles

Tags: ,

November 11, 2013 0

plot functions in mathematica

By in Mathematica, Uncategorized

contour plots can be used in mathematica to plot equations such as ellipsoids like:

1/10^2*x^2 + 1/6^2*y^2 + 1/15^2*z^2 == 1

a command like:

ContourPlot3D[
1/10^2*x^2 + 1/6^2*y^2 + 1/15^2*z^2 == 1, {x, -11, 11}, {y, -7,
7}, {z, -16, 16}]

creates the ellipsoid

May 27, 2013 0

push all submodules in a git repo

By in GIT

If you have a git repository that consist of several submodules you can push all submodules by doing the following:

place yourself in the main git repo.

write:
git submodule foreach git push

To make sure that you get through all the submodules even if errors occurs do:
git submodule foreach "git push || true"

Tags: , ,