Thursday, July 28, 2016

Changing Shells on a Domain

Problem:  Linux box on Windows domain does not allow the user to set the shell with chsh -s /bin/zsh (or whichever shell).  There are no errors, it just doesn't work.  Using root, nothing happens either, using chsh -s /bin/zsh to set it for the user gives the error user '' does not exist in /etc/passwd.  You could probably go into the passwd file and make it work but a suitable way is to add to .bashrc

export SHELL=/bin/zsh
exec /bin/zsh -l

This redirects the shell to zsh but also allows you to type "exit" to leave the terminal - not just return to bash.

*NOTE:  this should also work if the user does not have root access - like on a shared computer

OpenFOAM on Domain Computer

Problem: OpenFOAM does not work linux machine added to a Windows domain.  When you source OpenFOAM bashrc file, it overwrites the PATH so no terminal commands are recognized (ls, sudo, etc.)

cd /opt/openfoam4/etc (or whichever version is installed)

sudo vim bashrc

comment line 153:
# cleaned=`$foamClean "$PATH" "$foamOldDirs"` && PATH="$cleaned"

save and quit (:wq)

For some reason, this line destroys the path when the machine is on the domain.  This is not a problem for machines not on a domain.

*NOTE: for zsh shell, there may be an error stating that "-t" flag is not recognized, if so:

sudo vim

delete the "-t" from line 73

the line should read:
[ "$(type wmRefresh)" = "alias" ] && unalias wmRefresh || unset wmRefresh

Wednesday, June 1, 2016

Label 3D Scatter Plots in Python

I work with grid data and sometimes I need to see the sequence in which nodes are ordered.

This can be done with annotate in 2D (see documentation) but not 3D.  Alternatively use "text"

ax.text(x[i], y[i], z[i] , "%s" % (str(i)), size=20, zorder=1, color = "black")

x,y,z are the location in 3-space, %s stores a string, str(i) converts "i" into a string and puts it in place of %s.

Friday, May 20, 2016

Accidentially hit C-x C-s in Vim

I use both emacs and Vim, but mostly emacs.  I often forget I'm in vim and hit C-x C-s to save.  C-s is scroll lock which effectively locks up vim.

C-q will unlock and allow you to return to vim.

*C = Ctrl so C-q is Ctrl+q

Thursday, May 19, 2016

Initiating Multidimensional Vectors in c++

I found this page helpful for 3D since 2D was reasonably straightforward.

std::vector array1D(2);

std::vector > array2D(2,std::vector(3))

std::vector > > array3d;
    int rows = 2, columns = 3, planes = 4;
    for (int i = 0; i < rows; i++) {
     for (int j = 0; j < columns; j++) {

and using structures
struct VoxelProperties {
    // Contains:
    int NumInVoxel; // Num points in each voxel
    std::vector NodeIndex; // Array to store the Index of points in the voxel
    std::vector Voxels(2);
    Voxels[0].NumInVoxel = 1;
    std::cout << Voxels[0].NumInVoxel << std::endl;
    std::cout << Voxels[0].NodeIndex[0] << std::endl;

    std::vector > Voxels(2,std::vector(3));
    Voxels[0][0].NumInVoxel = 1;
    Voxels[1][1].NumInVoxel = 11;
    std::cout << Voxels[0][0].NumInVoxel << std::endl;
    std::cout << Voxels[0][0].NodeIndex[0] << std::endl;
    std::cout << Voxels[1][1].NumInVoxel << std::endl;
    std::cout << Voxels[1][2].NodeIndex[0] << std::endl;

    std::vector > > Voxels(2,std::vector(3));
    std::vector > > Voxels(2,std::vector(2) >(3));
    std::vector > > Voxels;
    int rows = 2, columns = 3, planes = 4;
    for (int i = 0; i < rows; i++) {
    for (int j = 0; j < columns; j++) {
    Voxels[0][0][0].NumInVoxel = 1;
    Voxels[1][1][2].NumInVoxel = 11;
    std::cout << Voxels[0][0][0].NumInVoxel << std::endl;
    std::cout << Voxels[0][0][1].NodeIndex[0] << std::endl;
    std::cout << Voxels[1][1][2].NumInVoxel << std::endl;
    std::cout << Voxels[1][2][2].NodeIndex[0] << std::endl;
    std::cout << Voxels[1][2][2].NodeIndex[1] << std::endl;

Friday, April 1, 2016

Min, Max, argMin, argMax of std::vector in c++

I love c++.  I hate c++. I can confirm that c++ exists.  There... that's how I feel.  Coming from basic to VB to Matlab to Fortran to python to c++ - and all within the realm of numerical analysis - I view c++ as that dumb guy who thinks he's so much smarter than everyone else.  The rest of us just have to deal with him because but nobody really respects him (Linux: I'm talking to you too even though I have grown quite fond of you as my daily OS).

Anyway...ya ya ya c++ writes operating systems.  Beat that Fortran.  At least if I want to find the minimum and maximum values of an array, it's simple in Matlab and Fortran and Python and ... mrp min(x), max(x), argmin(x), argmax(x) or something simple like that.

Stackexchange is a godsend...not so much for this question though.

Here is how to do it in c++ using c++ BS to do it.

I almost exclusively use std::vectors so that's what I'm talking about now.

double min = *std::min_element(x.begin(), x.end());
double max = *std::max_element(x.begin(), x.end());

int argMin = std::distance(x.begin(), std::min_element(x.begin(), x.end()));
int argMax = std::distance(x.begin(), std::max_element(x.begin(), x.end()));

Tuesday, March 15, 2016

Convert git --bare to normal

I was making a bunch of --bare repos for interpreted codes.  I started working in compiled languages and found it nicer to have the compiled program easily available so my coworkers can just copy and run it rather than cloning and compiling themselves.  I wanted to convert the --bare to normal repos.  Enter stack exchange!

I'm reposting here because you have to read the answer and the comments to get it all working.

Make a .git folder in the top-level of your repository.
Move the all the repo folders into the .git folder (HEAD branches config description hooks info objects refs) into the .git you just created.
Run git config --local --bool core.bare false to convert the local git-repository to non-bare (might need sudo)
run git checkout master (this one was found in the comments)