datetime – In a unix shell, how to get yesterday's date into a variable? – Stack Overflow

In a unix shell, how to get yesterday’s date into a variable?

You can use GNU date command as shown below

Getting Date In the Past
To get yesterday and earlier day in the past use string day ago:

date –date=’yesterday’
date –date=’1 day ago’
date –date=’10 day ago’
date –date=’10 week ago’
date –date=’10 month ago’
date –date=’10 year ago’

Getting Date In the Future
To get tomorrow and day after tomorrow (tomorrow+N) use day word to get date in the future as follows:

date –date=’tomorrow’
date –date=’1 day’
date –date=’10 day’
date –date=’10 week’
date –date=’10 month’
date –date=’10 year’

Source: datetime – In a unix shell, how to get yesterday’s date into a variable? – Stack Overflow
 
 
I basically google everything when making a shell script for linux.  Blame projects with component that require windows stuff which has helped me forget what I used to know about shell scripting
 
Here is a way of using GNU date which is fortunately present in the linux installed in the oracle servers where our weblogic application servers are installed.
This was used in a CRON job that had to look at a file that is stored in a directory which is formatted with yesterday’s date <YYYYMMDD>.
another useful stackoverflow link regarding the date command.
Here is the link that help me format the command in a CRON job
The secret is that % have to be escaped with \

Oracle SQL: Update a table with data from another table

First time I used a correlated update in a script I had to do.

In oracle SQL, how do I run an sql update query that can update Table 1 with Table 2’s name and desc using the same id?
This is called a correlated update

UPDATE table1 t1
   SET (name, desc) = (SELECT t2.name, t2.desc
                         FROM table2 t2
                        WHERE t1.id = t2.id)
 WHERE EXISTS (
    SELECT 1
      FROM table2 t2
     WHERE t1.id = t2.id )

Assuming the join results in a key-preserved view, you could also

UPDATE (SELECT t1.id,
               t1.name name1,
               t1.desc desc1,
               t2.name name2,
               t2.desc desc2
          FROM table1 t1,
               table2 t2
         WHERE t1.id = t2.id)
   SET name1 = name2,
       desc1 = desc2

 
 
Source: Oracle SQL: Update a table with data from another table
 
Guide to the select form found here.
 
 

Getting GVM to work in Windows using PowerShell

I’ve been trying to learn griffon and upgrading to the latest version I noticed that there is a nifty tool that can be used to install Groovy related stuff like groovy / grails/ griffon. I use ubuntu for my personal coding and was able to get it up and running quite easily.
GVM is inspired by a Ruby tool and copying such and awesome utility was a no brainer.
Having used it with my coding experiments at home I just had to have this for work.
 
The first set back is that the steps required an upgrade to PowerShell 3.0.
You just have to google PowerShell 3.0 installer and you would have to install. Just remember to pick the correct version for your OS. There are different versions for Windows 7, Windows 8 and Windows Server 2008. Remember to close any open Powershell  consoles before starting the installation.
After installation you have to check the version of PowerShell installed by typing this command within Power Shell:

$PSVersionTable.PSVersion

This will display the version of the Powershell installed:

Major Minor Build Revision
—–       —–      —–   ——–
3               0 –          1 –         1

 
Open as Administrator a PowerShell console and type this command:

Set-ExecutionPolicy RemoteSigned

This will allow you to execute scripts.
 
Run this command:
(new-object Net.WebClient).DownloadString(“http://psget.net/GetPsGet.ps1”) | iex
This will download the script from github.
Type this command to install the GVM module:

 Install-Module posh-gvm

Import-Module posh-gvm

Type this command to test:

gvm help

 
Something like this should be displayed:

Usage: gvm <command> <candidate> [version]
gvm offline <enable|disable>

commands:
install or i <candidate> [version]
uninstall or rm <candidate> <version>
list or ls <candidate>
use or u <candidate> [version]
default or d <candidate> [version]
current or c [candidate]
version or v
broadcast or b
help or h
offline <enable|disable>
selfupdate [-Force]
flush <candidates|broadcast|archives|temp>
candidate : asciidoctorj, crash, gaiden, glide, gradle, grails, griffon, groovy, groovyserv, jbake, lazybones, sp
ringboot, vertx

version : where optional, defaults to latest stable if not provided

That Which We Call A POGO, By Any Other Name

Which would you rather write, the 100-line monstrosity from Java, or the 10-line (including the import statement) Groovy version? Sure, the IDE generated most of the Java code, but in Groovy all that code comes for free, and any code not present won’t develop bugs later. The Groovy attitude is that if the IDE can do it, why can’t the compiler? Even better, you can read this one, without swimming through all that generated code, and it works with the rest of your Java code simply by compiling it. So please consider using POGOs for all your mapped data.[6]
via That Which We Call A POGO, By Any Other Name.

How to use Groovy Traits

Traits are reusable components basically set of methods or fields that you can make your class implement.
 
Why you should use them ?
You must have heard of problems of multiple inheritence when working with java and also familiar with the well known situation of what is know as ‘Diamond problem’.It says that if you have two classes B and C inherit from A, and class D inherits from both B and C. If there is a method in A that B and/or C has overridden, and D does not override it, then which version of the method does D inherit: that of B, or that of C ??
via How to use Groovy Traits.

Windows Tip: Opening Command Prompt to a specific folder from GUI

I just noticed somebody who was using windows 7 and was opening a command prompt console using start menu and typing the path.
No problem with this except there is a simpler way.
 
For windows 7 just press the <SHIFT> key and right-click the folder and choose “Open command window here”.
 
This works for shortcuts and for whenever you have a windows explorer open and suddenly need to do something from the command line.
Also if you are using Ubuntu there is a package you can install to do something similar. The package is nautilus-open-terminal.
 
For windows XP: Why the hell are you still using Windows XP? Just google it, or better yet install a newer os like the latest ubuntu.
 
 

Coding Horror: YSlow: Yahoo's Problems Are Not Your Problems

I first saw Yahoo’s 13 Simple Rules for Speeding Up Your Web Site referenced in a post on Rich Skrenta’s blog in May. It looks like there were originally 14 rules; one must have fallen off the list somewhere along the way.
Make Fewer HTTP Requests
Use a Content Delivery Network
Add an Expires Header
Gzip Components
Put CSS at the Top
Move Scripts to the Bottom
Avoid CSS Expressions
Make JavaScript and CSS External
Reduce DNS Lookups
Minify JavaScript
Avoid Redirects
Remove Duplicate Scripts
Configure ETags
via Coding Horror: YSlow: Yahoo’s Problems Are Not Your Problems.

How To: Tune the performance of Grails apps

If your developers don’t know how to squeeze performance out of your server then they should either be taught how or shown.

Tune the performance of Grails apps
For many developers, a standard Grails application works plenty fast enough, particularly with judicious use of caching. Yet there is almost always a trade-off between convenience and flat out speed. So if you need to increase the number of concurrent users that can be handled or increase the number of requests per second that are processed, read on.
But! Before you do, please remember that every application is different. Sometimes an application is slow simply because it’s executing way more queries than it needs to. For that reason, you should always profile your application to find out what’s happening. The following suggestions only really apply if you discover that it’s not your application code that’s the problem.
via How To: Tune the performance of Grails apps.

Grails Best Practices

I’ve worked with grails for about as long or maybe even longer than the author and the list looks good.

Grails Best Practices Posted by Amit Jain on Apr 03, 2012 | 3 comments Share|
I work at IntelliGrape, a company which specializes in Groovy & Grails development. This article is a basic list of best practices that our Grails projects follow, gathered from mailing lists, Stack Overflow, blogs, podcasts and internal discussions at IntelliGrape. They are categorized under controller, service, domain, views, taglibs, testing and general.
The advice here is specifically for Grails 2.0, although much of it is generally applicable.
Controller
Don’t allow the controller to take over another role. The role of a controller is to accept incoming requests, check permissions etc, ask a domain or a service for a result, give the result back to the requester in the desired format such as HTML, JSON, or XML. Keep the controller as thin as possible. Don’t perform business logic, queries, or updates within controllers.
If a controller represents a single domain class, use the standard naming convention of “<DomainClass>Controller”.
Avoid code duplication – common operations should be extracted as a closure or a method. See this blog entry for more information.
Split complex data binding into a command object. You can make command objects rich (just like rich domain classes). Creating a hierarchy of command objects can also be useful in some scenarios.
Service
A service is the right candidate for complex business logic or coarse grained code. If required, the service API can easily be exposed as a RESTful/SOAP web service.
Services are transactional by default, but can be made non-transactional if none of their methods update the persistence store.
Views
Keep views as simple as possible – avoid the temptation to put business or database logic in this layer.
Use layouts to ensure a consistent look across all, or a sub-set of, the application’s pages.
Keep your views DRY (“Don’t Repeat Yourself”). Split the repeated content into templates.
Use custom TagLibs for common UI elements.
via Grails Best Practices.