Skip to main content

Posts

JAVA SORT COLLECTION List or Vector or arraylist or array

http://docs.oracle.com/javase/tutorial/collections/interfaces/order.html Sort vector or List import java.util.*;    public class Test {   class BedFormat implements Comparable     { String chrom; int end; public int compareTo(BedFormat obj) { return (this.end > obj.end ) ? 1 : -1 ; }    }      public static void main() { List vp = new ArrayList (); vp.add(new BedFormat()); vp.add(new BedFormat()); .... vp.add(new BedFormat()); Collections.sort( vp ); // print  // it will print according to end variable of object }   }     Example : Finding Median from a list   class ExpReplica implements Comparable { double valReplica; public ExpReplica(double valReplica) { super(); this.valReplica = valReplica; } public int compareTo(ExpReplica obj) { ...

Java Thread tutorial

// Wait for the child threads to finish job before main thread ends public Class TestJoin{      public static void main(String args[]) {         Vector vecThread = new Vector ();         for(int curLen=1; curLen<=5;curLen= curLen+1) //         {             vecThread.add( new Thread(new Inner(curLen)) );         }         for(int i=0;i         {             vecThread.get(i).start();         }         try {             for(int i=0;i             {                 vecThread.get(i).join()...

Gaussian Process GP

https://www.youtube.com/watch?v=16oPvgOd3UI function GP_1d kernel=5; switch kernel     case 1; k = @(x,y) 1*x'*y; % linear     case 2; k = @(x,y) 1*min(x,y); % brownian motion     case 3; k = @(x,y) exp(-100*(x-y)'*(x-y)); % squared     case 4; k = @(x,y) exp(-1*sqrt(x-y)'*(x-y)); % Ornistin        case 5; k = @(x,y) exp(-1*sin(5*pi*(x-y))^2); % periodic      end % choose points at which to sample x = (0:.005:1); n = length(x); % covariance matrix C = zeros(n,n); for i=1:n    for j=1:n       C(i,j) = k (x(i), x(j)) ;    end end % sample from gaussian process at this points u = randn(n,1); [A, S , B ] = svd(C); z = A *sqrt(S)*u; % plot figure(2); hold on; plot(x, z, '.-'); axis([0, 1, -2, 2]); end ============ IN 2D ======== function GP_2d kernel=3; switch kernel     case 1; k = @(x,y) 1*x'*y; % linear ...

Ruby Tutorial

 Ruby Installation with graphics (painful) ============================== * Install RVM for Ruby - \curl -#L https://get.rvm.io | bash -s stable --autolibs=3 --ruby * Install TK from ActiveTcl - http://www.activestate.com/activetcl * Run rvm reinstall 2.0.0 --enable-shared --enable-pthread --with-tk --with-tcl Recommended Sites ================== 1. From author (Yukihiro Matsumore) http://rubymonk.com/ 2. Basic http://www.tutorialspoint.com/ruby/ruby_variables.htm Interactive Tutorial ============== http://tryruby.org/ Run ruby ========= 1. Using interpreter irb ( start interpreter) load "fname.rb" ( load the file) ruby "fname.rb" ( run the file) 2. Using ruby command ruby "fname.rb" ( run the file) 3. Type of Variables & Mehod ==================== @instanceVariable   @@classVariable $GlobalVariable 4. instanceMethod def fnc ... end 5. ClassMethod ============= def self.fnc ... end 6. Ano...

Haskell tutorial

Important link for tutorial =================== http://www.haskell.org/haskellwiki/Haskell_in_5_steps#Where_to_go_from_here http://www.cs.nott.ac.uk/~gmh/book.html http://rigaux.org/language-study/syntax-across-languages-per-language/Haskell.html http://learnyouahaskell.com/chapters You can change prompt by :set prompt 0. how to run/quit haskell file =============================== a. ghci  ( it will load Glasgow Haskell Compiler) b. load file >  :l filename.hs c. fncInsideFile parameter d. :quit  1.  bracket Issues in ============= fnc(a)  // wrong fnc a ;// right, parameters are space seperated Parentesis a. for tuple  -- let tup = ( 1, "sss") b. (x:xs) -- x is first element, xs is rest elements c.   for curry function/section. if you don't use () it will not work -- correct useSection     = (/2) -- Incorrect useSection     = /2 instead of using 1 + 2  ...

Ghostscript pdf merge split

1. Cut range of page/ split  pages from pdf ========================= gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=3 -dLastPage=7 -sOutputFile=out.pdf   in.pdf 2. Merge multiple pdfs ================ gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=out.pdf in1.pdf in2.pdf