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)

UPDATE with A JOIN

You can't do a regular join with an update.  However, the following is a nice workaround (link):


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

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
  • /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
  • 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
  •  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
  •  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 -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) 
  • du that is "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