Posts

Showing posts from 2014

Getting Started with NatTable

Image
Sample code to create Nat table with dummy data private NatTable createNatTable(Composite parent) { DummyGridLayerStack dummyLayer = new DummyGridLayerStack(4, 10); DataLayer rowHeader = (DataLayer) dummyLayer .getRowHeaderDataLayer(); rowHeader.setColumnWidthByPosition(0, 20); return new NatTable(parent, dummyLayer ); } Output :

Alpha-Beta Pruning Algorithm

Alpha–Beta Pruning is a search algorithm that seeks to decrease the number of nodes that are evaluated by the minimax algorithm in its search tree alphabeta(origin, depth, -∞, +∞, TRUE) Pseudocode alphabeta(node, depth, α, β, maximizingPlayer) if depth = 0 or node is a terminal node return the heuristic value of node if maximizingPlayer for each child of node α := max(α, alphabeta(child, depth - 1, α, β, FALSE)) if β ≤ α break (* β cut-off *) return α else for each child of node β := min(β, alphabeta(child, depth - 1, α, β, TRUE)) if β ≤ α break (* α cut-off *) return β

Git Commands

Git Pull git pull will gets all from a remote and it instantly merge it into the branch you are in when you make the request. Pull is a request that runs ‘fetch’ then a ‘merge’ by default. Git Fetch Fetch is similar to pull, except it won’t do any merging. Download objects and refs from another repository Git Init command: git init Create an empty Git repository or reinitialize an existing one Git Status command: git status Show the working tree status Git Commit command: git commit -m "Message" Record changes to the repository Git Push command: git push Update remote refs along with associated objects Git add     Add file contents to the index Git bisect      Find by binary search the change that introduced a bug   Git branch      List, create, or delete branches     Git checkout    Checkout a branch or paths to the working tree     Git clone       Clone a repository into a new directory Git diff        Show changes between commits, comm

SQLite Dialect

Few days ago I worked with Hibernate and SQLite. I found that Hibernate doesn't provide dialect for SQLite Here is SQLiteDiaect: import java.sql.SQLException; import java.sql.Types; import org.hibernate.JDBCException; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.AbstractAnsiTrimEmulationFunction; import org.hibernate.dialect.function.NoArgSQLFunction; import org.hibernate.dialect.function.SQLFunction; import org.hibernate.dialect.function.SQLFunctionTemplate; import org.hibernate.dialect.function.StandardSQLFunction; import org.hibernate.dialect.function.VarArgsSQLFunction; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.DataException; import org.hibernate.exception.GenericJDBCException; import org.hibernate.exception.JDBCConnectionException; import org.hibernate.exception.LockAcquisitionException; import org.hibernate.exception.spi.SQLExceptionConverter;

Implement Auto-Hide Scrollbar in SWT Text Component

Text textControl = new Text(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); Listener listener = new Listener (){ @Override public void handleEvent(Event event) { Text t = (Text)event.widget; Rectangle r1 = t.getClientArea(); Rectangle r2 = t.computeTrim(r1.x, r1.y, r1.width, r1.height); Point p = t.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); t.getHorizontalBar().setVisible(r2.width <= p.x); t.getVerticalBar().setVisible(r2.height <= p.y); if (event.type == SWT.Modify){ t.getParent().layout(true); t.showSelection(); } }}; textControl.addListener(SWT.Resize, listener); textControl.addListener(SWT.Modify, listener);

Elementary Parallel Algorithm

Summation (Hypercube SIMD) Here SIMD - Single Instruction Multiple Data-streams Parameter n {number of elements to add} P {number of processing elements} Global j Local local.size, local.value [0….ceil([n/P]), sum, tmp { for all Pi where 0 ≤ i ≤ P – 1 do if i < (n mod p) then local.size <- ceil([n/P]) else local.size <- flr([n/P]) end if sum <- 0 end for for (j = 1; j <= ceil([n/P]); j++) do for all Pi where 0 ≤ i ≤ P – 1 do if local.size ≥ j then sum <- sum + local.value[j] end if end for end for for (j = log P - 1; j ≥ 0; j--) do for all Pi where 0 ≤ i ≤ P – 1 do if i < 2j then tmp <- [i + 2j] sum sum <- sum + tmp end if end for end for }

Trying to install Tomcat on Solaris 10

Problem: There is a problem in installing Tomcat on Solaris as there is some kind of incompatibility between Solaris Tar and GNU tar. When you will try to extract the Tomcat via tar utility then it will cut file names which is longer than some specific number of characters. It will produce @LongLink error. One solution:  Download Apache-Tomcat(required version).zip from ftp site of Apache tomcat. You will find some FTP links on this page http://www.apache.org/dyn/closer.cgi   Unzip that tomcat.zip file   Removed extra new line character on startup.sh and shutdown.sh: "dos2unix startup.sh startup.sh"  and  "dos2unix shutdown.sh shutdown.sh"  Changed permissions of the startup.sh and shutdown.sh:  "chmod 775  *.sh"

Hiding SWT Controls

There are many ways to hide SWT widgets. First one comes to mind is setVisible method of control. But the disadvantage of it is, hidden widget will not released and can't be used by other widgets. Another approach is. You can use layout data. In case of GridLayout, you can use exclude specific widget from being drown on canvas. Eg, Composite comp = new Composite(shell, SWT.NONE); comp.setLayout(new GridLayout(4, false)); Label hidenLabel = new Label (comp, SWT.NONE); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); hidenLabel.setGridData(gridData ); //hide the button gridData .exclude = true; comp.pack();