Wednesday, December 28, 2011

Comparable vs. Comparator

http://grdurand.com/static/presentation_four/comparable.html

Classes should implement the Comparable interface to control their natural ordering.

Objects that implement Comparable can be sorted by Collections.sort() and Arrays.sort() and can be used as keys in a sorted map or elements in a sorted set without the need to specify aComparator.

« Interface »
Comparable
+ compareTo(Object) : int
compareTo() compares this object with another object and returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the other object.

Use Comparator to sort objects in an order other than their natural ordering.

« Interface »
Comparator
+ compare(Object, Object) : int
+ equals(Object) : boolean
compare() compares its two arguments for order, and returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Saturday, December 24, 2011

[Play!] tips

  1. If you do as many tasks as possible such as validation in the application instead of the database it is always easier to scale.
  2. Do not use something like the DAO pattern in Play, as this is not natural for the framework and would pretty much break its flow. The anemic domain model—pulling logic from the object into data access objects—should be an absolute no-go when developing with Play.
  3. Every HTML file in the app/views/tags directory is automatically used as a tag (such as #{loginStatus /}, which makes creating tags pretty simple.
  4. Be aware that the session referenced in the code is actually not a HttpSession as in almost all other Java based frameworks. It is not an object stored on the server side, but rather its contents are stored as an encrypted cookie on the client side. This means you cannot store an arbitrary amount of data in it.
  5. If you need more performance, there is a mechanism called FastTags inside of Play. These tags are actually compiled, as they are written in pure Java. This speeds up execution time.



[Play!] How to use URL arguments to list multiple match results ?

You can even create a List from the arguments in the URL with the following line of code in conf/routes:

GET /showUsers/{<[\0-9]+>ids}/? Application.showUsers

In your application code you know you could use a List IDs and show several users at once, when the URL /showUsers/1234/1/2 is called. Your controller code would start like this:

public static void showUsers(@As("/") List ids) {
}

This introduces some new complexity in your application logic, so always be aware if you really want to do this. One of the usecases where this is useful is when you want to use some sort of hierarchical trees in your URLs, like when displaying a mailbox with folders and arbitrary
subfolders

How do deploy Play! on CloudFoundry ...

(prerequisite ruby and gem)
> sudo gem install vmc
> vmc target api.cloudfoundry.com
> vmc login
> cd helloworld (the Play app you created)
> play install cloudfoundry-0.4
> cat conf/dependencies.yml
require:
- play 1.2.4
- play -> cloudfoundry 0.4


> play war --output=../hello --zip
> mv ../hello.war .
> vmc push
Would you like to deploy from the current directory? [Yn]:
Application Name: dmakplayhello
Application Deployed URL [dmakplayhello.cloudfoundry.com]:
Detected a Java Web Application, is this correct? [Yn]:
Memory Reservation (64M, 128M, 256M, 512M, 1G) [512M]:
Creating Application: OK
Would you like to bind any services to 'dmakplayhello'? [yN]:
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (265K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK


> vmc update dmakplayhello (to update your changes to Cloud Foundry)

Friday, December 23, 2011

How do deploy Play! on Jelastic and Heroku ...

http://www.youtube.com/watch?v=SHA5aITE7Ak

HEROKU:
1. create a helloworld app by following http://www.playframework.org/documentation/1.1/firstapp
2. > cd helloworld
3. > git init
4. create .gitignore and add folders to be ignored
5. > git add .
6. > git commit -m init
7. > heroku create -s cedar
8. > git push heroku master
...
-----> Launching... done, v5
http://growing-warrior-4634.herokuapp.com deployed to Heroku

note: if you want to change a new name instead of using growing-warrior-4634, then you can do the following.
1. helloworld> git remote rm heroku
2. helloworld> git remote add heroku git@heroku.com:david-play-hello.git
3. helloworld> git push heroku master
then the new URL will be http://david-play-hello.herokuapp.com
- or -
1. heroku rename david-play-hello --app growing-warrior-4634

JELASTIC:
1. cd helloworld
2. > play war --output=../hello --zip
3. > cd ..
4. > ls hello.war
5. Navigate to jelastic.com and login
6. Upload hello.war and deploy it under Play

Tuesday, December 20, 2011

Spring annotations - @Service and @Repository

In Spring 2.0 and later, the @Repository annotation is a marker for any class that fulfills the role or stereotype (also known as Data Access Object or DAO) of a repository. Among the uses of this marker is the automatic translation of exceptions.

@Service serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning. What this means is that you could annotate your service-layer classes with @Component, but by annotating them with @Service instead, your classes are more properly suited for processing by tools or associating with aspects, since @Service makes an ideal target for pointcuts.

@Service
public class WorldServiceImpl implements WorldService {
@Autowired
private CountryDao countryDao;
...
}
@Service - business service facade (it makes use of DAO)
@Repository - indicate that a class function as a repository or a data access object (DAO)

http://www.slideshare.net/kensipe/spring-3-annotated-development

The @Repository annotation (introduced in Spring 2.0) and @Service annotation (introduced in Spring 2.5) are specialization of the @Component annotation.
The main advantage of using @Repository or @Service over @Component is that it's easy to write an AOP pointcut that targets, for instance, all classes annotated with @Repository.
Also, the specialized annotations help to clearly demarcate application layers (in a standard 3 tiers application).
http://stackoverflow.com/questions/6256331/spring-annotations-repository-and-service

Then the only thing you need in the xml is the context:component-scan tag to tell Spring which package to scan for @Component annotations. @Repository extends @Component so @Repository is an @Component.
http://www.coderanch.com/t/61389/oa/autowired-annotation


Saturday, December 17, 2011

Where to save the hibernate.cfg.xml ?

hibernate.cfg.xml must be found in the root of the classpath when the webapp is started.

If you are using maven to build the project, put hibernate.cfg.xml in the src/main/resources directory so that when you build the war package, it will be automatically be placed in /WEB-INF/classes

If not using maven, place the file directly in your WEB-INF/classes dir

http://stackoverflow.com/questions/4934330/org-hibernate-hibernateexception-hibernate-cfg-xml-not-found

Friday, December 16, 2011

How does BigMemory hide objects from the Java garbage collector?

BigMemory achieves off-heap storage using Direct ByteBuffers, which is a feature introduced with NIO in Java 1.4 to allow zero copy buffers between Java applications and the operating system as it's not possible with memory belonging to Java heap because of unstable location.

An interesting additional property of Direct ByteBuffers is that they give access to memory that won't be managed by the Garbage Collector, hence avoiding its overhead.

Note: The point of BigMemory is not that native memory is faster, but rather, it's to reduce the overhead of the garbage collector having to go through the effort of tracking down references to memory and cleaning it up.

http://www.quora.com/How-does-BigMemory-hide-objects-from-the-Java-garbage-collector


Terracotta's BigMemory takes advantage of non-garbage-collected, off-heap "native memory," and apparently this is about 10x slower than heap-storage due to serialization/deserialization issues.

http://stackoverflow.com/questions/5863316/is-java-native-memory-faster-than-the-heap

Java VM option to setup Direct Memory Size: -XX:MaxDirectMemorySize

Tuesday, December 13, 2011

What do you use NoSQL for ?

General Use Cases:
- Bigness
- Massive write performance
- Fast key-value access
- Flexible schema and flexible datatypes
- Schema migration
- Write availability
- Easier maintainability, administration and operations
- No single point of failure
- Generally available parallel computing
- Programmer ease of use
- Use the right data model for the right problem
- Avoid hitting the wall
- Distributed systems support
- Tunable CAP tradeoffs

http://highscalability.com/blog/2010/12/6/what-the-heck-are-you-actually-using-nosql-for.html

http://www.infoq.com/presentations/Using-Spring-with-NoSQL-Databases (Spring Data)

The 10 Most Important Open Source Projects of 2011

The 10 Most Important Open Source Projects of 2011
Hadoop
Git
Cassandra
LibreOffice
OpenStack
Nginx
jQuery
Node.js
Puppet
Linux 3.0

Saturday, December 3, 2011

How to setup Maven home in IntelliJ ?

http://devnet.jetbrains.net/thread/278634

A valid Maven installation should contain bin/m2.conf

$ sudo find / -name m2.conf
/home/david/.hudson/maven/slavebundle/bundled-maven/bin/m2.conf
/home/david/tools/springsource/maven-2.2.1.RELEASE/bin/m2.conf
/usr/share/maven2/bin/m2.conf
/etc/maven2/m2.conf

$ export M2_HOME=/usr/share/maven

Monday, October 24, 2011

Java Swing MVC

It is said that the MVC in SWING is really MV/C. What this means it that most SWING components (Views) are pre-coupled with a default Model. The programmer only needs to add a Controller (EventListener) to it, to get it to a workable state.

While this is true for most cases, but usually only for simpler components, like JButton etc. The more complex components, like JTable, JTree or JList, require you to provide them with your own custom Model to get them to a fully functional state.

Reference: http://compsci.ca/v3/viewtopic.php?t=11199

Sunday, October 9, 2011

Actor v.s. STM

Actors are excellent for solving problems where you have many independent processes that can work in isolation and only interact with other Actors through message passing. This model fits many problems. But the Actor model is unfortunately a terrible model for implementing truly shared state. E.g. when you need to have consensus and a stable view of state across many components.

Software Transactional Memory (STM) on the other hand is excellent for problems where you need consensus and a stable view of the state by providing compositional transactional shared state. Some of the really nice traits of STM are that transactions compose and that it raises the abstraction level from lock-based concurrency.

Akka allows you to combine Actors and STM into what we call Transactors (short for Transactional Actors), these allow you to optionally combine Actors and STM provides IMHO the best of the Actor model (simple concurrency and asynchronous event-based programming) andSTM (compositional transactional shared state) by providing transactional, compositional, asynchronous, event-based message flows. You don’t need Transactors all the time but when you do need them then you really need them.


Saturday, October 8, 2011

When to use case classes ?

It is very important that all messages that will be sent around in the system are immutable. The Actor model relies on the simple fact that no state is shared between Actors and the only way to guarantee that is to make sure we don’t pass mutable state around as part of the messages.

In Scala we have something called case classes. These make excellent messages since they are both immutable and great to pattern match on.


class Person {  
   def tell { 
   println( "here's a little story ..." ) 
   } 
}  
val singingPerson = new Person with Singer 
singingperson.sing
def cast( p: Person ) {     
   p match {       
   case s: Singer => s.sing       
   case _ => p.tell    
   } 
}

"Let it crash" - Scala

The “let it crash” approach to fault/error handling, implemented by linking actors, is very different to what Java and most non-concurrency oriented languages/frameworks have adopted.
It encourages non-defensive programming. Don’t try to prevent things from go wrong, because they will, whether you want it or not. Instead; expect failure as a natural state in the life-cycle of your app, crash early and let someone else (that sees the whole picture), deal with it.

reference: http://akka.io/docs/akka/1.1.3/scala/fault-tolerance.html

Scala's Unit vs Java's void

The type of the result here is scala.Unit, which is Scala's analogue to void in Java. The main difference between Scala's Unit and Java's void is that Scala lets you write down a value of type Unit, namely (), whereas in Java there is no value of type void.
(In other words, just as 1, 2, and 3, are potential values of type int in both Scala and Java, () is the one and only value of type Unit in Scala. By contrast, there are no values of type void in Java.) Except for this, Unit and void are equivalent. In particular, every void-returning method in Java is mapped to a Unit-returning method in Scala.

scala> println("Hello, world!")
Hello, world!
unnamed2: Unit = ()

Tuesday, September 27, 2011

How to build .air using adt.jar ?

bin-debug> java -jar "e:/Adobe/Adobe Flash Builder 4/sdks/4.1.0/lib/adt.jar" -package -storetype pkcs12 -keystore ..\SCP_Operator_Station.p12 -tsa none SCP_Operator_Station.air SCP_Operator_Station-app.xml SCP_Operator_Station.swf RMA.swf rma_config.xml

Sunday, July 31, 2011

Configure LOPA to run on Ubuntu 10.10 (64-bit)

Install Flex SDK on Ubuntu 10.10 (64-bit):
http://www.philliphodges.co.uk/?p=435 (note: the adl in bin folder cannot be executed because the downloaded SDK is for Mac OSX not Linux, you need to download Linux version of AIR SDK from http://kb2.adobe.com/cps/853/cpsid_85304.html and copy the the Linux version adl over to /opt/flex/bin)

Install AIR SDK on Ubuntu 10.10 (64-bit):

Debug Configuration:

Tuesday, July 26, 2011

Scala: Array vs List

Arrays are mutable objects, you can't change the length of an array after it is instantiated. You can change its element values.

val numNames = Array("zero", "one", "two") // is the same as below
val numNames2 = Array.apply("zero", "one", "two")

numNames.update(0, "ZZZ") // update array element

For an immutable sequence of objects that share the same type you can
use Scala’s List class. As with arrays, a List[String] contains only
strings. Scala’s List, scala.List, differs from Java’s java.util.List
type in that Scala Lists are always immutable (whereas Java Lists can be
mutable). More generally, Scala’s List is designed to enable a functional
style of programming.

val oneTwoThree = List(1, 2, 3)

Thursday, July 14, 2011

Setting up Flash/AIR to log trace messages to a file

Create the flashlog.txt file
Well, let Flash do it for you.

If you have Flash installed:
Go to wherever you installed Flash (usually C:\Program Files\Adobe\Flash CS4) and open the Players\Debug directory. Run the FlashPlayer.exe file. That’s it.

If you don’t have Flash installed:
Run the flashplayer_10_sa_debug.exe file you downloaded above. Again, that’s it.
This step is required because the Debug Standalone Player is what initially creates the flashlog.txt file where all of your trace() messages will end up. To verify that it’s been created, look for it (in Windows) in C:\Documents and Settings\[username]\Application Data\Macromedia\Flash Player\Logs or the equivalent if you have some different install scheme.

Reference:
http://www.thoughtlabs.com/2008/12/09/setting-up-flash-cs4-to-log-trace-messages-to-a-file/

Tuesday, July 12, 2011

Scala's result type "Unit"

A result type of Unit indicates the function returns no interesting
value. Scala’s Unit type is similar to Java’s void type, and in fact every
void-returning method in Java is mapped to a Unit-returning method in
Scala.

def test(args: Array[String]): Unit = {
var i = 0
while (i < args.length) {
println(args(i))
i += 1
}
}

Monday, July 11, 2011

Useful Addroid Tips

In Android, processes and Applications are two different things. An app can stay "running" in the background without any processes eating up your phone's resources. Android keeps the app in its memory so it launches more quickly and returns to its prior state. When your phone runs out of memory, Android will automatically start killing tasks on its own, starting with ones that you haven't used in awhile.

Reference:
http://lifehacker.com/5650894/android-task-killers-explained-what-they-do-and-why-you-shouldnt-use-them
http://www.howtogeek.com/howto/25319/complete-guide-to-maximizing-your-android-phones-battery-life/

Friday, July 1, 2011

MDT Blog Post 1 ~ 7

Reference: http://blogs.technet.com/b/johnbaker/archive/tags/screencast/

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 7 of 7)

Custom Edit the Deployment Wizard to Add a New Page In the final part of the seven part series we’ll see how we can do further customizations to the MDT deployments. We’ll use the MDT 2010 Wizard editor from CodePlex to modify our Windows Deployment Wizard . In this demonstration we...
on17 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 6 of 7)

Using Linked Deployment Points In our demonstration we have a Test deployment share that has been populated with some deployment assets suchs as application, operating systems, out-of-box drivers and packages. So how do I easily get the deployment assets I’ve tested into a production environment...
on16 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 5 of 7)

Configuring the Deployment Point to Use the Configuration Database In order for the properties populated in configuration database to be of any use, the database must be tied to a deployment point. In this demonstration we’ll look at how to configure the database rules which basically tells what needs...
on15 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 4 of 7)

Configuring Other Methods in the Configuration Database In this demonstration we’re going to go through creating examples of the other three role methods and will assign role methods created earlier: Refresh User and Managed Computer . With all methods we can associate properties settings, applications...
on12 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 3 of 7)

Configuring Role Methods in the Configuration Database Role methods are used to target a group of computers based on a variety of criteria. As you will see there are four types of methods: Computers , Role , Locations , and Make and Model . The Role method is unique in that it can be assigned to other...
on11 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 2 of 7)

Create and Explore the Configuration Database The Microsoft Deployment Toolkit has the ability use a configuration database which provides a rich opportunity for customization of an automated deployment. The configuration database is a logical extension of the configuration settings normally stored...
on10 Nov 2010

Blog Post: Advanced Deployment Scenarios using the Microsoft Deployment Toolkit 2010: (Part 1 of 7)

Reviewing the Available Options in the Deployment Workbench In this demonstration we’ll review the CustomSettings.ini file before we make any customizations to the Microsoft Deployment Toolkit (MDT) . We’ll also look at what the default experience is from the client computers perspective and step through...
on9 Nov 2010

ZTI vs LTI vs UDI

Zero Touch Installation:
http://www.microsoft.com/technet/desktopdeployment/bdd/enterprise/ZTIDFTGuide_13.mspx

Lite Touch Installation:
http://www.microsoft.com/technet/desktopdeployment/bdd/enterprise/LTDFTGuideEn_6.mspx
http://myitforum.com/cs2/blogs/cnackers/archive/2010/07/09/microsoft-deployment-toolkit-2010-lti-making-applications-mandatory.aspx

Differences between them: http://www.scribd.com/doc/50846412/24/Choosing-LTI-ZTI-or-UDI-Deployments (* look at the comparison table for UDI *)


General Deployment Guidance
This topic outlines four recommended deployment strategies:
- High-Touch with Retail Media A manual process using the installation DVD and manual configuration of each computer.
- High Touch with Standard Image A manual process using a customized system image and application configurations.
- Lite-Touch, High-Volume Deployment A mostly automated deployment with some manual interaction at the beginning of the installation process.
- Zero-Touch, High-Volume Deployment A fully automated deployment using Microsoft System Center Configuration Manager.

Reference: http://technet.microsoft.com/en-us/library/ee344846(WS.10).aspx

Thursday, June 30, 2011

MDT vs WAIK vs WDS

WDS to enable PXE booting.
WAIK to allow validation and editing of Unattend.xml files.
MDT 2010 to create and deploy WIndows 7/Windows Server 2008 images.

Reference: http://social.technet.microsoft.com/Forums/en-US/mdt/thread/5731ae3f-1802-4922-9a4f-87e48b2c2f8b/

MDT - Microsoft Deploymnet Toolkit

MDT Lite Touch Screencast: http://technet.microsoft.com/en-us/edge/Video/ff711679 (better)

MDT Zero Touch Screencast: http://technet.microsoft.com/en-us/edge/video/system-center-configuration-manager-2007-and-microsoft-deployment-toolkit-screencast (best)

MDT Setup step-by-step: http://www.scribd.com/doc/34545158/MDT-2010-Setup-Step-by-Step

MDT Demo: Deploying Windows Server 2008 R2 and Hyper-V with MDT
http://technet.microsoft.com/en-us/edge/video/mdt-demo-deploying-windows-server-2008-r2-and-hyper-v-with-mdt

MDT Demo: Using MDT to quickly and efficiently deploy WIndows 7 across your organization.
http://technet.microsoft.com/en-us/edge/video/microsoft-deployment-toolkit-mdt-demo-using-mdt-to-quickly-and-efficiently-deploy-windows-7-across-your-organization

Advanced Deployment Scenarios: http://technet.microsoft.com/en-us/edge/video/advanced-deployment-scenarios- using-the-microsoft-deployment-toolkit-2010-part-1-of-7-reviewing-the-available-options-in-the-deployment-workbench (part 1 of 7)

MDT Demo: Tols to plan and deploy Winodws 7 or Windows Server 2008 R2
http://technet.microsoft.com/en-us/edge/tools-to-plan-and-deploy-windows-7-or-server-2008-r2.aspx

MDT TechNet: http://technet.microsoft.com/en-us/library/ee376932.aspx


Reference to MAK: http://technet.microsoft.com/en-us/library/ff793438.aspx
1. Activating MAK Clients Using VAMT
VAMT allows automation of MAK deployment and activation over the network by distributing MAKs from a centralized console, as Figure 1 shows. VAMT queries Microsoft activation servers to get the number of remaining activations for a given MAK, then lists the activation status of all MAK-activated systems in the environment. This count is a snapshot in time, not a real-time count. VAMT version 1.2 is included in the Windows AIK.

2. Integrating MAKs with Deployment Workbench
Microsoft Deployment Toolkit (MDT) also provides a solution for deploying MAKs. In Deployment Workbench, administrators configure the MAK in task sequences , which add the MAK to the Unattend.xml file used during installation. Administrators can prepare the reference image for KMS activation, then, during deployment , MDT activates the installation by using a MAK as long as it does not detect a KMS infrastructure. MDT applies the MAK after installing the image.

Wednesday, June 29, 2011

How to install Adobe Reader using a MST file ?


In order to deploy Adobe Reader X using an MST file, you wil need to first extract the installation source and then use the Adobe Customization Wizard to generate an MST file.

To do this open a command prompt and run the following on your Adobe X executable.

> AdbeRdrX_en_US.exe -nos_oFOLDERNAME -nos_ne

By running that command you’ll be able to select a folder to place the installation source at. Once the source has been extracted launch the Customization Wizard for Adobe Reader/Acrobat X. Go to File, Open Package, and open the AcroRead.msi for Adobe Reader X. You can then go through and make your customizations to the application. Once you’ve finish customizing the deployment, click Transform at the top and then Generate Transform. Save the MST file in the same folder as the installation source.

Now open up the folder in which your installation source is located at, and open the Setup.ini file in Notepad. Under the [Product] section, add without quotes ” CmdLine=TRANSFORMS=”unattend.mst” ” under “msi=AcroRead.msi”.

You can now run the setup.exe and it will automatically pickup all your customizations from the MST you’ve created.


Tuesday, June 28, 2011

Windows AIK - WAIK

The Windows Automated Installation Kit (Windows AIK or WAIK) is a tool designed to help corporate IT professionals customize and deploy the Windows Vista and Windows Server 2008 family of operation systems.

Windows Automated Installation Kit (WAIK) can be used for :
- unattended Windows installations
- capturing Windows images using ImageX
- creating WinPE images

Windows Automated Installation Kit includes the following tools :
- Windows System Image Manager (Windows SIM)
- ImageX- Deployment Image Servicing and Management (DISM)
- Windows Preinstallation Environment (Windows PE)
- User State Migration Tool (USMT)

Monday, June 27, 2011

List installed 32/64 bits apps using Powershell


Output:
PS C:\tools> .\list-apps4.ps1
DisplayName

-----------
AD LDS Instance instance1
Adobe Reader X
Adobe Reader X (10.0.1)
Calculator


List installed apps without using Powershell

Putting WMIC to Work
As often, the local WMI database contains all the information we need. The simplest way of extracting the required data is via the WMI command line, wmic:

wmic product

Yes, that is all. It runs for a while and then spits out very detailed information on what is installed on the local system. If you need the information in a file for later processing, use the following variation of above command to have wmic create a CSV file:

wmic product get /format:csv > Software_%Computername%.csv


Reference: http://www.sepago.de/helge/2010/01/14/how-to-list-all-installed-applications-from-the-command-line/

How to run a PowerShell script ?

powershell.exe -File C:\my_path\yada_yada\run_import_script.ps1
-or-
powershell.exe -noexit "& 'c:\Data\ScheduledScripts\ShutdownVM.ps1'"

Note: use absolute path and no relative path.

If you are running from inside PowerShell environment then
navigate to the directory where the script lives
PS> cd C:\my_path\yada_yada\ (enter)Execute the script:
PS> .\run_import_script.ps1 (enter)

Powershell - List Programs installed on Remote Computer

Now we COULD just use a GET-WMIOBJECT Win32_Product to query installed applications but that’s only good for applications registered via the MSI (Windows Installer)

Reference: http://www.energizedtech.com/2010/09/powershell-list-programs-insta.html


Function to uninstall a program:
function uninstallapp ($x) { 
$app = Get-WmiObject -Class Win32_Product | Where-Object {
$_.Name -match "$x"
}

$app.Uninstall()
}

Sunday, June 26, 2011

Scala notes

In Scala a function value is an object. Function types are
classes that can be inherited by subclasses
. This might seem nothing more
than an academic nicety, but it has deep consequences for scalability. In fact
the actor concept could not have been implemented without
this unification of functions and objects.

Scala is more advanced than most other languages when it comes to composing
objects. An example is Scala’s traits. Traits are like interfaces in Java,
but they can also have method implementations and even fields. Objects are
constructed by mixin composition, which takes the members of a class and
adds the members of a number of traits to them. In this way, different aspects
of classes can be encapsulated in different traits. This looks a bit like
multiple inheritance, but differs when it comes to the details. Unlike a class,
a trait can add some new functionality to an unspecified superclass. This
makes traits more “pluggable” than classes. In particular, it avoids the classical
“diamond inheritance” problems of multiple inheritance, which arise
when the same class is inherited via several different paths.

Functional programming is guided by two main ideas. The first idea is
that functions are first-class values.
In a functional language, a function is a
value of the same status as, say, an integer or a string.
The second main idea of functional programming is that the operations
of a program should map input values to output values rather than change
data in place
. Another way of expressing this is that strings are immutable in Java whereas they are mutable in Ruby. So looking at just strings, Java is a functional
language, whereas Ruby is not. Immutable data structures are one
of the cornerstones of functional programming.

Friday, June 24, 2011

Domain Controller

Only domain controllers can host Active Directory. All servers that are not domain controllers must access the directory in the same manner as the workstations. They send requests for information to a domain controller, which processes the request and returns the information back to them.

Domain controllers store and maintain portions of the directory. They also have services that allow them to directly store and retrieve information from the directory. These services are referred to as the Active Directory. When you install Active Directory on a Windows 2000based server, it becomes a Windows 2000based domain controller.Reference: http://technet.microsoft.com/en-us/library/bb727049.aspx

Wednesday, June 22, 2011

IaaS vs PaaS

A major difference between IaaS and PaaS is the amount of control over the system available to users of the services. IaaS provides total control, PaaS typically provides no control. This also means virtually zero administration costs for PaaS whereas IaaS has administration costs similar to a traditional computing infrastructure.

Reference: http://cloud-computing.learningtree.com/2010/08/25/comparing-paas-and-iaas/

Sunday, April 24, 2011

Inheritance vs compositon

Why Inheritance and Not Composition?
Whenever a design pattern uses inheritance as a key element instead of composition, you need to consider the reason. To understand the reason, you need to fully understand the principle of favoring composition over inheritance as a general principle in good OOP. The principle’s established because of certain advantages of composition over inheritance, especially the composition advantage of not breaking encapsulation. However, Gamma, Helm, Johnson and Vlissides (GoF) note that inheritance also has certain advantages. One such advantage is that when using subclasses where some but not all operations are overridden, modifying the reused implementation is easier.

reference: Oreilly Actionscript 3.0 design patterns p.335

Sprite vs MovieClip

http://www.theflashstudio.net/articles/movieClips.php

Movie Clips

MovieClip merely adds the timeline capability to the Sprite class, and are reusable pieces of flash animation - consisting of one or more graphic/button symbols - thus they are flash movies within your flash movie. They have their own non-restricted Timeline (any number of layers and frames - just like the main timeline) that plays independent of the main movie's Timeline. The best thing about using movieclips is that you can control them from actionscript - you can change their dimensions, position, color, alpha, and other properties and can even duplicate and delete them.

Sprites

The Sprite class is new in ActionScript 3.0. It provides an alternative to the functionality of the MovieClip class. Sprites and Movie Clips are virtually identical in what they can hold and what they can do. Sprite is a type of DisplayObject and it is the class that MovieClip directly extends from, (so all MovieClips are Sprites). Use Sprites when you want to draw shapes with ActionScript. Sprites are generally the display object to use as they are highly functional and take little memory. Sprites do not have timelines so if you would like to create an animation contained within the display object, a Movie Clip is the display object to use.



Thursday, April 21, 2011

Flex - TileList vs Tile

The DataGroup and SkinnableDataContainer, using a TileLayout class, replace the Flex 3 technique of using a repeater and the Tile container. A repeater in Flex 3 was a simple mechanism for looping over a collection of data (such as an array), which could be used to dynamically create child display objects in a container such as a Tile.

As a general guideline, TileList is usually the more logical way to go. Using a TileList consumes less memory and produces a faster initial response, because it renders only the viewable portion of the data. As you scroll to bring more items into view, they must be rendered on the fly, causing a momentary blank spot in their place (hint: one way of mitigating this is to display a little swirling loader icon until the item is rendered), increasing the lag time between scroll movement and a repainted window.

In contrast to the way item renderers are handled by List-based components, a Tile renders all children at once, whether it’s within the dimensions of the stage’s current viewport or not. If you have a decent number of items to be rendered, be careful if you go this route, because the stage won’t paint itself until every display object (including all those renderers!) has completed the component lifecycle (see Flex in Action chapter 17 for more on this) and is ready to be displayed. On a slower connection, this could take a long time. On the plus side, once the render is complete, scrolling is seamless, with the only real limitation now being the hardware resources available (for example, scrolling fast will make CPU usage go up a lot because graphics rendering unfortunately can’t be offloaded to the graphics processor, and so the Flash Player is limited to a single thread on the main CPU to render everything on the stage).

Monday, April 11, 2011

How to run a command/script as other users ?


> runuser -s /bin/bash - ttt -c /usr/bin/top

This is also the way how daemon use to call runuser in /etc/rc.d/init.d/functions


How to run a batch as service/daemon ?

Since you are using Redhat you have a script handy which will launch a process as a daemon. The script is /etc/rc.d/init.d/functions and you could source that in your script and launch the process like this:

> . /etc/rc.d/init.d/functions
> daemon /path/to/my/script

you can use /etc/init.d/xfs as an example
/etc/rc.d/rc5.d/S90xfs is actually a soft-link to /etc/init.d/xfs

lrwxrwxrwx 1 root root 13 Jul 6 2009 S90xfs -> ../init.d/xfs

> cat /etc/init.d/xfs
...
start() {
...
daemon xfs -droppriv -daemon
...
}

Friday, April 8, 2011

Tuning IDE Hard Disk Performance

Reference: http://www.faqs.org/docs/securing/chap6sec74.html

Putting your swap partitions near the beginning of your drive, see This chart to get a better idea, may give you some acceptable improvement. The beginning of the drive is physically located on the outer portion of the cylinder, and the read/write head can cover much more ground per revolution. We typically see partitions placed at the end of the drive work 3MB/s slower using the hdparm -t command.

Performance increases have been reported on massive disk I/O operations by setting the IDE drivers to use DMA, 32-bit transfers and multiple sector modes. The kernel seems to use more conservative settings unless told otherwise. The magic command to change the setting of your drive is hdparm. To enable 32-bit I/O over the PCI buses, use the command:

[root@deep] /# /sbin/hdparm -c1 /dev/hda or hdb, hdc etc. 

This will usually, depending on your IDE Disk Drive model, cut the timing buffered disk reads time by 2. The hdparm(8) manpage says that you may need to use -c 3 for some chipsets. All (E)IDE drives still have only a 16-bit connection over the ribbon cable from the interface card. To enable DMA, use the command:

[root@deep] /# /sbin/hdparm -d1 /dev/hda or hdb, hdc etc.

This may depend on support for your motherboard chipset being compiled into your kernel. Also, this command will enable DMA support for your hard drive, it will cut the timing buffered disk reads time and will improve the performance by 2. To enable multiword DMA mode 2 transfers, use the command:

[root@deep] /#/sbin/hdparm -d1 -X34 /dev/hda or hdb, hdc etc.

This sets the IDE transfer mode for newer (E)IDE/ATA2 drives. check your hardware manual to see if you have it. To enable UltraDMA mode2 transfers, use the command:

[root@deep] /# /sbin/hdparm -d1 -X66 /dev/hda or hdb, hdc etc.

You'll need to prepare the chipset for UltraDMA beforehand. Also, see your manual page about hdparm for more information. Use this with extreme caution! To set multiple sector mode I/O, use the command:

[root@deep] /#/sbin/hdparm -m XX /dev/hda or hdb, hdc etc. 

Where XX is the maximum setting supported by your drive. The -i flag can be used to find the maximum setting supported by an installed drive: look for MaxMultSect in the output.

[root@deep] /#/sbin/hdparm -i /dev/hda or hdb, hdc etc.

/dev/hda: Model=Maxtor 7540 AV, FwRev=GA7X4647,
SerialNo=L1007YZS
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>5Mbs FmtGapReq }
RawCHS=1046/16/63, TrkSize=0, SectSize=0, ECCbytes=11
BuffType=3(DualPortCache), BuffSize=32kB, MaxMultSect=8, MultSect=8
DblWordIO=yes, maxPIO=2(fast), DMA=yes, maxDMA=1(medium)
CurCHS=523/32/63, CurSects=379584528, LBA=yes, LBA=yes, LBAsects=1054368
tDMA={min:150,rec:150}, DMA modes: sword0 sword1 *sword2 *mword0
IORDY=on/off, tPIO={min:240,w/IORDY:180}, PIO modes: mode3

Multiple sector mode aka IDE Block Mode, is a feature of most modern IDE hard drives, permitting the transfer of multiple sectors per I/O interrupt, rather than the usual one sector per interrupt. When this feature is enabled, it typically reduces operating system overhead for disk I/O by 30-50%. On many systems it also provides increased data throughput of anywhere from 5% to 50%. You can test the results of your changes by running hdparm in performance test mode:
             [root@deep] /#/sbin/hdparm -t /dev/hda or hdb, hdc etc.              

Wednesday, March 30, 2011

Gradle Init script vs Build script

On 7/07/10 7:06 AM, Rene Groeschke wrote:
> hi there,
> I would like to apply the eclipse plugin on demand via init script
> while updating my eclipse classpath.
> Is there a way to get this working and avoid the UnsupportedOperation
> exception I got while trying " apply plugin'eclipse' " ?

Init scripts delegate to a Gradle instance, rather than a Project
instance as the build scripts do. And so, when you do apply plugin:
'eclipse', you're trying to apply a plugin designed to work with a
Project instance, to a Gradle instance. Of course, the error message
should tell you this (and what to do about it, too, I guess).

At the moment, it's a bit awkward to apply a project plugin from an init
script. You could do something like:

addListener(new ApplyPluginListener())

class ApplyPluginListener extends BuildAdapter {
public void projectsEvaluated(Gradle gradle) {
gradle.rootProject.allprojects { apply plugin: 'eclipse' }
}
}

Ideally, the init script would offer something like an allprojects { }
method, to make this kind of thing simpler.



Tuesday, March 22, 2011

How to setup JAVA_HOME on Mac OSX


25
down voteaccepted

Does Snow Leopard still have /usr/libexec/java_home? On 10.5, I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:

export JAVA_HOME=$(/usr/libexec/java_home)

I haven't experienced any problems with that technique.

(Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I setJAVA_HOME to /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home.)

link|edit|flag
Snow Leopard does still have /usr/libexec/java_home. ThanksRobert Christie Aug 28 '09 at 20:40

I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.

link|edit|flag

Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):

export JAVA_HOME=$(/usr/libexec/java_home)

Add also in ~/.profile:

export PATH=${JAVA_HOME}/bin:$PATH

P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc


http://stackoverflow.com/questions/1348842/what-should-i-set-java-home-to-on-osx