How to replace line feeds in a text file with Python

The below Python code will replace line feeds in a text file with space or replace consecutive line feeds with one line feed. I named this replacelf.py. # file outtext in the current directory file_path = r"./outtext" # Note that the file has to be opened in binary mode. with open(file_path, "rb") as open_file: #read … Continue reading How to replace line feeds in a text file with Python

How to sort and rename files in Python on Linux and use tesseract OCR to extract text to a file

In order to convert a series of images with text as an image in them to text files, the best tool is tesseract. It is quite old, but very reliable when it comes to looking for and extracting text from images. After saving some screen shots as jpg files, it was found their names contained … Continue reading How to sort and rename files in Python on Linux and use tesseract OCR to extract text to a file

How to include other layout xml files in a layout file in Android

Sometimes some layout files can contain too many views making it difficult to manage the layout file later. To overcome this, Android has an <include> tag that allows the inclusion of other layout files into the main layout file (in below illustration, the activity_main.xml file). <include android:id="@+id/b_layout" layout="@layout/activity_main_part_b" /> The above include statement will add … Continue reading How to include other layout xml files in a layout file in Android

How to update or commit code changes from local github repository to repository on github

A user can make changes to code in their local folder (in this case, MumbaiStock) and then update or commit  that code into the github repository. Below is the user information: github User ID is userid github User Name is "UserFirstName UserLastName" github User Email is "user@emailsystem.com" To update github or commit code from the … Continue reading How to update or commit code changes from local github repository to repository on github

Read data from a JTable created from AbstractTableModel

If you have a JTable in Java created with an AbstractTableModel, you can read the data from it, using following: int rowCount = testTable.getRowCount(); for (int i = 0; i < rowCount; i++) { String mColumn1 = (String) testTable.getModel().getValueAt(i, 0); String mColumn2 = (String) testTable.getModel().getValueAt(i, 1); } Alternatively, you could also try where the JTable … Continue reading Read data from a JTable created from AbstractTableModel

Delete a selected row in JTable with a custom model

DefaultTableModel model = (DefaultTableModel) myTable.getModel(); //Get reference to model model.removeRow(x); //Remove row x You can also add a method deleteRow(int row) to your custom model class code as in: public class MyTableModel extends AbstractModel { private Vector dataVector = new Vector(); String[] columnNames = {"First Name", "Last Name", "Age"}; public int getRowCount() { if (dataVector.size() … Continue reading Delete a selected row in JTable with a custom model

Java program bug due to multiple declaration of variable in code and the fix

I created a small Java class to accept a date. However, when I tried to use it, I got a NullPointerException error. This post is just to illustrate how it was fixed. 1 public class DateForm { 2 JFormattedTextField txtMyDate;     //This is a variable at class level 3 4 dateForm () { 5 JTextFormattedField … Continue reading Java program bug due to multiple declaration of variable in code and the fix

How to print a date in the default JTable.print() header and setup the page

After a struggle, managed to figure out that the MessageFormat is not that complicated at all. All I wanted was to print a heading on each page of the JTable with the current date in it. The heading was to read "Report as on " + today's date. Here is how I accomplished the task. … Continue reading How to print a date in the default JTable.print() header and setup the page