Snippets

Contents

  1. Linux
    1. Create *nix timestamp
    2. Convert screencast video
    3. Cut ogv videos without reencoding with ffmpeg
    4. monitor udev events from usb port etc..
    5. Pretty Print JSON (Python installed)
    6. Pretty Print and colorize JSON (Python installed)
    7. bash/zsh use cursor up/down keys for command history up/down
    8. Execute last command as root
    9. Copy to Clipboard from Console
    10. TrueCrypt GUIless/console mount encrypted volume
    11. Enable MTP Support
    12. Convert all mp3's in a directory to aac
    13. Generate SSH Keys
    14. Find out which application runs on a given port and protocol
    15. List your hardware
    16. Directory tree comparison
    17. Recording audio from the command line to a mp3
    18. List files and dirs by size
    19. Backup directory using rsync with progress bar
    20. Debian/Ubuntu save a list of all installed packages and how to reinstall using this list
    21. Benchmarking the Network Speed between to Workstations
    22. Tell SVN not to store your password in .svn ..
    23. Execute function on shell script exit
    24. Join multiple PDF Files with GhostScript
    25. Curl send header
    26. Curl send POST request
    27. Curl get all response headers
    28. Curl send JSON
    29. Run Apache Benchmark Tool (10 Requests, 5 Concurrent)
    30. Screen detach session/ list  / reattach
    31. Join multiple videos into a single one
    32. Mount SSH filesystem with user mapping and symlinks
    33. netcat emulate http server
    34. Emulate a http server using python
    35. Emulate a mail server using python
    36. Colored and comfortable alternative to top
    37. Colorize Logs
  2. SQL
    1. Count unique / all values
    2. Partially anonymize e-mail addresses
    3. Find duplicate entries
    4. Oracle Multiple Levels of Subtotals
    5. Postgres create roles
    6. Postgres set user password
    7. Postgres change database
  3. Java
    1. Show processes
    2. Create heap dump from running process
    3. Use SLF4J and Logback
    4. CDI / Weld Logging for GlassFish
    5. Service Discovery using ServiceLoader
    6. Java FX 2 Maven Dependency
    7. Java FX 2 Fullscreen Stage
    8. WildFly Deploy via Console
    9. Patching WildFly
    10. Dynamic Proxy
    11. JAX-RS return a generic list in a Response
    12. JAX-RS / Jersey - Return a JSON Array for a Collection with a single element
    13. Increase Eclipse Memory Settings
    14. Create heap dump on OutOfMemoryError
  4. Scala
    1. SBT - Eclipse Plugin
  5. Apache Webserver
    1. Deny all methods excepting POST and GET
    2. Rewrite all aliases for a domain to a single domain
  6. Maven
    1. Colourize output
    2. Run build with 4 threads
    3. Run build with 2 threads per core
    4. Adjust java source/target version for compiler
  7. Javascript / jQuery
    1. Firebug XPath Testing Build in
    2. Create a custom jQuery selector
    3. Afterscriptexecute Event
    4. jQuery function to center an element
  8. Cascading Stylesheets / CSS
    1. Calculations
  9. Firefox
    1. Configure address bar to return search results
  10. Eclipse
    1. Favorites
    2. Template to insert a static logger instance
  11. Atlassian
    1. Disable YUI compressor
    2. Confluence - Get favourites by user
    3. Confluence - Determine the base URL
    4. Confluence - Get the context path
    5. Confluence - Using Velocity Template for a Macro
    6. Confluence - Perform a content search with restrictions
    7. Reference exported Web Resources like CSS/JS in a Velocity Template
    8. Webworks/XWorks Action - Rendering a template without the page frame
    9. Stash - Enable a Package Logger via REST
    10. JIRA - Find existing locations for web-items and web-sections
    11. Confluence - Search for Spaces by Space Label
    12. Confluence - Read User Details
    13. ActiveObjects Create Entity with NotNull Constraint
  12. Git
    1. Show changes in a dedicated date range
    2. Git Contributor Stats for a given Period
    3. Search for occurance in a commit
    4. Git ignore versioned files
    5. Git setup a server using the git protocol
  13. Misc
    1. Data Normalizing
  14. XML / XSLT / XPath / Schema
    1. XSLT Strip Namespaces for Output
 

A collection of snippets I’m using often but sometimes my brain refuses to remember ..

Linux

Create *nix timestamp

date --utc --date "2011-11-11 11:11:11" +%s

Convert screencast video

mencoder -idx input.ogv -ovc lavc -oac mp3lame -o output

Cut ogv videos without reencoding with ffmpeg

ffmpeg -i in.ogv -vcodec copy -acodec copy -ss 00:00:00 -t 00:10:00 out.ogv

monitor udev events from usb port etc..

udevadm monitor

Pretty Print JSON (Python installed)

echo '{"tutorials": 100, "url": "http://www.hascode.com/"}' | python -m json.tool

Result in the following output:

{
    "tutorials": 100,
    "url": "http://www.hascode.com/"
}

Pretty Print and colorize JSON (Python installed)

echo '{"tutorials": 100, "url": "http://www.hascode.com/"}' | python -m json.tool | pygmentize -l javascript

bash/zsh use cursor up/down keys for command history up/down

bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward

Execute last command as root

sudo !!

Copy to Clipboard from Console

Use xclip

sudo apt-get install xclip

Examples:

uptime | xclip

Clicking the third mouse button allows to paste the result in any x-application

TrueCrypt GUIless/console mount encrypted volume

sudo truecrypt -t -k "" --protect-hidden=no /path/to/encfile /path/to/mountpoint

Enable MTP Support

sudo apt-get install mtp-tools mtpfs

-> connect the device and detect vendor- and product-id

mtp-detect | grep idVendor
mtp-detect | grep idProduct

Add to /etc/udev/rules.d/55-android.rules:

SUBSYSTEM=="usb", ATTR{idVendor}=="VENDORID", ATTR{idProduct}=="PRODUCTID", MODE="0666"
sudo service udev restart

Connect:

mtpfs -o allow_other /media/GalaxyNexus

Disconnect:

fusermount -u /media/GalaxyNexus

Convert all mp3′s in a directory to aac

for f in *.mp3; do ffmpeg -i "$f" -acodec aac -strict experimental -ab 128k "${f%.mp3}.aac"; done

Generate SSH Keys

ssh-keygen -t rsa -C "my@email.com"

Find out which application runs on a given port and protocol

sudo fuser -n tcp 8080

List your hardware

sudo lshw

Directory tree comparison

diff -r dir1 dir2

Recording audio from the command line to a mp3

arecord -f cd -t raw | lame -x -r – outfile.mp3

List files and dirs by size

du -cks * |sort -gr

Backup directory using rsync with progress bar

rsync -h --progress --stats -r -tgo -l -p -D --update --delete-after /path/to/dir-to-be-saved /path/to/targetdir/

Debian/Ubuntu save a list of all installed packages and how to reinstall using this list

dpkg --get-selections > installed-packages
 
dpkg --set-selections < installed-packages
 
dselect

Benchmarking the Network Speed between to Workstations

sudo apt-get install iperf

On the target workstation start iperf in server mode:

iperf -s

On the other workstation start the benchmark

iperf -c SERVER_IP_ADDRESS

Tell SVN not to store your password in .svn ..

svn command --no-auth-cache

Execute function on shell script exit

#!/bin/sh
# exit function
onExit() {
   # do something here .. cleanup etc ....
}
# bind exit function
trap onExit ERR EXIT
 
# here's the normal code to be executed

Join multiple PDF Files with GhostScript

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output_file.pdf file1.pdf file2.pdf ...

Curl send header

curl -H "headername:value" url
 
e.g. curl -H "REMOTE_USER:foo" http://developers.android.com

Curl send POST request

curl -X POST url
 
e.g. curl -X POST http://developers.android.com

Curl get all response headers

curl -i url
 
e.g. curl -i http://developers.android.com

Curl send JSON

curl -H "Content-Type: application/json" -XPOST -d '{"id":null, "title":"New book", "published":"2009-11-15T14:12:12"}' http://localhost:8080/javaee7-wildfly-liquibase-tutorial-1.0.0/rs/book

Run Apache Benchmark Tool (10 Requests, 5 Concurrent)

ab -n 10 -c 5 http://site.com

Screen detach session/ list  / reattach

Detach: Ctrl + A + D

List:

$ screen -ls
There is a screen on:
    2859.pts-0.host    (11/07/11 20:18:00)    (Detached)
1 Socket in /var/run/screen/S-user.

Reattach:

screen -r 2859.pts-0.host

Join multiple videos into a single one

mencoder -oac copy -ovc copy -o outfile infile1 infile2 ... infileN
 
# or if ls -l filename* matches the correct order ..
 
mencoder -oac copy -ovc copy -o outfile filename*

Mount SSH filesystem with user mapping and symlinks

sudo sshfs user@host.com:/path/to/directory /path/to/local-directory -o uid=1000,allow_other,follow_symlinks,transform_symlinks,workaround=rename

netcat emulate http server

sudo nc -l 80

Emulate a http server using python

python -m SimpleHTTPServer

Emulate a mail server using python

python -m smtpd -n -c DebuggingServer localhost:1025

Colored and comfortable alternative to top

if not installed: sudo apt-get install htop
 
htop

Colorize Logs

Three different tools to solve this: multitail, grc, ccze


Installation:

sudo apt-get install multitail grc ccze

multitail:

multitail logfile

grc:

grc tail -f logfile

ccze:

tail -f logfile | ccze -m ansi // or html or curses

SQL

Count unique / all values

SELECT COUNT(DISTINCT <FIELDNAME>), COUNT(ALL <FIELDNAME>) FROM <TABLE>;

Partially anonymize e-mail addresses

UPDATE <TABLE_NAME>
SET <EMAIL_FIELD>=
  INSERT(
    <EMAIL_FIELD>,
    POSITION('@' IN <EMAIL_FIELD>),
    100,
    CONCAT(FLOOR(1 + (RAND() * 100)),'@hascode.com'))
  WHERE
    POSITION('@' IN <EMAIL_FIELD>)>0;

Find duplicate entries

SELECT COUNT(*), <FIELDNAME> FROM <TABLENAME>
GROUP BY <FIELDNAME>
HAVING COUNT(*)>1;

Oracle Multiple Levels of Subtotals

SELECT <FIELD>, <otherfield..>
FROM <TABLE>
GROUP BY ROLLUP(<FIELD>);

Postgres create roles

CREATE ROLE name;
DROP ROLE name;
SELECT rolname FROM pg_roles;
\du
GRANT name TO username

Postgres set user password

ALTER USER
ALTER USER root WITH password 'xxx';

Postgres change database

\cDBNAME

Java

Show processes

jps

Create heap dump from running process

jmap -dump:format=b,file=/tmp/heap.bin 2381

Use SLF4J and Logback

Maven dependencies:

<project>
    <properties>
        <logback.version>1.0.3</logback.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
    </dependencies>
</project>

Example logback.xml:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="debug">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

CDI / Weld Logging for GlassFish

add to domaindir/config/logging.properties

org.jboss.weld.level=FINE

Service Discovery using ServiceLoader

interface MyService {}
class MyServiceImpl {}
class AnotherMyServiceImpl {}
 
ServiceLoader<MyService> serviceLoader = ServiceLoader.load(MyService.class);
for (MyService s : serviceLoader) {
    System.out.println(s);
}

Java FX 2 Maven Dependency

<dependency>
	<groupId>com.oracle</groupId>
	<artifactId>javafx</artifactId>
	<version>2.2</version>
	<systemPath>${java.home}/lib/jfxrt.jar</systemPath>
	<scope>system</scope>
</dependency>

Java FX 2 Fullscreen Stage

@Override
public void start(final Stage stage) throws Exception {
	Screen screen = Screen.getPrimary();
	Rectangle2D bounds = screen.getVisualBounds();
	stage.setX(bounds.getMinX());
	stage.setY(bounds.getMinY());
	stage.setWidth(bounds.getWidth());
	stage.setHeight(bounds.getHeight());
	[...]
}

WildFly Deploy via Console

Deploy

jboss-cli.sh --connect --command="deploy target/myapp-1.0.0.war"

Deployment Status

jboss-cli.sh --connect --command=deployment-info

Undeploy

jboss-cli.sh --connect --command="undeploy myapp-1.0.0.war"

Patching WildFly

$ sh jboss-cli.sh
You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /] connect
[standalone@localhost:9990 /] patch apply ~/Downloads/wildfly-8.1.0.Final
wildfly-8.1.0.Final-weld-2.2.2.Final-patch.zip  wildfly-8.1.0.Final.tar.gz
[standalone@localhost:9990 /] patch apply ~/Downloads/wildfly-8.1.0.Final-weld-2.2.2.Final-patch.zip
{
    "outcome" : "success",
    "response-headers" : {
        "operation-requires-restart" : true,
        "process-state" : "restart-required"
    }
}

Dynamic Proxy

package com.hascode.sample;
 
public interface SampleService {
    String printInformation();
}
 
package com.hascode.sample;
 
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
 
public class SampleServiceInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
        return "test";
    }
}
 
package com.hascode.sample;
 
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
 
public class Main {
    public static void main(String[] args) {
        InvocationHandler handler = new SampleServiceInvocationHandler();
        SampleService service = (SampleService) Proxy.newProxyInstance(SampleService.class.getClassLoader(), new Class[]{SampleService.class}, handler);
        System.out.println(service.printInformation());
    }
}

JAX-RS return a generic list in a Response

List<Book> list = new ArrayList<>();
GenericEntity<List<Book>> entity = new GenericEntity<List<Book>>(list) {};
Response response = Response.ok(entity).build();

JAX-RS / Jersey – Return a JSON Array for a Collection with a single element

Lets say you’re mapping a collection of books e.g. List<Book> books using jaxb passed as a jaxrs Response .. you may encounter a situation where you receive the following JSON output if there are many books in the collection:

{
	books:[
		{id:1, title:"foo"},
		{id:2, title:"bar"}
	]
}

But if there is only one book in the collection your receive a single JSON object instead of an array .. e.g.:

{
	books:{
		id:1, title:"foo"
	}
}

The solution is to provide a custom JAXBContext ContextResolver and advise the context always to render arrays here:

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import javax.xml.bind.JAXBContext;
 
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.api.json.JSONJAXBContext;
 
import com.hascode.entity.Book;
 
@Provider
public class BookContextResolver implements ContextResolver<JAXBContext> {
        private final JAXBContext context;
        private final Class[] types = { Book.class };
 
        public PersonContextResolver() throws Exception {
                this.context = new JSONJAXBContext(JSONConfiguration.mapped().arrays("books").build(), Book.class);
        }
 
        @Override
        public JAXBContext getContext(final Class<?> objectType) {
                for (Class type : types) {
                        if (type == objectType) {
                                return context;
                        }
                }
                return null;
        }
}

Increase Eclipse Memory Settings

In the eclipse/configuration directory edit the config.ini

--launcher.XXMaxPermSize
128M
-Xms1024m
-Xmx2048m
-XX:MaxPermSize=1048m

Create heap dump on OutOfMemoryError

-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/save/dumps

Scala

SBT – Eclipse Plugin

Add to your ~/.sbt/plugins/plugins.sbt

addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.1")

Apache Webserver

Deny all methods excepting POST and GET

RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS|HEAD)
RewriteRule .* - [F]

Rewrite all aliases for a domain to a single domain

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain3\.com [NC,OR]
RewriteRule (.*) http://mydomain.com/$1 [R=301,L]

Maven

Colourize output

export MAVEN_COLOR=true

Run build with 4 threads

mvn -T 4 clean install

Run build with 2 threads per core

mvn -T 2C clean install

Adjust java source/target version for compiler

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Javascript / jQuery

Firebug XPath Testing Build in

$x("//div/span/em");

Create a custom jQuery selector

The following selector matches all elements with a width greater than 200px. Just run the example on a website like jQuery.com in the Firebug console.

$.extend($.expr[':'], {
    widthGT200Pixels: function(elem) {
        return $(elem).width() > 200;
    }
});
 
$('div:widthGT200Pixels').css('border','1px solid red').click(function() {
    alert('The width of this div exceeds 200px');
});

Afterscriptexecute Event

Allows to hook into the execution of every script tag in a page

<script type="text/javascript">
document.addEventListener('afterscriptexecute', function(e){
  console.log('exec script:', e.target);
}, false);
</script>

jQuery function to center an element

jQuery.fn.center = function () {
    return this.css('position','absolute')
               .css('top', ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + 'px')
               .css('left', ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + 'px');
}
 
// centering an element
$('#jq-footerNavigation').center();

Cascading Stylesheets / CSS

Calculations

see also W3C draft

.container {
    width: calc(100% - 80px);
}

Firefox

Configure address bar to return search results

  1. Enter about:config in the address bar
  2. Search for the key keyword.url
  3. Modify the value for your search engine of choice .. e.g. for the google search: http://www.google.com/search?q=

Eclipse

Favorites

Spare my time when using static imports ..

Window > Preferences > Java > Editor > Content  Assist > Favorites:

com.google.common.collect.Lists
 
com.jayway.restassured.matcher.RestAssuredMatchers
 
com.jayway.restassured.RestAssured
 
org.hamcrest.MatcherAssert
 
org.hamcrest.Matchers
 
org.mockito.Mockito

Template to insert a static logger instance

Go Windows > Preferences > Java > Editor > Templates > New …

Enter logger as name and as template: private static final Logger log = LoggerFactory.getLogger(${enclosing_type}.class);

Afterwards you’re able to type logger in your code and ctrl+space gives the option to insert the logger

Atlassian

Disable YUI compressor

<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-jira-plugin</artifactId>
    <version>${amps.version}</version>
    <extensions>true</extensions>
    <configuration>
        <compressResources>false</compressResources>
        [..]
    </configuration>
</plugin>

Confluence – Get favourites by user

Using the label manager.

List getFavouriteSpaces(String username)

Confluence – Determine the base URL

Using the SettingsManager:

String baseUrl = settingsManager.getGlobalSettings().getBaseUrl();

Confluence – Get the context path

Using the BootstrapManager:

String contextPath = bootstrapManager.getWebAppContextPath();

Confluence – Using Velocity Template for a Macro

final VelocityContext contextMap = new VelocityContext(MacroUtils.defaultVelocityContext());
 
contextMap.put("key", obj); // references obj as variable named $key in the velocity template
 
VelocityUtils.getRenderedTemplate("path/to/template.vm", contextMap);

Confluence – Perform a content search with restrictions

final SearchManager searchManager // <- injected
final SearchQuery inSpacesQuery = new InSpaceQuery("DS");
final SearchQuery contentTypeQuery = new ContentTypeQuery(ContentTypeEnum.ATTACHMENT);
final SearchQuery query = BooleanQuery.andQuery(inSpacesQuery,contentTypeQuery);
final SearchSort searchSort = new CreatedSort(Order.DESCENDING);
final SearchFilter contentPermissionFilter = ContentPermissionsSearchFilter.getInstance();
final SearchFilter spacePermissionFilter = SpacePermissionsSearchFilter.getInstance();
final SearchFilter permissionsFilter = new ChainedSearchFilter(contentPermissionFilter, spacePermissionFilter);
final ResultFilter maxResultFilter = new SubsetResultFilter(20);
final ISearch search = new ContentSearch(query, searchSort,permissionsFilter, maxResultFilter);
final SearchResults results = searchManager.search(search);

Reference exported Web Resources like CSS/JS in a Velocity Template

Include this directive in the velocity template:

#requireResource("PLUGINKEY:WEBRESOURCEKEY")

Example declaration of a web resource in the atlassian-plugin.xml:

<web-resource name="Some Web Resources" i18n-name-key="some-web-resources.name" key="WEBRESOURCEKEY">
    <description key="some-web-resources.description">Some Web Resources</description>
    <resource name="some.css" type="download" location="somepath/some-min.css"/>
</web-resource>

Webworks/XWorks Action – Rendering a template without the page frame

Applying the parameter decorator=popup or decorator=none is one option.

Another option is to specify the decorator in the velocity template’s header section

<head>
	<meta name="decorator" content="atl.popup" />
</head>

Stash – Enable a Package Logger via REST

curl -u admin -v -X PUT -d "" -H "Content-Type: application/json" http://localhost:7990/stash/rest/api/latest/logs/logger/com.hascode/debug

JIRA – Find existing locations for web-items and web-sections

Their declarations can be found in <source-installation-directory>/jira-project/jira-components/jira-core/src/main/resources/webfragment/system-user-nav-bar-sections.xml

Confluence – Search for Spaces by Space Label

Label label ...
 
List spaces = labelManager.getSpacesWithLabel(label);
 
or
 
List spaces = labelManager.getSpacesWithLabel("labelString", Namespace.GLOBAL);

Confluence – Read User Details

for (String group : userDetailsManager.getProfileGroups()) {
 
System.err.println(Group:+ group + ” has keys:);
 
for (String key : userDetailsManager.getProfileKeys(group)) {
 
System.err.println(“key:+ key +/ current user’s value:+ userDetailsManager.getStringProperty(currentUser, key));
 
}
 
}
 
Group: personal has keys:
 
key: phone / current user’s value: 1234
 
key: im / current user’s value: -
 
key: website / current user’s value: www.hascode.com
 
Group: business has keys:
 
key: position / current user’s value: CTO
 
key: department / current user’s value: Technologies
 
key: location / current user’s value: Wiesbaden

ActiveObjects Create Entity with NotNull Constraint

The entity:

public interface Book extends Entity {
 
 [..]
 
 @NotNull
 
 String getTitle();
 
}

Create a new book entity:

ActiveObjects ao; // -> set via dependency injection
 
Book book = ao.create(Book.class, new DBParam("TITLE", "some title"));

Git

Show changes in a dedicated date range

git log --since=4.days --until=3.days

Git Contributor Stats for a given Period

git shortlog -s --number --since='last 2 year'

Search for occurance in a commit

git log --follow -S 'term' -- path/to/file

Git ignore versioned files

git update-index --assume-unchanged /path/to/file

Git setup a server using the git protocol

cd projectdir
git daemon --reuseaddr --base-path=. --export-all --verbose
git clone git://ipaddress/ appname

Misc

Data Normalizing

newVal = (oldVal-min) / (max-min)

Ugly Scala Example

package com.hascode
import scala.collection.mutable.LinkedList
 
object NormalizerExample extends App {
  val dataSet = LinkedList(1., 6.5, 3., 6.2, 20., 31.2, 50.2, 12., 0.24, 1.224, 2.2, 3.)
  for ((num, index) <- dataSet.zipWithIndex) {
    dataSet(index) = (num - dataSet.min) / (dataSet.max - dataSet.min)
  }
  println("Normalized: " + dataSet)
}
Normalized: LinkedList(0.01521216973578863, 0.12921819759798853, 0.05947594797769014, 0.12324029048767723, 0.3982240175619966, 0.6213992163469515, 1.0, 1.0, 0.07531115879828326, 0.40498283261802576, 0.7319742489270387, 1.0)

XML / XSLT / XPath / Schema

XSLT Strip Namespaces for Output

<xsl:stylesheet version="1.0"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:foo="http://foo"
       xmlns:bar="http://bar"
       exclude-result-prefixes="foo bar">
Search
Categories