Monday, December 30, 2013

Find ssh port number for ftp

Yeah, that!
I could ssh from terminal but wanted to transfer files into a windows. Tried ftp into the server using the filezilla. However, could not confirm the port number. So, this guy did the trick of finding the connected port number.
Once I had access to the port number, I could put that into filezilla, then log in. Neat!

echo ${SSH_CLIENT##* }

Thursday, December 26, 2013

Convert png into movie for youtube

Just small piece of code does the magic!


avconv -i rlds_bced_1960_1999_ipsl-cm5a-lr_rcp8p5_20%02d.png -r 5 -c:v libx264 -crf 1  -pix_fmt yuv420p img2.mov
  • -i "rlds_bced_1960_1999_ipsl-cm5a-lr_rcp8p5_20%02d.png" uses these files as the input, %d is a placeholder for the number
  • -r 5 the desired frame rate, 5 FPS in this case
  • -c:v libx264 use the h264 codec x264
  • -crf 20 the video quality, 20 is pretty high, the default is 23
  • -pix_fmt yuv420p a compatible pixel format

The nice info here:
http://askubuntu.com/questions/269834/how-to-generate-a-mov-file-from-png-images

Sunday, November 24, 2013

Edit Webpages in Google Chrome

  • Open DevTools (View page elements Ctrl+Shift+I).
  • Open Elements panel.
  • Select html or body or another element you want.
  • Open console by Esc.
  • Type $0.contentEditable = true
The edits are not permanent. However, useful to get insights into the webpage construction. Another useful tool is too see the webpage in 3D (in Firefox).

Friday, November 22, 2013

Mention Directory/Filename as 02 format

x = 3;

modisFold =  (sprintf('MODIS_july_%02.f/',x))

will result into 'MODIS_july_03/'.


This is a nice trick using sprintf as it avoids need to do for loop like I used to for date<10.

Thursday, November 14, 2013

Save Matlab Figure png same as screen appearance with annotation box

Problem: When I save matlab figures, the plots are saved distorted.
% Get screen size

scrsz = get(0,'ScreenSize');
h = figure('Position',[1 scrsz(4)/2 scrsz(3) scrsz(4)/2]);  % set figure size wrto screen size
% Position is set as  [left bottom width height]
% This is for setting fig size

h1= subplot(1,3,1);

% annotation box
p1 = get(h1,'Position');
t1 = get(h1,'TightInset');
x1 = p1(1)+t1(1); y1 = p1(4)-p1(1);
t = sprintf('R = %0.4f \ny = %0.2f + %0.2fx\nN = %i\nRMSE = %0.2f',g(1,2),p(1,2),p(1,1),length(outputs),RMSE);
% yes, I had few stuffs going on in there.  R, y=mx+c, Number of data, and RMSE
% axis   square
annotation('textbox',[x1 0.7 0.30 0.20],'String',t,'FontSize',14,'FitBoxToText','on');

h2= subplot(1,3,2);

axis([0 100 0 100])
% axis   square
p1 = get(h2,'Position');
t1 = get(h2,'TightInset');

x1 = p1(1)+t1(1); y1 = p1(4); % this will fix the annotation box

% axis   square
annotation('textbox',[x1 0.7 0.30 0.20],'String',t,'FontSize',14,'FitBoxToText','on');
% one more subplot


% Get png right for saving
% Set units
set(h, 'Units', 'centimeters')
set(h, 'PaperUnits','centimeters');
pos = get(h,'Position');

% Set paper size to be same as figure size
set(gcf, 'PaperSize', [pos(3) pos(4)]);

set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 pos(3) pos(4)]); % yes, bottom right corner!

% Print as png figure file
print(gcf, '-dpng', [fnPRE, num2str(nneurons),'-loop',num2str(i),'ipdea',num2str(testm{numvarcase})])

Sunday, November 3, 2013

Empty that Full Swap Memory #Ubuntu

Well, I just did not like the 100% swap memory usage being shown after my process was done done done!
So I swap-offed and onned (there are no such words, but why not!).
You see that green line going from 100% to 0%. Yeah, that!


sudo swapoff -a
sudo swapon -a

Saturday, November 2, 2013

Find the number of days in given year range



% Find Number of days in an year
% This needed for finding indices to process
clc
countindices1 = 1
year = 2005;
countdays = 0;
while year<= 2010
   disp(['year', num2str(year)]) 
    countdays = countdays+yeardays(year);

    disp(['starts@', num2str(countindices1)])
        disp(['ends@', num2str(countdays)])
        array= [countindices1:countdays];
        whos array
    disp('%%%%%')
    
    countindices1 = countdays+1;
    
         year = year+1;
disp(['totaldays = ',num2str(countdays)])
end


Monday, October 28, 2013

Tuesday, October 22, 2013

Install wget in Mac using terminal

This is my history from the terminal installing wget in mac

210  which wget
  211  curl -O http://ftp.gnu.org/gnu/wget/wget-1.13.4.tar.gz
  212  tar -xzf wget-1.13.4.tar.gz
  213  cd wget-1.13.4
  214  ./configure --with-ssl=openssl
  215  make
  216  sudo make install
  217  wget --help
  218  cd .. && rm -rf wget*
  219  ls
  220  history

Monday, October 21, 2013

Check and curl the file list.

So, I had downloaded a bunch of files using curl.
However, the number of files seem to be less than what I had in the list.

Simple program to check if the file exists, else download using curl.

My trouble was that the list had repeated items. Had not checked before running around... Sigh!


clc

fid = fopen('urls.txt');
flist = textscan(fid, '%s');
fclose(fid);

for jj = 1:length(flist{1})
    fn = flist{1}{jj}
   
    fnlocal = fn(28:length(fn));
   
    if exist(fnlocal,'file')>0
        jj
        fnlocal
        pause(0.5)
        % do nothing
       
    else
        %curl
       
        command = ['curl -L -O ' fn];
        system(command)
       
    end
end

Install using software-center in Ubuntu

So I had trouble getting Meld diff viewer software using the software center.
Whenever I tried to install it, it asked the password for the first user.

This can be solved by sudoing the software center from terminal
$ sudo software-center

Then Install the Meld diff viewer.
 


Friday, October 18, 2013

Download from list using curl in shell/terminal

So, I had to get data from a text file with the list of url.
I saved the url (one per line) in a txt file. Then executed the command
-O saves teh given name in the server. -L gracefully handles redirects if any.

xargs -n 1 curl -O -L < urls.txt

Remove "Subscribe to: posts (atom) " from Blogger

Search for "blog feed links" Change "!=" tp "==" so that subscribe to posts will be visible only in the posts page.
  <b:if cond='data:blog.pageType == "item"'> <!-- Blog feed links -->
If you want to remove the subscribe to comments feature, then remove the following:
  <b:include data='post.feedLinks' name='feedLinksBody'/>

In the following block:

  <b:includable id='feedLinks'>
  <b:if cond='data:blog.pageType == "item"'> <!-- Blog feed links -->
    <b:if cond='data:feedLinks'>
      <div class='blog-feeds'>
        <b:include data='feedLinks' name='feedLinksBody'/>
      </div>
    </b:if>

    <b:else/> <!--Post feed links -->
    <div class='post-feeds'>
      <b:loop values='data:posts' var='post'>
        <b:if cond='data:post.allowComments'>
          <b:if cond='data:post.feedLinks'>
   <b:include data='post.feedLinks' name='feedLinksBody'/>         
          </b:if>
        </b:if>
      </b:loop>
    </div>
  </b:if>
</b:includable>

Saturday, October 12, 2013

Creating CDF plot.

Generate a CDF plot

close all
y = randn(1,40000);
figure
hist(y,40)
title('Histogram')
% xlimit([-3,3])

  saveas(gcf, ['SAVE/''Histogram-Gaussian', num2str(mm)], 'png')

figure
cdfplot(y)
  saveas(gcf, ['SAVE/''CDF-Gaussian', num2str(mm)], 'png')
        

Monday, October 7, 2013

Load saved figure and save in fullscreen size

Code
% Load figure
filename =dir;
filename.name
for jj = 3:length(filename)
    this = filename(jj).name;
    hfig=  openfig(this,'reuse');
    set(hfig,'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
     set(hfig,'paperorientation','portrait');

 %     saveas(gcf,[this,'.png'])
% pause
 
end

Monday, June 17, 2013

Create SSH alias

Pretty easy!
In terminal do:
vi ~/.ssh/config #add the following lines Host myserver User username HostName host.server #then esc, :wq # Then ssh myserver should do the magic.
-->

Tuesday, May 28, 2013

copy the list of files to another folder

I had a list of file, to be copied to another folder location for compiling them together. This worked!
cat listFile.txt | while read line; do cp "$line" /Users/asdf/Documents/compile; done
-->

Sunday, February 10, 2013

Run matlab program from shell

This is nice!
#!/bin/bash filename=program.m; cat > $filename << EOF % It is matlab script disp('Hello World') A=zeros(3,3); if size(A)==3 disp('Hello again') end EOF chmod +x $filename matlab -nodesktop -nosplash -nodisplay -r "run ./$filename ; quit;"
-->

Tuesday, February 5, 2013

Recursive Action in Folders using matlab

I wanted to cleanup some of the old pdf files but not clean out the .doc/.tex in there. Also, .zip was of no use, so wanted to get rid of that too! This small matlab script did the job! jj=3 because . and .. are first two from the dir.
filename =dir; filename.name for jj = 3:length(filename) this = filename(jj).name; if isdir(this) this eval(['cd ' this]) !rm -r *.pdf !rm -r *.zip cd .. end end
-->

Sunday, January 27, 2013

MCMC

Doing MCMC is fun! Thanks to KnuthClass
aa
% probability step
if x(n) < 0
    px = 3/5;
else
    px = 2/5;
end


% Metropolis Hastings MCMC

p = min([1, p(y)/p(x(n))]);
r = rand;

n = n+1;
if r < p 
    x(n) = y;
else
    x(n) = x(n-1);
end


%%

% do this 100 times

x(1) = 1;   % start in the low prob region
px(1) = 2/5;

for n = 1:10000
    
    % take a step
    y = (-1)*x(n);
    
    % probability step
    if y < 0
        py = 3/5;
    else
     py = 2/5;
    end
    
    % Metropolis Hastings MCMC
    p = min([1, py/px(n)]);
    r = rand;

    %n = n+1;
    if r < p 
        x(n+1) = y;
        px(n+1) = py;
    else
        x(n+1) = x(n);
        px(n+1) = px(n);
    end
    
    x(n)
    
end
    

%%
clear

% Gaussian probability density with zero mean and unit variance
prob = @(z)((sqrt(2*pi))^(-1)*exp(-z^2/2));

x(1) = 5*(2*rand-1);
px(1) = prob(x);

for n = 1:100000
    step = 0.01*randn;
    y = x(n)+step;
    
    py = prob(y);
    
    p = min([1,py/px(n)]);
    r = rand;

    if r < p 
        x(n+1) = y;
        px(n+1) = py;
    else
        x(n+1) = x(n);
        px(n+1) = px(n);
    end
end

 aa

Wednesday, January 23, 2013

Blogger Trick hide the post/widget in main page

Well, I wanted to replace some of the widgets to invisible mode in nabinkm.com. Actually, wanted for long time...
<b:if cond='data:blog.pageType != "index"'>

the widget goes here...

</b:if>

Another trick is: replacing
]]></b:skin>


 by


]]></b:skin>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<style type="text/css">
.post,   #blog-pager {display:none;}
</style>
</b:if>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<style type="text/css">
body#layout .sidebar {display:inline;margin-top:200px;}
</style>
</b:if>
-->