Categories
Java

JRE

The Java Run-time Environment, aka Java Virtual Machine (VM).

This is automatically installed when you install the JDK.

It’s bits are installed in the \jre directory inside the jdkx.x.x_xx directory.

Categories
Java

Java Cookbook

Java Language Features

Packages

Packages work like Namespaces do in C++.

Packages provide an elegant way to name groups of related classes, and the classes within a package have package-private access by default (i.e., visibility scoped to the package level).

Default Visibility

Classes

Default: package-private.

To get a class to appear in the docs (using JavaDoc), you must make it public (explicitly).

Class Members

Default: package-private.

public: The member can be accessed

private: The member can be accessed from within its own class only.

protected: The member can be accessed from within a subclass in another package.

Categories
XSL XSL Languages

XSLT Development Environments

Adobe Dreamweaver

Drag & drop XML schema elements from the Bindings panel, onto the Design view, not the code view. When you do this, the statement that appears in the code view is properly tagged as <xsl:value-of select=”Bla bla bla”/>

In a repeating region, the expression for the repeated element isn’t the full-qualified name of the element. It is simply the name of the element (its local name).

<xsl:for-each select="project/file/class/property">
        <p><xsl:value-of select="name" disable-output-escaping="yes"/></p>
</xsl:for-each>

In oXygen XML Editor

Use Master Files as containers to manage housekeeping for things like intellesense (Content Completion Assistant), includes, validation, etc.

These are the XSL files that are not imported or included in other files. The files that included or imported are known as Modules. You can have multiple Master Files in your project, and each Master File can include references to files that are common to other Master Files.
As a rule of thumb, break large XSL files into multiple files, and use one of them to include the others.

Ctrl+Click on a template name in an XPath expression in an XSL file – to find out where it is included elsewhere in the project.

“Component Dependency Helper” – Click the little light bulb that appears in place of the line number.
To search for declarations and references, and to rename components.

When Creating an XSL

When you use oXygen to do this, it automatically creates an XSL file that contains all the needed namespace declarations.

When you save the XSL file, set the transformation scenario. All you have to do is select the XML file for the source (the document with the current focus will automatically become the XSL file).

You can creates templates easily by dragging and dropping nodes from the XSLT/Query Input pane!

Debugging Transformations

In the XSLT Debugger Perspective, click the blue right-arrow to run the transformation (Run), not the Run to End.

Enable XHTML output.

Then you can double-click parts of the HTML output to see where the part of the XSL file that generated it.

You can also double-click line items in the Output Mapping Stack to highlight the associated line in the XSL file.
Think of the Output Mapping Stack as a trail of breadcrumbs.

To see the transform in process, set breakpoints, and click Run.
This is better than stepping through the code, one line at a time.

Conditional Breakpoints

Open the Breakpoints tab.

You can set breakpoints that evaluate to boolean results.

Scenario-based XSLT Debugging

This allows you to specify which files to use for the input XML

From the Editor perspective, click the Debug Scenario button.

Folding

You can add “foldable”, “folded”, and “not-foldable-child” declarations to CSS rules for style selectors.

E.g.,

sect1
{
        foldable: true;
        not-foldable-child: figure;
}

figure
{
        foldable: true;
        folded: true;
        not-foldable-child: title;
}
Categories
XSL XSL Languages

XSLT

XSL is the programming language used for creating XSL style sheets, for:

  • creating new documents of various types, based on the content in source XML documents,
  • processing the data they contain, and
  • applying customizations (not to be confused with format styling).

XSLT is the most important part of XSL. It uses XPath to navigate the XML tree structure (nodes), to find and access the XML content (node sets).

XSLT Stylesheet Elements

Element Description
<xsl:template match=”/”/> Defines a template to match a node from the input stream (making it the current element).
<xsl:value-of select=”title”/> Defines the node to match, and then extracts its value.
<xsl:for-each select=”catalog/cd”/> Defines a collection of nodes to match, and then loops through them.
<xsl:sort select=”artist”/> Used to sort the output. Meant to be used within the <xsl:for-each/> loop.
<xsl:if test=”price &gt; 10”/> Used to refine the match by filtering-out content.
<xsl:choose/> Used to refine the match in specific cases (by filtering-out content).
<xsl:when test=”price &gt; 10”/>  
<xsl:otherwise/>  
<xsl:apply-templates/> Applies a template to the current element or to the current element’s child nodes.
Include vs. Import

Both of these directives bring more templates into the current stylesheet. The difference between them lies in how conflicts are handled when both stylesheets contain templates that the exact same node.

<xsl:include href=”fixup_href.xsl”/> Use include when you want imported stylesheet’s templates to be used.

<xsl:import href=”common.xsl”/> Use import when you want the current stylesheet’s templates to be used. I.e., imported stylesheets are always overridden. An import element must always be a top-level element, and must always come before any other elements.

XSL Parameters

A template takes a paramater when you declare a parameter, but you don’t initialize it.
E.g., <xsl:param name=”tableTitle”/>

Modules

A module is an XSL file that you intend to include in the main stylesheet.

Each module defines generic XSLT parameters and templates that can be used from different stylesheets.

E.g.,

<xsl:import href=”params.xsl”/> <xsl:import href=”common-code.xsl”/> <xsl:import href=”page-layout.xsl”/>

Use the Validation Scenarios to validate such compound/interconnected XSL stylesheets.

Categories
XSL XSL Languages

XPath

You have to know XPath, in order to understand XSLT. XPath is the language used for searching through an XML source document, and finding & copying pieces of information (node sets). XPath uses RegEx-like expressions for extracting data from an XML source.

Selecting Nodes

See: http://www.w3schools.com/xpath/xpath_syntax.asp

nodename Selects all nodes with the name “nodename”. / Selects from the root node. // Selects nodes in the document from the current node that match the selection no matter where they are. . Selects the current node. .. Selects the parent of the current node. @ Selects attributes.

bookstore Selects all nodes with the name “bookstore” /bookstore Selects the root element bookstore

Note: If the path starts with a slash ( / ) it always represents an absolute path to an element!

bookstore/book Selects all book elements that are children of bookstore //book Selects all book elements no matter where they are in the document bookstore//book Selects all book elements that are descendant of the bookstore element. //@lang Selects all attributes that are named lang

XPath Predicates

Used to find specific nodes.

Predicates always appear inside brackets “[]”.

/bookstore/book[1] Selects the first book element that is the child of the bookstore element. /bookstore/book[last()] Selects the last book element that is the child of the bookstore element

Selecting Unknown Nodes

These are the XPath wildcards.

\* Matches any element node. @* Matches any attribute node. node() Matches any node of any kind.

/bookstore/* Selects all the child nodes of the bookstore element. //* Selects all elements in the document. //title[@*] Selects all title elements which have any attribute.

Selecting Several Paths

By using the | operator in an XPath expression you can select several paths. You use the | operator to combine XPath expressions.

Note: In XPath, you use the “OR” operator for AND’ing (sort of like bitwise OR’ing is actually AND’ing.).

//book/title | //book/price Selects all the title AND price elements of all book elements. //title | //price Selects all the title AND price elements in the document. /bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document.

Notes

You might get tripped-up by the use of the OR operator. The “Logical OR” operator “|” and the work “or” (as used in Axes definitions (like “parent or self”) are used to include more paths in the selection. OR means “Either case matches”. There really is no use for AND in matching paths!

XPath Axes

An XPath Axis specifies the tree-relationship between the selected nodes and the current node.

ancestor Selects all ancestors (parent, grandparent, etc.) of the current node. ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself. attribute Selects all attributes of the current node. child Selects all children of the current node. descendant Selects all descendants (children, grandchildren, etc.) of the current node. descendant-or-self Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself. following Selects everything in the document after the closing tag of the current node. following-sibling Selects all siblings after the current node. namespace Selects all namespace nodes of the current node. parent Selects the parent of the current node. preceding Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes. preceding-sibling Selects all siblings before the current node self Selects the current node

Location Path Expression

A location path can be absolute or relative.

Each step is evaluated against the nodes in the current node-set.

An absolute location path starts with a slash ( / ) and a relative location path does not. In both cases, the location path consists of one or more steps, each separated by a slash:

Absolute
/step/step/...
Relative
step/step/...
A step consists of
  • an axis (defines the tree-relationship between the selected nodes and the current node).
  • a node-test (identifies a node within an axis).
  • zero or more predicates (to further refine the selected node-set).
Location Step Syntax

axisname::nodetest[predicate]

Path Expression Example Description
child::book Selects all book nodes that are children of the current node.
attribute::lang Selects the lang attribute of the current node.
child::* Selects all element children of the current node.
attribute::* Selects all attributes of the current node.
child::text() Selects all text node children of the current node.
child::node() Selects all children of the current node.
descendant::book Selects all book descendants of the current node.
ancestor::book Selects all book ancestors of the current node.
ancestor-or-self::book Selects all book ancestors of the current node – and the current as well if it is a book node.
child::*/child::price Selects all price grandchildren of the current node.

XPath Operators

An XPath expression returns either a:

  • node-set
  • string
  • Boolean
  • number
Symbol Meaning Example Result
  Computes two node-sets //book | //cd Returns a node-set with all book and cd elements.
  •  
Addition 6 + 4 10
  •  
Subtraction 6 – 4 2
  •  
Multiplication 6 * 4 24
div Division 8 div 4 2
= Equal price=9.80 true if price is 9.80, false if price is 9.90.
!= Not equal price!=9.80 true if price is 9.90, false if price is 9.80.
< Less than price<9.80 true if price is 9.00, false if price is 9.80.
<= Less than or equal to price<=9.80 true if price is 9.00, false if price is 9.90.
> Greater than price>9.80 true if price is 9.90, false if price is 9.80.
>= Greater than or equal to price>=9.80 true if price is 9.90, false if price is 9.70.
or or price=9.80 or price=9.70 true if price is 9.80, false if price is 9.50.
and and price>9.00 and price<9.90 true if price is 9.80, false if price is 8.50.
mod Modulus (division remainder) 5 mod 2 1
Categories
XSL

XSL Cookbook

Extensible Style Sheets are for XML, what Cascading Style Sheets are for HTML. XML content.

The transformation process is the automated process of copying the information from the source XML document, processing it (e.g., running calculations on it, sorting it, filtering it, etc.), writing the processed information into a new document of a particular presentation type (XML, HTML, XHTML, PDF, CHM, etc), and then applying custom rendering to it (format styling).

Background

Unlike HTML content, is ambiguous outside of the content of it’s schema (namespace). Therefore, Extensible Style Sheets are written in a language that allows the XML content to be described generically, and redefined (transformed).

If you think of the process of applying style sheets to HTML content as passive, then it makes sense to view the process of applying style sheets to XML content as active. Since you can do so much more with an XML file than simply style it, the name Extensible Style Sheet is misleading.

The terms are confusing

XSL used to refer to the programming language used to program Extensible Style Sheets. Now, the term XSLT is used instead. It stands for “Extensible Stylesheet Language Transformation”. “xsl” is the file extension for Extensible Style Sheets, and it is also used as the XSLT namespace.

The term “Transformation” is misleading. The transformation process doesn’t actually transform XML content (it doesn’t alter the source file).

XSL now refers to a family of three languages

And they all play a part in the transformation process: XSLT, XSL-FO, and XPath.

XSLT – the language for transforming source XML content.

XSL-FO – the language for formatting output content.

XPath – the language for navigating source XML content. XSLT uses XPath to define RegEx-like expressions to match parts of the source XML document. XSLT defines one or more transformation templates, for processing matches; each one with a different XPath match definition.

Rendering in a Web Browser

After you create an XSL style sheet for a particular XML file, you can put the XML file up on the web, and it will render according to the style sheet if you embed a reference to the style sheet, within the XML file. This is because modern web browsers can process XSL Transforms (just like Saxon).

Categories
JavaScript TypeScript

TypeScript Cookbook

TypeScript is a programming language that is a superset of ECMAScript 6. TypeScript was created to address the shortcomings of JavaScript for the development of large-scale applications by extending JavaScript with the addition of static typing. This enables static language analysis, which in turn facilitates tooling and IDE support (which makes programming so much easier!).

I suspect that Microsoft developed the Visual Studio Code IDE specifically with TypeScript development in mind. When you develop TypeScript code in Visual Studio Code, you get IntelliSense, and you can set breakpoints and can step through the code just like you can with C# and C++. Within the IDE, the TypeScript service provides code complete suggestions, and it flags syntax errors.

Note: When you use Visual Studio Code for your TypeScript development, you must install the TypeScript compiler (tsc). To install it, simply open an administrative command prompt and enter the following command: npm install -g typescript. Note that Visual Studio Code’s TypeScript language service is separate from the TypeScript compiler.

Like ECMAScript 6, TypeScript also supports classes, modules, interfaces, namespaces, enumerations, generics, tuples, and lambda syntax.

Key concepts

The act of typing is the association of a data type with a sequence of bits. TypeScript provides static typing through type annotations to enable type checking at compile time. The annotations for the primitive types are numberboolean and string.

The TypeScript compiler compiles TypeScript files (*.ts) into JavaScript files (*.js). TypeScript also supports definition files (*.d.ts), that contain type information of existing JavaScript libraries (similar to header files in C++).

  • Weakly typed = dynamic typing.
  • Strongly typed = static typing.

Example

function add(left: number, right: number): number {
    return left + right;
}

Declaration files

When you compile a TypeScript script, there is an option to generate a declaration file (with extension *.d.ts) that serves as an interface to the components in the compiled JavaScript. The compiler removes the function bodies and keeps just their signatures, which includes type details. You declaration files are then used by third-party developers when they integrate your code.

Example

declare var foo: number;

declare function greet(greeting: string): void;

declare namespace myLib {
    function makeGreeting(s: string): string;
    let numberOfGreetings: number;
}

declare function greet(setting: GreetingSettings): void;

declare class Greeter {
    constructor(greeting: string);
    greeting: string;
    showGreeting(): void;
}

tsconfig.json

Generally, the first thing you do when starting a new TypeScript development project is to create a project configuration file called tsconfig.json. It contains settings in JSON format, that specify such options as the target compiler, and where to output files.

Example

{
    "compilerOptions": {
      "target": "es6",
      "module": "commonjs",
      "sourceMap": true
    }
}

Notes

To run a TypeScript program, you first transpile it into JavaScript (tsc HelloWorld.ts), and then you execute the resulting JavaScript file with node (node HelloWorld.js).

Categories
JavaScript

JavaScript Functions

Functions in JavaScript have really changed over the past ten years or so.

Function Declarations

Defining functions using declarations used to be the the usual way of using functions. Declared functions are not executed immediately. They are executed later when they are invoked.

Example

function myfunction(a, b) {
    return a * b;
}

myfunction(2, 3);

Anonymous Functions

You can define a function without a name. Such functions are known as anonymous functions.

Example

You can pass an anonymous function as a parameter in another function call.

setTimeout(function() {
  alert('hello');
}, 1000);

Function Expressions

You can also define an anonymous function using an expression, and you can store a function expression in a variable. You invoke the function by stating the variable name followed by a set of parenthesis and a semicolon.

Example

var sayhi = function() {
    alert('Hello World!');
}

sayhi();

But what problems do function expressions solve? Why were they added to the JavaScript language?

Closures

When you wrap an anonymous function definition in a set of parenthesis, you can invoke it by appending a set of parenthesis to it, followed by a semicolon.

Example

(function() {
    alert('foo');
})();

Lambdas

Lambdas provide a shorthand for creating anonymous functions.

Example

An anonymous function with one argument x that returns x + 1.

x => x + 1

Example

As above, but with a function body.

x => {return x + 1}

Example

A two-argument lambda function.

(x, y) => x + y

Example

Same as above, except with a function body.

(x, y) => {return x + y}
Categories
Git How to Reference

Notes on a Successful Git Branching Model

This refers to the explanation on the web site A Successful Git Branching Model. It was only after reading this article that Git really started to make sense to me. It’s an application of Git, and it seems that Git only makes sense within this context.

  • In this branching model, there are only two branches that live forever.
    • master
    • develop
  • origin/master
    • Where the source code of HEAD always reflects a production-ready state.
  • origin/develop
    • Where the source code of HEAD always reflects a state with the latest delivered development changes for the next release.
    • This branch is also known as the Integration branch.
    • This is where automatic nightly builds are built from.
  • When the source code in develop reaches a stable point and is ready to be released, all of the changes are merged back into master, and then tagged with a release number.
    • By definition, each time changes are merged into master, it’s a new production release.
Categories
Git Reference

Notes from Git for Ages Four and Up

Here are my notes from watching the video Git for Ages Four and Up. It contains a really good expanation of how Git works under the hood. The speaker (Michael G. Schwern <schwern@pobox.com>) created a new repository, and then created a new file, added some text to it, saved it, closed it, then added it to the Staging Area, and then committed it.

git add

  • Adds a file your working directory, to the staging area (the Index), as a BLOB.

git commit

  • Creates a “Commit” object from that BLOB.
    • That somehow points to the files that are stored in Git.
      • The commit contains all of the files in the repot – not just the ones that were just staged.
  • And attaches two labels (“References”) to it.
    • HEAD
      • The name of the most recent Commit.
      • Always points to the tip of the branch that you currently have checked-out.
    • MASTER
      • The name of the currently checked-out Branch.
      • The one that advances upon “git commit”.

When you create a branch

  • All Git does is attach a new branch label to the Commit currently pointed to by HEAD.

When you perform a “git checkout”

  • Git merely switches which branch it’s going to advance when you perform a “git commit”.
    • We say the branch becomes active.
  • And it moves HEAD to the commit object that has that branch label.
  • Git populates your Working Directory with a snapshot of the branches tip commit..

Commit ID

  • Content + Author + Date + Log + Previous Commit ID.
  • A hexadecimal UUID (Universally Unique Identifier).
  • Is a checksum (Hash)
  • Git calculates this value by running the bits in the BLOB through a function, which produces a thirty eight digit hexadecimal value.

Staging Area (Index)

  • Allows you to build up a commit.
  • You can add multiple files to the index, and then commit them (i.e., all files as one commit object).

The basic Git workflow

  • You isolate your work from everyone else’s (spawn a new branch to work in).
  • Do some work (modify one or more files).
  • Update from everyone else (pull from origin).
  • Commit your work to your local enlistment (commit).
  • Finally, you share your work with everyone else (push to origin).

Merge

  • git checkout your local master (feature/api_doc).
    • You’ll be bringing your work back into this branch.
  • Git performed a Fast Forward.
    • Since no merging of content (all modifications added new content).
      • A merge object wasn’t created.
    • All Git did was move the branch label to the commit from the ‘from’ branch.
    • Git also moved the HEAD label, because you have that branch checked out.

git reset –hard HEAD^

  • This undoes the last commit.
  • But all it does is move reference labels!
  • Moves the current branch label (Master), back one commit to HEAD-1.
  • –hard does a checkout, so that you end up where you want to be.

git log –graph –decorate –all

git commit does not mean share (inflict).

  • Commit is a local operation.

Merge

  • Git can merge in many different ways.
  • It picks the most convenient way.
  • Fast Forward is the simplest.

Working with others

  • This is where remote repositories comes in.
    • remote commands.
      • Push, Fetch, and Pull.

Clone

  • You normally start working on a clone of an existing repository.
  • When you clone a repository, git attaches labels to the objects in your local repository to mark the tracking branches.
  • origin/MASTER
  • Git clones only origin/MASTER (the default branch).

Directed Acyclic Graph

  • Graph – a collection of nodes and edges.
  • Directed – the edges all point to the previous node.
  • Acyclic – there are no cycles. I.e., the path from one commit to any other is unique.

Pull

  • Is actually a Fetch followed by a Merge.
  • When you’re starting out, it’s often easier to do a pull as two steps (a fetch followed by a merge).

We’re going to create a third repository

  • So we can have someone other than us, doing work.

We’ll create a new branch called “bugfix”

  • And we’ll create a new file in it called “baz”.

git push origin bugfix

  • Sometimes you have a space between “origin” and “bugfix”, and sometimes you have a slash between them.
    • The slash version refers to the label (origin/bugfix) on your repository. This is a reference to a tracking branch.
    • The space version refers to the remote (origin) branch (bugfix).

Push

  • Does two things.
    • Git checks to see if the remote repository has the commit object your pushing.
      • If it doesn’t, then it checks to see if it has the ancestor commit object(s).
      • If it does, then
        • Git sends over the commit object (plus a branch label, if it’s on a new branch).
      • If it doesn’t, then
        • Git send all of the ancestors + the commit object.
  • This is where the cool thing about IDs comes in (this is why git is so amazingly fast).
    • Every ID is unique.
    • Every commit is unique.
    • Commits never change.
    • This means that every commit can be uniquely identified by its ID.
    • Since IDs contain the ID of the previous commit,
      • Every commit’s history can be uniquely identified by its ID.
      • Two devs push to the same repo without pulling…
        • If I have ae123, and you have ae123,
          • Then we know everything from ae123 on down is exactly the same.

Tag

  • Tags are good to use when you continually jump back to a particular snapshot.
  • E.g., git tag v1.0 bfce7
  • All Git does is add a label (reference) to the commit object you want to tag.
  • Excep that tag labels never move.

git reflog

  • This is your rescue command.
  • You can use this command when something gets screwed up, to find a particular commit ID.
  • Git shows you the commits you’ve been working on lately.

You can combine git add and git commit into one step

E.g., git commit -a foo.

Rebase

  • This is a local operation.
  • Example use: instead of fixing a typo and then committing the file again, you can perform a rebase instead.
  • Git rebase doesn’t rewrite history. It writes new history (you can’t actually change history in Git).
    • Instead, git creates a whole new line of history.
  • Interactive rebase.
    • Go back two commits.
      • git rebase -i HEAD^^
      • Git says “I’m going to replay these things as if they were patches, one on top of the other.
        • Nothing happened! (because nothing changed).
      • You can “squash” a later commit into a previous commit (so the typo fix you made is written on top of the version with the typo).
        • I.e., you combine two (in this case) commits into a new commit.
        • The original two commits become detached!

Note: Once you have pushed, don’t rebase or you’ll screw up everyone else’s history! So never rebase until after you’ve pulled!