Syntax for Dynamically Generating JSON in JavaScript to be Output to HTML

Should you find yourself in a situation where you want to call a function (or method) that accepts JSON data parameters that you want to actually print to the browser to be invoked on some sort of callback (onchange, onclick, etc).

Given the following function:

doSomething(JSONparam) {
    // Something happens in here . . .
}

Here is the syntax for rendering an onclick link that is generated in JavaScript and then output to the DOM:

var $markup = ‘<a Continue reading “Syntax for Dynamically Generating JSON in JavaScript to be Output to HTML”

Simple Solution for JavaScript Object Packages and Namespaces

Most OO programers are familiar with packages.  This enables programmers to group like classes together in a logical order and provide some namespace to avoid class name collisions.

I have seen a variety of JavaScript sugar implementations that are mostly unintelligible.

I like things that are simple and easy to understand.

So, if you have a JavaScript class that looks like:

/**
 * Constructor
 */
com.ryanchapin.Base = function() {

    //
    // Constructor does something here . . .
    //
}→ Continue reading “Simple Solution for JavaScript Object Packages and Namespaces”

Solution for ‘NX service is not available’

When first installing NXServer I have seen a number of occastions when the initial run of

# /usr/NX/bin/nxserver –install

Does not necessarily work correctly and simply running the following commands has worked.

# /usr/NX/bin/nxsetup –uninstall –purge –clean

then

# /usr/NX/bin/nxsetup –install –setup-nomachine-key

If the previous uninstall/install command doesn’t work, try rpm -e nx*.rpms and reinstalling the rpms before trying to run the nxserver –install command again.→ Continue reading “Solution for ‘NX service is not available’”

Resources for Understanding Object-Oriented JavaScript

Following are some good articles/tutorial on OO JavaScript:

Continue reading “Resources for Understanding Object-Oriented JavaScript”

Creating a MD5 Hash in Java From Either a String or the Byte Value of a Long

Following is a quick example of how to generate an MD5 Hash (SHA-256, SHA-512 or any other supported hash algorithm) of either a String or the byte value of a long.  You should be able to adapt for your particular application:

package com.ryanchapin.util;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashGenerator {

    public static String createHash(long input, String hashAlgorithm) {
        // Generate a byte array from the long
        // Extract the byte value → Continue reading “Creating a MD5 Hash in Java From Either a String or the Byte Value of a Long”

Adding MultipartConfig Configuration to web.xml in JBoss 6.x for a Servlet 3.0 File Upload Servlet

If you do not want to hard-code your file upload servlet with the @MultipartConfig annotation but would rather add it to your <servlet> configuration element in web.xml, following is the syntax (add this as a child element of <servlet>):

<multipart-config>
      <location>/tmp</location>
      <max-file-size>20848820</max-file-size>
      <max-request-size>418018841</max-request-size>
      <file-size-threshold>1048576</file-size-threshold>
</multipart-config>
Continue reading “Adding MultipartConfig Configuration to web.xml in JBoss 6.x for a Servlet 3.0 File Upload Servlet”