Blog

From the source directory, find all shortcuts, and copy the shortcut contents to a destination directory

PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language. Wikipedia

# Get all shortcuts

$shortcuts = gci "$srcDir\*.lnk"

cgi = Get-ChildItem  Microsoft

Gets the items and child items in one or more specified locations.

# skip existing dirs

if (Test-Path "$destPath") {

Test-Path Microsoft

Determines whether all elements of a path exist.

# copy

copy-item -Path "$srcPath" -Destination "$destRecreatePath" -Force -Recurse -Container -Exclude $exclude

copy-item Microsoft

Copies an item from one location to another.

But alas, without any indication of progress.

So, from some help on Stack Overflow

# xcopy prompts for is this a file/dir, no progress

# robocopy asks for admin perms on ntfs/audit attribs

# copy copies with progress %

# /z   : Copies networked files in restartable mode.

cmd /c copy /z $srcFile $destFile


Some screenshots of the full script in action












And the full source is on GitHub

End of document. Thanks for reading.

While writing a simple JavaScript 'class', I wanted to toggle console.logs on for development and off for production.  Normally I would create a method to wrap console.log with a debug flag, such as:

function Awesome() {
   this.debug = true;

   this.log = function(msg) {
       if (this.debug) {
           console.log(msg);    // line 6
       }
   };   

   this.log('test');            // outputs line 6

   this.doStuff = function() {
       this.log('doing stuff'); // outputs line 6
   };
}

But the line number logged is always from within the log wrapper, this.log(),
which is not overly useful.
After some searching, I ran across this StackOverflow thread
https://stackoverflow.com/a/13815846/3893727
Basically, instead of using a logging wrapper, use a function alias.

function Awesome() {

   this.debug = true;   

   if (this.debug && window.console && console.log && console.warn && console.error) {

       this.console = {
           'log': window.console.log,
           'warn': window.console.warn,
           'error': window.console.error
       };

   } else {

       this.console = {
           'log': function(){},
           'warn': function(){},
           'error': function(){}
       };
   }

   this.console.log('test');            // outputs line 18

   this.doStuff = function() {
       this.console.log('doing stuff'); // outputs line 21
   };
}    

So now Awesome is awesome with logging showing the original line number,
which is helpful for debugging.

Of course, this.console could be renamed to anything, such as this.log, this.out, etc.
And you could add the log to the window namespace so it could be used by other functions, such as window.debug or window.log, etc

End of document. Thanks for reading.

DBeaver is a most excellent Universal SQL Client
https://dbeaver.jkiss.org

“Free multi-platform database tool for developers, SQL programmers, database administrators and analysts. Supports all popular databases: MySQL, PostgreSQL, MariaDB, SQLite, Oracle, DB2, SQL Server, Sybase, MS Access, Teradata, Firebird, Derby, etc.”

You can also buy and support DBeaver, or if you need more features, at
https://dbeaver.com

“Best multi-platform database tool for developers, database administrators and analysts. Supports all popular relational databases: MySQL, PostgreSQL, SQLite, Oracle, DB2, SQL Server, MariaDB, Sybase, Teradata, Netezza, etc. Supports NoSQL databases: MongoDB, Cassandra, Redis, Apache Hive, etc.”

Note: If you can, install the latest executable DBeaver, which will give you the option to keep the program auto updated.

But if due to your company’s security policies, you are not be able to update to the latest required DBeaver or even install the DBeaver executable (exe), you can often download and use the portable versions of programs, often distributed as zip, tar, or gz files.

Or maybe you just want a portable and easy to backup version of the DBeaver.

Download the latest version of DBeaver
DBeaver 
https://dbeaver.jkiss.org/download/

Be sure to download the appropriate OS version and the zip file




Extract either download to a directory, such as 
C:\Portable\DBeaver

Note: BandiZip is a good free archive (zip) program


To run DBeaver, you must have a Java JRE installed or a portable copy.
Note: This Blog post will show you how to create a portable copy of the Java JRE
Portable Java


If using a portable version of the Java JRE, 
Edit the DBeaver configuration file to tell DBeaver where your portable version of Java JRE is located.

Open the file
C:\Portable\DBeaver\dbeaver.ini




Note: Notepad++ is a good free text editor, which can also be used portable
just download the zip or 7z version.

Add -vm and path to jvm lines in between the -showsplash and -vmargs lines
Make sure -vm is on one line, and the path to jvm.dll on the next line

..
-showsplash
-vm 
C:\Portable\jre-10.0.1\bin\client\jvm.dll
-vmargs
..

Create a shortcut to the DBeaver executable, which is in 
C:\Portable\DBeaver\



Add to the shortcut the parameter 
-data .dbeaver


This will create the DBeaver configuration in the same directory as the dbeaver.exe
C:\Portable\DBeaver\.dbeaver

Else, the DBeaver configuration will be created in your users home directory

Save and close and try to run DBeaver 

DBeaver should be up and running.

Query away!




Additional Information

Your company policies may prevent the auto downloads of required Java database drivers, which are often distributed as jar files (compressed java files)

Try to create a new database connection
Right click on the Database Navigation pane
Choose Create New Connection




Choose a database to connect to, 
in this example PostgreSQL (Postgres) was chosen

Click either Driver properties or Edit Driver Settings

If you are missing drivers or DBeaver cannot auto download them, DBeaver will notify you and the drivers will be in red



You can try setting the download proxy, if you have that information




If not, you can try to download the drivers directly.

For Postrgres, download the driver jar files from
https://jdbc.postgresql.org/download.html (42.2.2)
https://mvnrepository.com/artifact/net.postgis/postgis-jdbc-jtsparser/2.2.1 (2.2.1)
https://mvnrepository.com/artifact/net.postgis/postgis-jdbc/2.2.1 (2.2.1)

Note: These urls were found by searching for the driver name and version listed by DBeaver

Then click Add File for each jar file.
And also remove the prior entries.




That should get you Querying

End of document. Thanks for reading.
NetBeans IDE is a free and open source integrated development environment.
“Quickly and easily develop desktop, mobile and web applications
with Java, JavaScript, HTML5, PHP, C/C++ and more.”

Netbeans IDE is often just called Netbeans.

Note: If you can, install the latest executable Netbeans IDE, which will give you the option to keep the program auto updated.

But if due to your company’s security policies, you are not be able to update to the latest required NetBeans or even install the NetBeans executable (exe), you can often download and use the portable versions of programs, often distributed as zip, tar, or gz files.

Or maybe you just want a portable and easy to backup version of the NetBeans.

Download the latest version of Netbeans.

Note: Netbeans used to be developed by Oracle, but is currently moving to Apache.
Either download the latest stable version from Oracle, or the latest beta from Apache (as of this post)

Netbeans 8.2 (Oracle)
https://netbeans.org/downloads/

Be sure to switch the Platform dropdown to OS Independent Zip
Then download the appropriate environment
If in doubt, All will suffice.



Netbeans Beta 9.0 (Apache)
http://netbeans.incubator.apache.org/download/nb90/nb90-beta.html
http://netbeans.incubator.apache.org




Extract either download to a directory, such as 
C:\Portable\Netbeans

Note: BandiZip is a good free archive (zip) program

To run Netbeans, you must have a Java JRE installed or a portable copy.
Note: This Blog post will show you how to create a portable copy of the Java JRE
Portable Java


If using a portable version of the Java JRE, 
Edit the Netbeans configuration file to tell Netbeans where your portable version of Java JRE is located.

Open the file
C:\Portable\Netbeans\etc\netbeans.conf




Note: Notepad++ is a good free text editor, which can also be used portable
just download the zip or 7z version.


Find the string (CTRL F or scroll and read)
#netbeans_jdkhome="/path/to/jdk"

And change it to where you installed/extracted the Java JRE
Such as
netbeans_jdkhome="C:\Portable\jre1.8.0_161"
Or
netbeans_jdkhome="C:\Portable\jre-10.0.1"

Note the removal of the comment tag #

Save and close and try to run Netbeans

Create a shortcut to the Netbeans executable, which is in 
C:\Portable\Netbeans\bin\




Choose netbeans64.exe if you are using a 64bit OS (most likely)
else choose netbeans.exe

Netbeans should be up and running.

Program away!




Additional information

If your company policy locks down your installation options, more than likely you are on ‘less than optimal’ hardware. If your laptop or desktop only has 4gb memory, this change can help the performance of Netbeans

Edit the Netbeans configuration file again
C:\Portable\Netbeans\etc\netbeans.conf

Find the string 
netbeans_default_options

Place a comment mark # in front of it, so you can reset the configuration if need be
#netbeans_default_options

And create a new entry
netbeans_default_options="-J-client -J-Xss8m -J-Xms256m -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Djava.net.preferIPv4Stack=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled"

-J-Xss8m -J-Xms256m allows Netbeans to start up a little faster, and caps it’s memory usage.

Further details of options
https://performance.netbeans.org/howto/jvmswitches/

Additional ideas
https://stackoverflow.com/questions/229763/how-to-improve-netbeans-performance

With two semi-obvious ones being
Disable the Netbeans plugins you are not using.
Close the projects you are not working on (Netbeans keeps an index on every project opened)

End of document. Thanks for reading.