Thursday, November 12, 2015

Update in PostgresSQL Using the Command Line Tool - PSQL

The command:

psql -h hostname -d database -U username -W --echo-queries -f script-file-name.sql

where:

-W - to request psql to ask for password (rather then assume no-password)-h  - PostgreSql server host name or ip
-f  - file with the SQL script to execute on the database
 --echo-querries - shows the currently executed query for easier debugging of the script

Wednesday, October 28, 2015

Install Puppy Linux on my Old ThinkPad R60

Version: Slacko Puppy 5.7

  • Problem: Wi-Fi not working. Solution:
  • First: rfkill list
  • if it says softblock yes, try Fn F5. If it doesn't help do: sudo rfkill unblock wifi; sudo rfkill unblock all
  • Then:

# cd /lib/firmware/
# cp iwlwifi-3945-2.ucode iwlwifi-3945-1.ucode
# ifconfig wlan0 up

And try to connect.

Monday, September 21, 2015

IntelliJ IDEA - Keyboard Shortcuts And More for An Ex-Eclipse User

Since, couple years ago, JetBrains made available its IntelliJ IDEA to users for free (yes, only its Community Edition), it became an interesting alternative to Eclipse IDE.  While Eclipse is a great IDE, people looking for something more (even if just a little more), may be tempted to switch to IDEA, so here's something for them from another developer tempted to switch as well.

I have bolded out the actions I tend to use all the time in Eclipse.


Basic Shortcuts:

  • C-N - open class
  • C-S-N - open any file
  • A-F7 - find all usages of the object in the workspace
  • C-Q - quick doco (info) about the object under cursor
  • C-click - go to definition/implementation
  • C-F12 - show quick outline of the class
  • C-Space - auto complete
  • C-S-Space - power auto complete (Tan and Enter - both select, but differently)
  • A-Insert - code generate
  • C-/ - comments with //
  • C-S-/ - comments with /*...*/
  • C-D - duplicates the selection
  • C-S-BckSpc - move back in change-history locations
  • C-S-F7 - highlight an identifier; F3 and S-F3 move to next/prev usage; Esc - de-highlight
  • Code | Optimize Imports - from menu
  • C-E - recent files list
  • call tree of the current method: C-A-H
  • locate the current file in the project tree: there is an icon in the project viewer
  • move selected statements up or down the file: C-S-up and down
  • go to declaration of the object: C-B 
  • go back in the browsing history (as opposed to change history):
    C-A-left and right or C-[
  • synchronize a file or a project against the SVN repo: see Version Control tool
Legend: C means Control, S - Shift and A - Alt

Advanced Shortcuts:

  • S-F6 - refactor: rename
  • Esc - in a tool window - moves focus to editor (S-Esc - also hides the tool window)
  • F12 - opposite to Esc
  • C-A-T - surround it
  • C-W - extend the selection
  • C-A-V - refactor: extract variable
  • Tab - live templates (np. itar Tab)
  • Local History | Show History - from file or directory shows and lets  revert to any version all changes in this file or directory

Create a New Project from Sources in IntelliJ: 

  • Open from sources or from SVN/GIT
  • Open Project Structure dialog (Ctrl+Shift+Alt+S) and specify which are source folders using the Module item from the left-hand panel

Friday, August 14, 2015

pgAdmin

Copy just the schema of a database: do Backup, with any format other than Plain (it requires pgsql to import it) and on the Option tab page select Schema Only.  It runs pg_dump behind the scene.  You will need pgAdmin newer than 1.16 which allowed schema-only option with Plain format only.
The problem is, version 1.20, for example, copies the whole database even if I check Schema-Only.

Back to Plain format.  In pgAdmin we choose a plain format and options as above or use comand line in CMD in folder where pgAdmin was installed as below:

pg_dump.exe --host myhost --port 8035 --username "myuser" --format plain --schema-only --no-owner --no-privileges --verbose --file "filename" "mydbname"

After generating it, in CMD run:

psql -d my-db-name -f "c:\aaa\my-exported-schema-file" -U postgres 

It will ask for the password.  The tool psql comes bundled with pgAdmin, at least it does in version 1.20.

Saturday, July 18, 2015

I Need Web Hosting Service - Small Size

Intro

I decided to host my genealogy tree using TNG software.  And so, I need webhosting service.  Small. Neither my tree is big, nor do I expect havey traffic to it, since I plan to open it only to my extended family.

First Impressions from Market Search

First, skip all companies advertising $2 hosting a month.  Haven't found one, that has a similar price for more than a first month.  Second, you may skip the so-called unlimited hosting.  At best, they will shutdown your service when when you generate more than average traffic from and to it.  Then, there are companies that squeeze so much from their hardware, that their server response is terrible, although basically everything works.  After this, you get prices of some $5 a month or more.  And this with only 500MB of disk space.  This was US market.

If you speak Polish, or are adventurous, go for polish web hosting.  They're still a jungle, but I have found a opinion based ranking of polish web hosting services at webhostingtalk.pl.  That website has also filterable collection of over 4K older and recent user opinions, So, you can easily check just opinions, for linuxpl, which is the company that seem to make my cut. It seems, for 2GB disk space with 50GB transfer (monthly) they charge about $13 a year.

Closing

I'll report on progress and my experience as I go.

I'd Like to Publish My Family Tree

Why publish on the internet? 

Why not just keeping it on the desktop/laptop at home?
  • Desktop and laptops do break and sometimes you may lose your data.
  • I'd like to share information easier with other members of my family.

There are many options, that is, many sites where you can publish your family tree. The question is about privacy and data ownership. First of all, I don't want my family tree to be public (at least not as a whole). Two, I want to preserve the ownership of the information.

I'm willing to pay for the service, but a reasonable amount, for example up to $50 a year. Ah, currently I don't have enough time to host a genealogy software on my own website. It does take time (although, at the end I consider this option, too).

Candidate websites 

Below candidates come from this review:
  1. Ancestry.com: family trees can be made private and shared only with the users you want (who can access them for free), the website is free to enter the family tree info BUT all Ancestry.com receives perpetual, complete right to all the user content in very generous terms (generous to Ancestry.com).
  2. tribalpages.com: Up to 10MB of space is free for user family tree info and access is controlled by the user (there is a fee for more space, $24-$48 per year). Tribal Pages will not share use etc. the user content and user preserves the full ownership.
  3. wikitree.com: To any data entered on this website, user gives to the owner of the website a non-exclusive, royalty-free, worldwide, sublicenseable, and transferable license to use, copy publish, etc very much like with Ancestry.com in point 1 above.

Clearly options 1 and 3 do not satisfy my expectations. Option 2 does, however.

GEDCOM import and export

GEDCOM file format for genealogical data is de facto standard and I need as means of importing the information, I have now and to export the information, if I ever need to move to a different site or software.

For Tribalpages, I have also checked this important for me issue. Import: yes. Export: yes, as a backup function, only with paid accounts, no photos in gedcom.

Afterthought

Actually, for the parameters described above, hosting a genealogy software on my own website might be ideal (despite my earlier assumption of the opposite). Candidates:
  • TNG or The Next Generation, $25 or less, one time cost, proprietary license.
  • webtrees - a free GPL-licensed PHP-written software. Comparing to TNG, it misses only WordPress integration, duplicate finder (there partial for this) and possibly a photo gallery (it supports photos, of course, though).

Both softwares have GEDCOM support and both require a web hosting service, LAMP hosting would be sufficient. But finding a reasonable web hosting service, not too expensive, but not a fake (by this, I mean companies, that artificially drive their price very low, but provide poor service, for example, by using insufficient hardware, or cutting off customers, whose websites generate much traffic, even if it's within the agreed bandwidth), that is a quite separate issue.

Closing

Let me know, what solution do you use to publish your family tree.

Connect Windows to Windows and to Android via FTP

Applications I Tried and Used - Conclusions

I had a need to transfer files from one laptop with windows to another, in a safe way.  The first laptop had a bad virus, removed, but I wasn't going to risk it and wanted to copy just data files and be sure that no virus gets transfered.  I chose ftp, as opposed to, for example, a USB drive, that could get infected and then infect the seconds laptop.  With ftp, I just made sure I didn't copy files that could carry a virus.

Android, I used only to diagnose the connection problem. It worked.

Windows


  • ftp server: Filezilla Grade: 5 of 5
  • firewall, option 1: built-in (Windows 7)
    Result: doesn't allow traffic to ftp server even when added to allow programs. Grade: 1 of 5
  • firewall, option 2: Comodo. Grade: 5 of 5

Android

  • ftp client: AndFTP. Grade: 5 of 5
  • firewall: NoRoot Firewall. 
    Result: Silently ignores connections to local network, but otherwise great. Grade: 4 of 5 
  • network monitoring: Network Connections.
    Result: Doesn't show network requests but only established connections (attempt to connect to Windows ftp server which was blocked by Windows firewall wasn't reported). This limits a usefulness. Grade: 4 of 5

Choosing a light weight Linux distro

From ...
Wanted an option to run as live CD or to install.

  • lubuntu,
  • lxse,
  • vector Linux, or
  • puppy Linux

Monday, July 13, 2015

GrooveIP, RingTo - Calling and Especially: Receiving Calls

Intro

From Android, you can and receive voice calls within continental US over VoIP, even from abroad.  The app, I use is called GrooveIP.  It's a paid but not expensive app.  Since Google Voice stopped providing free calling to continental US, GrooveIP entered into a collaboration with a company called RingTo.

How to start?

You need to open a GV account, buy and install GrooveIP, set in GV your RingTo number as forwarding number.  Contrary to suggestions found on internet, I have not setup forwarding to Google Chat, but only to my RingTo number. It looks like this:

How to send a call?

Open GrooveIP, login to RingTo, if it doesn't do it automagically (often it does) and punch the destination number.  Just like on a regular phone dialer.  The rest is straightforward as well.

How to receive a call?

Open GrooveIP and wait for the ring. If it doesn't ring, but instead you receive a voicemail email from RingTo into you gmail, there are two things to check:
  • GV forwards your call to the last active gmail login. So, don't open your gmail app after you open GrooveIP (I'm guessing, GrooveIP actually logs into gmail, too).
  • Open GrooveIP settings. Make sure the "Dial 1 on Answer" option is checked.

Tuesday, June 9, 2015

Java - Pass Object by Reference

Facts:
  • Java passes everything by value.
  • References to objects-as well.
  • As long as you use or modify the object whose reference you've got in a parm, you're good.
  • When you want to assign a new object to replace the one that was passed-in, you're for a bad surprise.  Doesn't work
  • The above case can be hidden:
private MainReturnObject getThatObject(BigDecimal extraValue) {
  ...
  extraValue = extraValue.add(BigDecimal.valueOf(7));
  ...
}
...
BigDecimal objectExtraValue;
anObject = getThatObject(objectExtraValue);

After your program exits from getThatObject(), you'll find that extraValue = 0.0.  The method has modified the getThatObject's copy of the reference to objectExtraValue.

Wednesday, April 29, 2015

SVN - Merging the Same Change

Sometimes, I seem to be getting a conflict when trying to commit a change to SVN, if someone else has already committed the same exactly change before me.

So, I create a little repo with a single Java file in it and branched it.  Let's assume the file is like this:

1:    Line1  
2:    Line2  
3:    Line3  
4:    xxx NIE yyy  
5:    Line5  
6:    Line6  
7:    Line7  

On the trunk, I have changed NIE to TAK and Line2 to XXX and committed the change.  On the the branch, I have changed NIE to TAK and Line6 to YYY and committed the change as well.  When I merged the changes in trunk into the working copy of the branch, I've got only a change of Line2 brought in.

So, the conclusion is, that an identical change is merged by SVN smoothly, even if other non-matching changes were found nearby.  Or possibly, it's not SVN but the merge tool, which in my case was the Tortoise SVN built in merge tool.

Wednesday, April 22, 2015

SVN Externals - Create and Edit in Tortoise SVN Client

SVN let's you create links inside the repository.  For example, if with your project A you always need a module B, which is in another part of the SVN repo, you may want to create a svn:external to B in A.

Steps:
  • open the project A in repo browser
  • right-click on the project and select properties
  • click New->Externals to create a new one or select it and click Edit to modify an existing one
  • point the external to B and carefully consider whether you want to point it to the HEAD or to a specific version; the latter will make your project A always build regardless of what happens with project B
The same dialogs you can access from windows menu of folder A of the working copy, from the Subversion tab. Once you're there, click on Properties.

Monday, April 20, 2015

Open Source Repositories over Time

First, there was Source Forge.  It was big, as if open source was invented there (well, other than linux).  Then, it faded into the past (security issues?).  Google Code became the thing.  This year, Google Code is closing.  GitHub is the center of the universe.

That's how it changes:

SQL - Write Universal Querries

This post is supposed to deal with pecularities of SQL, and not one or another SQL dialect but the universal SQL, that can be ported without doing any porting to any other SQL database.


Boolean in Where-clause

If table client has a boolean column active, you may be tempted to write a query:

select * from client where active

However, to be sure it works on all databases, you better write it like this (for example, there are many other options):

select * from client where active = true

And, remember about nulls.  In general, every condition involving a variable which is not set (null) will be considered as a unsatisfied condition.

INSERT from SELECT

Sometimes, it's convenient to save a copy results of a select into the same or different table. No problem.  Here's how you do this:

INSERT INTO users
  SELECT * FROM users1 WHERE age < 18


Or, if you want just selected columns:

INSERT INTO users (id, age) 
  SELECT id, age FROM users1 WHERE age < 18

CREATE from SELECT (option: as temp table)

To create a table from select do:

CREATE [temp] table table_name as
SELECT t.name, t.id as my_id

FROM orig_table t
WHERE ...
With the "temp", the table will be auto deleted when session is killed.

I'm not sure this is standard SQL, but for Postgres for example it works just fine.

UPDATE with A JOIN

Joins can be done with an update, but the first table joined is joined the old way (link) and the next tables can be joined the new way:

The first table:

UPDATE vehicles_vehicle AS
  SET price = s.price_per_vehicle  
  FROM shipments_shipment AS
  WHERE v.shipment_id = s.id

Two or more tables joined:

UPDATE vehicles_vehicle AS
  SET price = s.price_per_vehicle  
  FROM shipments_shipment AS
  JOIN vehicles_owner o ON o.id = v.owner_id
  WHERE v.shipment_id = s.id

The standard SQL is not specific about this syntax, but for Postgres, for example, it works just fine.  For MySQL, the syntax is as follows:

UPDATE vehicle
INNER JOIN driver ON driver.vehicle_id = driver.id 
SET color = "blue";



Thursday, April 16, 2015

Substituting Voice in the Movie with Another Voice

The Task

I had a movie, in AVI format with only some random noise.  And I had a voice in an MP3 file (actually, it was a 3GP file format).  I wanted put the voice into the movie

The Method

  • Download and install VirtualDub application (I had version 1.10.4 on WinXP).
  • If you have a desired audio in a 3GP format, just rename the file by changing the file extension to MP3.
  • Convert audio to WAV (I used MusicBee for this).
  • Open the video file in VirtualDub.
  • Set the following in VD:
    • In Video menu, set Direct Stream Copy
    • In Audio menu, chose Audio from the other file and select the WAV file
    • From File menu, choose Save as AVI

 The Result

The generated AVI file was only 78.3 MB, while the original video was 76.3 MB and the WAV file was 3.85 MB.  Quality was just fine.  Sync didn't matter and I can't ass it.

Monday, January 5, 2015

Usefull linux commands

  • find folderABC -mtime -9 -- show files in and below folder ABC modified less than 9 days ago
  • find ~ -name font* -print  -- show files and folders in my home folder and below starting with the work 'font'
  • find . -type f \( -iname *.jpg -o -iname *.jpeg \)  -- find only files with extension jpg or jpeg
  • find . -type f -path ./.config -prune -false -o -iname.jpeg  -- skip files with and 'Android' in path
  • ps
    • ps aux | grep myprocesspartialname - not no '-' before the options
    • /bin/ps -context -www -p processID -- shows wide command line for the process
  • svn status | grep '^M' -- shows files modified in the current SVN copy
  • svn diff -r HEAD fileABC -- compares the file ABC to its most recent version in the repo
  • zip+unzip:
    • unzip zip-file -d destination-folder  -- unzip a file
  • tar+gzip:
    • tar -ztvf file.tar.gz -- list contents of gzipped tar archive file.tar.gz
    • tar -czf file.tar.gz file1 file2 file3 -- create a gzipped archive file.tar.gz with three files in it
    • tar -xzf tar-file-name.tar.gz
  • bzip2
    • to unpack a bz2 file use command:  bzip2 -dk filename.bz2
  •  vim:
    • search - just like in vi, by hitting / you can search by specifying a regex pattern
    • to search for a whole word: \<...\>
    • to escape a special char, for example to search for a path, do: \/opt\/jboss
    • to cut lines into a vim internal clipboard, use dd command.
    • option :set-nowrap turns of the default, and sometimes annoying, line wrapping
    • to toggle word wrapping, use command:  :set wrap!
    • to do case-ignore search do /\cAlicja, and to do case sensitive search use \C
    • to mark a location type m L, where L is any letter, e.g. m a, and to move back to this location type: ' L (single apostrophe)
    • to place the current line at the top, center or bottom, hit zt, z., or zb.
  •  symbolic link: ln -s target link-name
    To me, it seems backward, but I guess you can say it like this: take target and call it link-name 
  •  folders
    •  remove: rm -r folder-name
      (note: rmdir will delete only an empty folder)
    • copy: cp -r folder-name dest-folder-name
    •  with -f option, you can avoid any questions 
    • by convention: folder/* means contents of the folder, while folder/ means all of the folder 
  • diff files and folders
    •  -wBb file1 file2 -- diff two files with all whitespaces ignored (new lines are not ignored-this is a much more complex problen, even just conceptually) 
    • -r dir1 ird2 -- recursively, shows files found only in one of the trees, for binaries shows message "files different"
  • du which tells "how much of the precious space does a this folder or files use":
    • du -sh my-folder/*  -- shows size of all files and folders in my-folder folder, one number per file/folder
  • df -h  which shows you the list of the files systems and which of them full if any.
  • grep
    •  ignoring the useless Permission denied entries.  Can be done using a redirection: grep my-cat-Lois my-folder/Lois-files 2> /dev/null
    • with a regex.  The simplest regex to find one or more tabs in the file was:
      grep '^This[[:space:]]\+5' parms*.txt
    • to show only the file names, use option -l
    • to search through compressed .bz2 files, use bzgrep instead of grep
    • to search for words, use option -w
  • su and sudo  -- both can take a user as a parm (superuser by default).  The su switches to that user until you do exit, while sudo is followed by a command, that only this one command is executed in the assumed user context.  
  • chown -R jboss:jboss_grp * --  change ownership of all files in this folder and below to user jboss, group jboss_grp.
  • adduser username -- add a new user and add user to the group. Once the user is created, to add user to the sudo group, repeat the same command with one more argument at the end: sudo
  • usermod -a -G sudo jdoe  -- add user to group sudo
  • passwd user1 -- change password for user1. Use option -e to have force user to change it at the first login.
  • awk -F '\t' ' /^Product\t/ {print $7} ' file.txt 
    • -F - Tab as a separator (deault: spc)
    • '...'  - program, inline  
    • default program structure: condition action
    •  Together: above command prints 7th (tab-separated) element of all lines of file file.txt that start with 'Product\TAB'
    • a bit more complex script:  { if( $0 ~ /^Fund\t/ && $10 == "False") {print $13} } -- It prints 13th element of the record, but only for lines starting with 'Fund', where the element 10th is 'False'.
    • and, if you need to process mutliple files, one option is a shell script:
      #!/bin/bash
      for var in $(ls /var/GOLL/import/exportPP_*.txt); do
        ls -l $var
        awk -F '\t' ' { if( $0 ~ /^Fund\t/ && $10 == "True") {print $3, $6, "ClosedDate:", $8, $10, $11, $12, $13} }' $var
      done
  • dmsg  show system messages, e.g. out-of-memory errors and processes killed as a result
  • working in command line:
    • to find a previous command you can use Ctrl-R (reverse search) 
  • less, tail and vim - you can open a file to view anypart of it using vim-like commands and switch to the 'tail -f' mode with Ctrl-F.  Then, Ctrl-C will take you back to viewing the whole file.
  • mkdir -p /var/dir1/dir2  -- create directory with all its missing parents
  • getfacl folder  -- show details of custome access specs for a folder (it shows as + on the long directory/file listing)
  • cat /etc/*release  -- show the name and version of the OS

Groups

  • groups [user]  -- show groups that user belongs to (by default - this user)
  • groupadd grouptoadd  -- creates a new group
  • cat /etc/group  -- shows one line per group with all its members; grep the list as needed
  • gpasswd -a user group  -- adds user to the group (-d for delete from the group)