text:
"""Generate a diffusion map embedding
"""

import numpy as np
has_sklearn = True
try:
    import sklearn
except ImportError:
    has_sklearn = False

def compute_diffusion_map(L, alpha=0.5, n_components=None, diffusion_time=0,
                          skip_checks=False, overwrite=False,
                          eigen_solver=None, return_result=False):
    """Compute the diffusion maps of a symmetric similarity matrix

        L : matrix N x N
           L is symmetric and L(x, y) >= 0

        alpha: float [0, 1]
            Setting alpha=1 and the diffusion operator approximates the
            Laplace-Beltrami operator. We then recover the Riemannian geometry
            of the data set regardless of the distribution of the points. To
            describe the long-term behavior of the point distribution of a
            system of stochastic differential equations, we can use alpha=0.5
            and the resulting Markov chain approximates the Fokker-Planck
            diffusion. With alpha=0, it reduces to the classical graph Laplacian
            normalization.

        n_components: int
            The number of diffusion map components to return. Due to the
            spectrum decay of the eigenvalues, only a few terms are necessary to
            achieve a given relative accuracy in the sum M^t.

        diffusion_time: float >= 0
            use the diffusion_time (t) step transition matrix M^t

            t not only serves as a time parameter, but also has the dual role of
            scale parameter. One of the main ideas of diffusion framework is
            that running the chain forward in time (taking larger and larger
            powers of M) reveals the geometric structure of X at larger and
            larger scales (the diffusion process).

            t = 0 empirically provides a reasonable balance from a clustering
            perspective. Specifically, the notion of a cluster in the data set
            is quantified as a region in which the probability of escaping this
            region is low (within a certain time t).

        skip_checks: bool
            Avoid expensive pre-checks on input data. The caller has to make
            sure that input data is valid or results will be undefined.

        overwrite: bool
            Optimize memory usage by re-using input matrix L as scratch space.

        References
        ----------

        [1] https://en.wikipedia.org/wiki/Diffusion_map
        [2] Coifman, R.R.; S. Lafon. (2006). "Diffusion maps". Applied and
        Computational Harmonic Analysis 21: 5-30. doi:10.1016/j.acha.2006.04.006
    """

    import numpy as np
    import scipy.sparse as sps

    use_sparse = False
    if sps.issparse(L):
        use_sparse = True

    if not skip_checks:
        if has_sklearn:
            from sklearn.manifold.spectral_embedding_ import _graph_is_connected
            if not _graph_is_connected(L):
                raise ValueError('Graph is disconnected')
        else:
            raise ImportError('Checks require scikit-learn, but not found')

    ndim = L.shape[0]
    if overwrite:
        L_alpha = L
    else:
        L_alpha = L.copy()

    if alpha > 0:
        # Step 2
        d = np.array(L_alpha.sum(axis=1)).flatten()
        d_alpha = np.power(d, -alpha)
        if use_sparse:
            L_alpha.data *= d_alpha[L_alpha.indices]
            L_alpha = sps.csr_matrix(L_alpha.transpose().toarray())
            L_alpha.data *= d_alpha[L_alpha.indices]
            L_alpha = sps.csr_matrix(L_alpha.transpose().toarray())
        else:
            L_alpha = d_alpha[:, np.newaxis] * L_alpha
            L_alpha = L_alpha * d_alpha[np.newaxis, :]

    # Step 3
    d_alpha = np.power(np.array(L_alpha.sum(axis=1)).flatten(), -1)
    if use_sparse:
        L_alpha.data *= d_alpha[L_alpha.indices]
    else:
        L_alpha = d_alpha[:, np.newaxis] * L_alpha

    M = L_alpha

    from scipy.sparse.linalg import eigs, eigsh
    if eigen_solver is None:
        eigen_solver = eigs

    # Step 4
    # v0 is the starting point for iterative computation
    # set v0 to aviod randomness
    v0 = np.ones(min(M.shape))
    func = eigen_solver
    if n_components is not None:
        lambdas, vectors = func(M, k=n_components + 1, v0=v0)
    else:
        lambdas, vectors = func(M, k=max(2, int(np.sqrt(ndim))), v0=v0)
    del M

    if func == eigsh:
        lambdas = lambdas[::-1]
        vectors = vectors[:, ::-1]
    else:
        lambdas = np.real(lambdas)
        vectors = np.real(vectors)
        lambda_idx = np.argsort(lambdas)[::-1]
        lambdas = lambdas[lambda_idx]
        vectors = vectors[:, lambda_idx]

    return _step_5(lambdas, vectors, ndim, n_components, diffusion_time,
                   return_result)

def _step_5(lambdas, vectors, ndim, n_components, diffusion_time, return_result):
    """
    This is a helper function for diffusion map computation.

    The lambdas have been sorted in decreasing order.
    The vectors are ordered according to lambdas.

    """
    psi = vectors/vectors[:, [0]]
    diffusion_times = diffusion_time
    if diffusion_time == 0:
        diffusion_times = np.exp(1. -  np.log(1 - lambdas[1:])/np.log(lambdas[1:]))
        lambdas = lambdas[1:] / (1 - lambdas[1:])
    else:
        lambdas = lambdas[1:] ** float(diffusion_time)
    lambda_ratio = lambdas/lambdas[0]
    threshold = max(0.05, lambda_ratio[-1])

    n_components_auto = np.amax(np.nonzero(lambda_ratio > threshold)[0])
    n_components_auto = min(n_components_auto, ndim)
    if n_components is None:
        n_components = n_components_auto
    embedding = psi[:, 1:(n_components + 1)] * lambdas[:n_components][None, :]

    if return_result:
        result = dict(lambdas=lambdas, vectors=vectors,
                      n_components=n_components, diffusion_time=diffusion_times,
                      n_components_auto=n_components_auto)
        return embedding, result
    else:
        return embedding

def compute_diffusion_map_psd(
        X, alpha=0.5, n_components=None, diffusion_time=0, return_result=False):
    """
    This variant requires L to be dense, positive semidefinite and entrywise
    positive with decomposition L = dot(X, X.T).

    """
    from scipy.sparse.linalg import svds

    # Redefine X such that L is normalized in a way that is analogous
    # to a generalization of the normalized Laplacian.
    d = X.dot(X.sum(axis=0)) ** (-alpha)
    X = X * d[:, np.newaxis]

    # Decompose M = D^-1 X X^T
    # This is like
    # M = D^-1/2 D^-1/2 X (D^-1/2 X).T D^1/2
    # Substituting U = D^-1/2 X we have
    # M = D^-1/2 U U.T D^1/2
    # which is a diagonal change of basis of U U.T
    # which itself can be decomposed using svd.
    d = np.sqrt(X.dot(X.sum(axis=0)))
    U = X / d[:, np.newaxis]

    if n_components is not None:
        u, s, vh = svds(U, k=n_components+1, return_singular_vectors=True)
    else:
        k = max(2, int(np.sqrt(ndim)))
        u, s, vh = svds(U, k=k, return_singular_vectors=True)

    # restore the basis and the arbitrary norm of 1
    u = u / d[:, np.newaxis]
    u = u / np.linalg.norm(u, axis=0, keepdims=True)
    lambdas = s*s
    vectors = u

    # sort the lambdas in decreasing order and reorder vectors accordingly
    lambda_idx = np.argsort(lambdas)[::-1]
    lambdas = lambdas[lambda_idx]
    vectors = vectors[:, lambda_idx]

    return _step_5(lambdas, vectors, X.shape[0], n_components, diffusion_time,
                   return_result)

if has_sklearn:
    from sklearn.base import BaseEstimator
    import scipy.sparse as sps
    from sklearn.neighbors import kneighbors_graph

    class DiffusionMapEmbedding(BaseEstimator):
        """Diffusion map embedding for non-linear dimensionality reduction.

        Forms an affinity matrix given by the specified function and
        applies spectral decomposition to the corresponding graph laplacian.
        The resulting transformation is given by the value of the
        eigenvectors for each data point.

        Note : Laplacian Eigenmaps is the actual algorithm implemented here.

        Read more in the :ref:`User Guide <spectral_embedding>`.

        Parameters
        ----------

        diffusion_time : float
            Determines the scaling of the eigenvalues of the Laplacian

        alpha : float, optional, default: 0.5
            Setting alpha=1 and the diffusion operator approximates the
            Laplace-Beltrami operator. We then recover the Riemannian geometry
            of the data set regardless of the distribution of the points. To
            describe the long-term behavior of the point distribution of a
            system of stochastic differential equations, we can use alpha=0.5
            and the resulting Markov chain approximates the Fokker-Planck
            diffusion. With alpha=0, it reduces to the classical graph Laplacian
            normalization.

        n_components : integer, default: 2
            The dimension of the projected subspace.

        eigen_solver : {None, 'eigs' or 'eigsh'}
            The eigenvalue decomposition strategy to use.

        random_state : int, RandomState instance or None, optional, default: None
            A pseudo random number generator used for the initialization of the
            lobpcg eigenvectors.  If int, random_state is the seed used by the
            random number generator; If RandomState instance, random_state is the
            random number generator; If None, the random number generator is the
            RandomState instance used by `np.random`. Used when ``solver`` ==
            'amg'.

        affinity : string or callable, default : "nearest_neighbors"
            How to construct the affinity matrix.
             - 'nearest_neighbors' : construct affinity matrix by knn graph
             - 'rbf' : construct affinity matrix by rbf kernel
             - 'markov': construct affinity matrix by Markov kernel
             - 'cauchy': construct affinity matrix by Cauchy kernel
             - 'precomputed' : interpret X as precomputed affinity matrix
             - callable : use passed in function as affinity
               the function takes in data matrix (n_samples, n_features)
               and return affinity matrix (n_samples, n_samples).

        gamma : float, optional
            Kernel coefficient for pairwise distance (rbf, markov, cauchy)

        metric : string, optional
            Metric for scipy pdist function used to compute pairwise distances
            for markov and cauchy kernels

        n_neighbors : int, default : max(n_samples/10 , 1)
            Number of nearest neighbors for nearest_neighbors graph building.

        use_variant : boolean, default : False
            Use a variant requires L to be dense, positive semidefinite and
            entrywise positive with decomposition L = dot(X, X.T).

        n_jobs : int, optional (default = 1)
            The number of parallel jobs to run.
            If ``-1``, then the number of jobs is set to the number of CPU cores.

        Attributes
        ----------

        embedding_ : array, shape = (n_samples, n_components)
            Spectral embedding of the training matrix.

        affinity_matrix_ : array, shape = (n_samples, n_samples)
            Affinity_matrix constructed from samples or precomputed.

        References
        ----------

        - Lafon, Stephane, and Ann B. Lee. "Diffusion maps and coarse-graining: A
          unified framework for dimensionality reduction, graph partitioning, and
          data set parameterization." Pattern Analysis and Machine Intelligence,
          IEEE Transactions on 28.9 (2006): 1393-1403.
          https://doi.org/10.1109/TPAMI.2006.184

        - Coifman, Ronald R., and Stephane Lafon. Diffusion maps. Applied and
          Computational Harmonic Analysis 21.1 (2006): 5-30.
          https://doi.org/10.1016/j.acha.2006.04.006

        """

        def __init__(self, diffusion_time=0, alpha=0.5, n_components=2,
                     affinity="nearest_neighbors", gamma=None,
                     metric='euclidean', random_state=None, eigen_solver=None,
                     n_neighbors=None, use_variant=False, n_jobs=1):
            self.diffusion_time = diffusion_time
            self.alpha = alpha
            self.n_components = n_components
            self.affinity = affinity
            self.gamma = gamma
            self.metric = metric
            self.random_state = random_state
            self.eigen_solver = eigen_solver
            self.n_neighbors = n_neighbors
            self.use_variant = use_variant
            self.n_jobs = n_jobs

        @property
        def _pairwise(self):
            return self.affinity == "precomputed"

        def _get_affinity_matrix(self, X, Y=None):
            """Calculate the affinity matrix from data
            Parameters
            ----------
            X : array-like, shape (n_samples, n_features)
                Training vector, where n_samples is the number of samples
                and n_features is the number of features.

                If affinity is "precomputed"
                X : array-like, shape (n_samples, n_samples),
                Interpret X as precomputed adjacency graph computed from
                samples.

            Returns
            -------
            affinity_matrix, shape (n_samples, n_samples)
            """
            if self.affinity == 'precomputed':
                self.affinity_matrix_ = X
                return self.affinity_matrix_
            if self.affinity == 'nearest_neighbors':
                if sps.issparse(X):
                    warnings.warn("Nearest neighbors affinity currently does "
                                  "not support sparse input, falling back to "
                                  "rbf affinity")
                    self.affinity = "rbf"
                else:
                    self.n_neighbors_ = (self.n_neighbors
                                         if self.n_neighbors is not None
                                         else max(int(X.shape[0] / 10), 1))
                    self.affinity_matrix_ = kneighbors_graph(X, self.n_neighbors_,
                                                             include_self=True,
                                                             n_jobs=self.n_jobs)
                    # currently only symmetric affinity_matrix supported
                    self.affinity_matrix_ = 0.5 * (self.affinity_matrix_ +
                                                   self.affinity_matrix_.T)
                    return self.affinity_matrix_
            if self.affinity == 'rbf':
                self.gamma_ = (self.gamma
                               if self.gamma is not None else 1.0 / X.shape[1])
                self.affinity_matrix_ = rbf_kernel(X, gamma=self.gamma_)
                return self.affinity_matrix_
            if self.affinity in ['markov', 'cauchy']:
                from .dist import compute_affinity
                self.affinity_matrix_ = compute_affinity(X,
                                                         method=self.affinity,
                                                         eps=self.gamma,
                                                         metric=self.metric)
                return self.affinity_matrix_
            self.affinity_matrix_ = self.affinity(X)
            return self.affinity_matrix_

        def fit(self, X, y=None):
            """Fit the model from data in X.

            Parameters
            ----------
            X : array-like, shape (n_samples, n_features)
                Training vector, where n_samples is the number of samples
                and n_features is the number of features.

                If affinity is "precomputed"
                X : array-like, shape (n_samples, n_samples),
                Interpret X as precomputed adjacency graph computed from
                samples.

            Returns
            -------
            self : object
                Returns the instance itself.
            """

            from sklearn.utils import check_array, check_random_state
            X = check_array(X, ensure_min_samples=2, estimator=self)

            random_state = check_random_state(self.random_state)
            if isinstance(self.affinity, (str,)):
                if self.affinity not in set(("nearest_neighbors", "rbf",
                                             "markov", "cauchy",
                                             "precomputed")):
                    raise ValueError(("%s is not a valid affinity. Expected "
                                      "'precomputed', 'rbf', 'nearest_neighbors' "
                                      "or a callable.") % self.affinity)
            elif not callable(self.affinity):
                raise ValueError(("'affinity' is expected to be an affinity "
                                  "name or a callable. Got: %s") % self.affinity)

            affinity_matrix = self._get_affinity_matrix(X)
            if self.use_variant:
                self.embedding_ = compute_diffusion_map_psd(affinity_matrix,
                                                            alpha=self.alpha,
                                                            n_components=self.n_components,
                                                            diffusion_time=self.diffusion_time)
            else:
                self.embedding_ = compute_diffusion_map(affinity_matrix,
                                                        alpha=self.alpha,
                                                        n_components=self.n_components,
                                                        diffusion_time=self.diffusion_time,
                                                        eigen_solver=self.eigen_solver)
            return self

        def fit_transform(self, X, y=None):
            """Fit the model from data in X and transform X.

            Parameters
            ----------
            X : array-like, shape (n_samples, n_features)
                Training vector, where n_samples is the number of samples
                and n_features is the number of features.

                If affinity is "precomputed"
                X : array-like, shape (n_samples, n_samples),
                Interpret X as precomputed adjacency graph computed from
                samples.

            Returns
            -------
            X_new : array-like, shape (n_samples, n_components)
            """
            self.fit(X)
            return self.embedding_


text:
package org.chaston.oakfunds.storage;

/**
 * TODO(mchaston): write JavaDocs
 */
public class AttributeType {
  private final String name;
  private final Class<?> type;
  private final String columnName;
  private final boolean required;

  AttributeType(String name, Class<?> type, String columnName, boolean required) {
    this.name = name;
    this.type = type;
    this.columnName = columnName;
    this.required = required;
  }

  public String getColumnName() {
    return columnName;
  }

  public String getName() {
    return name;
  }

  public Class<?> getType() {
    return type;
  }

  public boolean isRequired() {
    return required;
  }
}

redpajama_set_name: RedPajamaGithub


text:
float gMinSize = 0.0005f;
float gMaxSize = 0.98f;
int gConsider = 250;
float gSpacing = 0.5f;
float gSmoothing = 0.03f;
float gMinThresh = 90;
float gMaxThresh = 250.0f;
float gThreshThresh = 50.0f;
float gThreshSteps = 4.f;
float gMaxScale = 600.f;
float MAX_WIDTH_MULTIPLIER = 100.f;

float gDebugThresh = 500;
float gDebugImage = 0;
bool gDebugRefresh = false;

ofFloatColor mLineColor = ofColor(0, 0, 0, 128);

int mBlendMode = 3;

float mLineWidth = 1.5f;

bool mExportFiles = false;
bool mUseFatline = false;

CollageProblem::CollageProblem() : GAProblem() {
	mCompMethod = 7;
	mUseDna = true;
	bFlattenAndSave = true;
	mRepeat = 1;
	mPopSize = 20;
	mNGen = 20;

	gui.addPage("Collage");
	gui.addSlider("Consider", gConsider, 0.0f, 500.0f);
	gui.addSlider("MinSize", gMinSize, 0.0f, 0.01f);
	gui.addSlider("MaxSize", gMaxSize, 0.0f, 1.0f);
	gui.addSlider("Spacing", gSpacing, 0.0f, 10.0f);
	gui.addSlider("Smoothing", gSmoothing, 0.0f, 1.0f);

	gui.addSlider("MinThresh", gMinThresh, 0.0f, 1000.0f);
	gui.addSlider("MaxThresh", gMaxThresh, 0.0f, 1000.0f);
	gui.addSlider("ThreshSteps", gThreshSteps, 0.0f, 10.0f);
	gui.addSlider("MaxScale", gMaxScale, 100.0f, 2000.0f);

	gui.addColorPicker("LineColor", mLineColor);
	gui.addSlider("LinelWidth", mLineWidth, 0.f, 10.f);
	gui.addToggle("UseFatline", mUseFatline);
	gui.addSlider("BlendMode", mBlendMode, 0, 5);

	gui.addToggle("ExportFiles", mExportFiles);

	gui.addTitle("-- Debug --");
	gui.addSlider("DebugThresh", gDebugThresh, 0.0f, 1.0f);
	gui.addSlider("DebugImage", gDebugImage, 0.0f, 0.99999f);
	gui.addButton("DebugRefresh", gDebugRefresh);
}

void CollageProblem::setup() {
	GAProblem::setup();

	ofDirectory dir(mRootDir + "/source/");
	dir.allowExt("jpg");
	int nd = dir.listDir();

	mImages.resize(nd);
	for (int i = 0; i < nd; ++i) {
		mImages[i].loadImage(dir.getPath(i), mWorkingWidth * MAX_WIDTH_MULTIPLIER);
	}
}

bool blobSort(BlobInfo* b1, BlobInfo* b2)
{
	return (b1->texture.getWidth() * b1->texture.getHeight() < b2->texture.getWidth() * b2->texture.getHeight());
}

void ImageCache::createBlobCvGray(ofxCvGrayscaleImage& cvImg) {
	ofTessellator tess;
	ofxCvContourFinder contourFinder;

	contourFinder.findContours(cvImg, cvImg.getWidth() * cvImg.getHeight() * gMinSize, cvImg.getWidth() * cvImg.getHeight() * gMaxSize, gConsider, false, true);

	for(int i = 0; i < contourFinder.blobs.size(); i++) {
		ofRectangle& rect = contourFinder.blobs[i].boundingRect;

		bool onEdge = rect.getLeft() < 2 ||
			image.getWidth() - rect.getRight() < 2 ||
			rect.getTop() < 2 ||
			image.getHeight() - rect.getBottom() < 2;

		if (mExportFiles || !onEdge) {
			ofPolyline line;
			line.addVertices(contourFinder.blobs[i].pts);
			line.setClosed(true);
			if (gSpacing > 0) {
				line = line.getResampledBySpacing(gSpacing);
				line = line.getSmoothed((gSmoothing * gSmoothing) * line.size(), 1.f);
			}
 			line.simplify();

			ofVboMesh mesh;
			tess.tessellateToMesh(line, OF_POLY_WINDING_ODD, mesh, true);

			vector<ofVec3f>& verts = mesh.getVertices();
			for (int iv = 0; iv < verts.size(); ++iv) {
				mesh.addTexCoord(ofVec2f(verts[iv].x, verts[iv].y));
			}
			mesh.disableColors();
			mesh.disableNormals();

			ofFbo fbo;
			ofPixels pixResult;
			ofImage workingImage;
			ofFbo::Settings sett;
			sett.width = rect.width;
			sett.height = rect.height;
			fbo.allocate(sett);

			fbo.begin();
			ofClear(255, 255, 255, 0);
			ofEnableBlendMode(OF_BLENDMODE_ALPHA);
			ofSetColor(255, 255, 255);
			ofPushMatrix();
			ofTranslate(-rect.x, -rect.y);
			image.bind();
			mesh.draw();
			image.unbind();

			if (mLineWidth > 0) {
				ofEnableBlendMode((ofBlendMode)mBlendMode);
				ofSetColor(mLineColor);
				ofSetLineWidth(mLineWidth);
				ofEnableSmoothing();
				ofEnableAntiAliasing();
				line.draw();
				if (mUseFatline) {
					ofSetLineWidth(mLineWidth * 2);
					line.draw();
					ofSetLineWidth(mLineWidth * 3);
					line.draw();
				}
			}
			ofPopMatrix();

			fbo.end();

			pixResult.clear();
			fbo.readToPixels(pixResult);
			workingImage.setFromPixels(pixResult);

			static int index = 0;
			if (mExportFiles) {
				if (onEdge) {
					ofSaveImage(workingImage.getPixels(), "debug/bad_" + name + ofToString(index++) + " .png", OF_IMAGE_QUALITY_BEST);
				}
				else {
					ofSaveImage(workingImage.getPixels(), "debug/good_" + name + ofToString(index++) + " .png", OF_IMAGE_QUALITY_BEST);
				}
			}
			if (!onEdge) {
				BlobInfo* info = new BlobInfo();
				info->line = line;
				info->centroid = contourFinder.blobs[i].centroid;
				info->mesh = mesh;
				info->texture = workingImage;
				blobs.push_back(info);
			}
		}
		printf("%d / %d\n", i + 1, contourFinder.blobs.size());
	}
	sort(blobs.begin(), blobs.end(), blobSort);
}

void ImageCache::deleteBlobs() {
	for (int i = 0; i < blobs.size(); ++i) {
		delete blobs[i];
	}
	blobs.clear();
}

void ImageCache::addBlobs(float threshold) {

	ofxCvColorImage cvImgColor;
	cvImgColor.allocate(image.getWidth(), image.getHeight());
	cvImgColor.setFromPixels(image.getPixelsRef());

	ofxCvGrayscaleImage cvImgGrayscale;
	cvImgGrayscale.allocate(cvImgColor.width, cvImgColor.height);

	cvImgGrayscale.setFromColorImage(cvImgColor);
	cvImgGrayscale.threshold(threshold, false);
	createBlobCvGray(cvImgGrayscale);

	cvImgGrayscale.setFromColorImage(cvImgColor);
	cvImgGrayscale.invert();
	cvImgGrayscale.threshold(threshold, false);
	createBlobCvGray(cvImgGrayscale);
}

void ImageCache::loadImage(const string& filename, float maxWidth) {
	name = ofFilePath::getBaseName(filename);
	image.loadImage(filename);

	if (image.getWidth() > maxWidth) {
		float diff = image.getWidth() / image.getHeight();
		image.resize(maxWidth, maxWidth / diff);
	}

	deleteBlobs();
	for (float f = 0; f < 1.f; f += (1.f / gThreshSteps)) {
		addBlobs(ofMap(f, 0.f, 1.f, gMinThresh, gMaxThresh));
	}
}

enum RangeType {
	RT_X,
	RT_Y,
	RT_DEG,
	RT_SCALE,
	RT_IMAGE,
	RT_BLOB,
	RT_MAX
};

void CollageProblem::setRanges() {
	mRanges.resize(RT_MAX);

	mRanges[RT_X] = RangeInfo(4, 0, 1.f); // x
	mRanges[RT_Y] = RangeInfo(4, 0, 1.f); // y
	mRanges[RT_DEG] = RangeInfo(4, 0.f, 360.0f); // y
	mRanges[RT_SCALE] = RangeInfo(4, 0.3f, 1.0f); // y
	mRanges[RT_IMAGE] = RangeInfo(4, 0.f, 0.99999f); // y
	mRanges[RT_BLOB] = RangeInfo(4, 0.f, 0.99999f); // image
}

void CollageProblem::createPixels(ofPixelsRef pixResult, const vector<float>& values, ofImage& baseImage, int width, int height) {
	if (mImages.size() == 0)
		return;

	pixResult.clear();

	ofFbo::Settings setts;
	setts.width = width;
	setts.height = height;
	setts.internalformat = GL_RGB;

	ofFbo fbo;
	fbo.allocate(setts);
	fbo.begin();
	ofClear(255,255,255,255);

	ofSetColor(255);
	ofBlendMode(OF_BLENDMODE_DISABLED);
	baseImage.draw(0, 0);

	ofEnableBlendMode(OF_BLENDMODE_ALPHA);
	for (int ir = 0; ir < mRepeat; ++ir) {
		float x = values[ir * RT_MAX + RT_X] * width;
		float y = values [ir * RT_MAX + RT_Y] * height;
		float deg = values[ir * RT_MAX + RT_DEG];
		float scale = values[ir * RT_MAX + RT_SCALE] * (width / gMaxScale);
		int iimg = (int)(values[ir * RT_MAX + RT_IMAGE] * (float)mImages.size());

		ImageCache& imgCache = mImages[iimg];

		if (imgCache.blobs.size() > 0 ) {
			int ib = values[ir * RT_MAX + RT_BLOB] * imgCache.blobs.size();
			ofImage& tex = imgCache.blobs[ib]->texture;
			ofPushMatrix();
			ofTranslate(x, y);
			ofRotateZ(deg);
			ofScale(scale, scale, scale);
			tex.draw(-tex.getWidth() / 2, -tex.getHeight() / 2);
			ofPopMatrix();
		}
	}

	// end draw
	fbo.end();
	fbo.readToPixels(pixResult);
}

void CollageProblem::debugDraw() {
	ImageCache& imgCache = mImages[gDebugImage * mImages.size()];

	static float lastTresh = 0;
	if (gDebugRefresh || gDebugThresh != lastTresh) {
		imgCache.deleteBlobs();
		imgCache.addBlobs(ofMap(gDebugThresh, 0.f, 1.f, gMinThresh, gMaxThresh));
		lastTresh = gDebugThresh;
	}

	float scale = 1;
	float x = 100;
	float y = 100;
	float deg = 0;
	float blob = 0;

	int xs = (int)sqrt(imgCache.blobs.size());

	for (int i = 0; i < imgCache.blobs.size(); ++i) {
		ofImage& tex = imgCache.blobs[i]->texture;

		//		scale = scale * width / imgCache.image.getWidth();
		ofEnableBlendMode(OF_BLENDMODE_ALPHA);
		ofSetColor(255, 255, 255);
		ofPushMatrix();
		ofTranslate(x, y);
		ofRotateZ(deg);
		ofScale(scale, scale, scale);
		ofTranslate(-tex.getWidth() / 2, -tex.getHeight() / 2);
		tex.draw(0, 0);
		ofPopMatrix();

		x += tex.getWidth();
		if (x > 1000) {
			x = 0;
			y += 200;
		}
	}
}


text:
package dbus

import (
	"fmt"
	"regexp"
	"strings"
	"testing"
)

type lowerCaseExport struct{}

func (export lowerCaseExport) foo() (string, *Error) {
	return "bar", nil
}

type fooExport struct {
	message Message
}

func (export *fooExport) Foo(message Message, param string) (string, *Error) {
	export.message = message
	return "foo", nil
}

type barExport struct{}

func (export barExport) Foo(param string) (string, *Error) {
	return "bar", nil
}

type badExport struct{}

func (export badExport) Foo(param string) string {
	return "bar"
}

// Test typical Export usage.
func TestExport(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	connection.Export(server{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	subtreeObject := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response int64
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Double: %s", err)
	}

	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}

	// Verify that calling a subtree of a regular export does not result in a
	// valid method call.
	err = subtreeObject.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected error due to no object being exported on that path")
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

// Test that Exported handlers can obtain raw message.
func TestExport_message(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	export := &fooExport{}
	connection.Export(export, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected a valid message to be given to handler")
	}
}

// Test Export with an invalid path.
func TestExport_invalidPath(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	err = connection.Export(nil, "foo", "bar")
	if err == nil {
		t.Error("Expected an error due to exporting with an invalid path")
	}
}

// Test Export with an un-exported method. This should not panic, but rather
// result in an invalid method call.
func TestExport_unexportedMethod(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	connection.Export(lowerCaseExport{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	call := object.Call("org.guelfey.DBus.Test.foo", 0)
	err = call.Store(&response)
	if err == nil {
		t.Errorf("Expected an error due to calling unexported method")
	}
}

// Test Export with a method lacking the correct return signature. This should
// result in an invalid method call.
func TestExport_badSignature(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	connection.Export(badExport{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	call := object.Call("org.guelfey.DBus.Test.Foo", 0)
	err = call.Store(&response)
	if err == nil {
		t.Errorf("Expected an error due to the method lacking the right signature")
	}
}

// Test typical ExportWithMap usage.
func TestExportWithMap(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	mapping := make(map[string]string)
	mapping["Double"] = "double" // Export this method as lower-case

	connection.ExportWithMap(server{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response int64
	err = object.Call("org.guelfey.DBus.Test.double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling double: %s", err)
	}

	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}
}

// Test that ExportWithMap does not export both method alias and method.
func TestExportWithMap_bypassAlias(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	mapping := make(map[string]string)
	mapping["Double"] = "double" // Export this method as lower-case

	connection.ExportWithMap(server{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response int64
	// Call upper-case Double (i.e. the real method, not the alias)
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error due to calling actual method, not alias")
	}
}

// Test typical ExportSubtree usage.
func TestExportSubtree(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	export := &fooExport{}
	connection.ExportSubtree(export, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	// Call a subpath of the exported path
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

// Test that using ExportSubtree with exported methods that don't contain a
// Message still work, they just don't get the message.
func TestExportSubtree_noMessage(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	connection.ExportSubtree(server{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	// Call a subpath of the exported path
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response int64
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Double: %s", err)
	}

	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

// Test that a regular Export takes precedence over ExportSubtree.
func TestExportSubtree_exportPrecedence(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	// Register for the entire subtree of /org/guelfey/DBus/Test
	connection.ExportSubtree(&fooExport{},
		"/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	// Explicitly register for /org/guelfey/DBus/Test/Foo, a subpath of above
	connection.Export(&barExport{}, "/org/guelfey/DBus/Test/Foo",
		"org.guelfey.DBus.Test")

	// Call the explicitly exported path
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "bar" {
		t.Errorf(`Response was %s, expected "bar"`, response)
	}

	response = "" // Reset response so errors aren't confusing

	// Now remove explicit export
	connection.Export(nil, "/org/guelfey/DBus/Test/Foo", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	// Now the subtree export should handle the call
	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}
}

// Test typical ExportSubtreeWithMap usage.
func TestExportSubtreeWithMap(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	mapping := make(map[string]string)
	mapping["Foo"] = "foo" // Export this method as lower-case

	connection.ExportSubtreeWithMap(&fooExport{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	// Call a subpath of the exported path
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response string
	// Call the lower-case method
	err = object.Call("org.guelfey.DBus.Test.foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

// Test that ExportSubtreeWithMap does not export both method alias and method.
func TestExportSubtreeWithMap_bypassAlias(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	mapping := make(map[string]string)
	mapping["Foo"] = "foo" // Export this method as lower-case

	connection.ExportSubtreeWithMap(&fooExport{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response string
	// Call upper-case Foo (i.e. the real method, not the alias)
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error due to calling actual method, not alias")
	}
}

func TestExportMethodTable(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]
	export := &fooExport{}
	tbl := make(map[string]interface{})
	tbl["Foo"] = func(message Message, param string) (string, *Error) {
		return export.Foo(message, param)
	}
	tbl["Foo2"] = export.Foo
	connection.ExportMethodTable(tbl, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	err = object.Call("org.guelfey.DBus.Test.Foo2", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

func TestExportSubtreeMethodTable(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	export := &fooExport{}
	tbl := make(map[string]interface{})
	tbl["Foo"] = func(message Message, param string) (string, *Error) {
		return export.Foo(message, param)
	}
	tbl["Foo2"] = export.Foo
	connection.ExportSubtreeMethodTable(tbl, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")

	// Call a subpath of the exported path
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	err = object.Call("org.guelfey.DBus.Test.Foo2", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	// Now remove export
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}

func TestExportMethodTable_NotFunc(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]
	export := &fooExport{}
	tbl := make(map[string]interface{})
	tbl["Foo"] = func(message Message, param string) (string, *Error) {
		return export.Foo(message, param)
	}
	tbl["Foo2"] = "foobar"

	connection.ExportMethodTable(tbl, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}

	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}

	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}

	err = object.Call("org.guelfey.DBus.Test.Foo2", 0, "qux").Store(&response)
	if err == nil {
		t.Errorf("Expected an error since the Foo2 was not a function")
	}
}

func TestExportMethodTable_ReturnNotError(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]
	export := &fooExport{}
	tbl := make(map[string]interface{})
	tbl["Foo"] = func(message Message, param string) (string, string) {
		out, _ := export.Foo(message, param)
		return out, out
	}

	connection.ExportMethodTable(tbl, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")

	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Errorf("Expected an error since the Foo did not have a final return as *dbus.Error")
	}
}

// Test that introspection works on sub path of every exported object
func TestExportSubPathIntrospection(t *testing.T) {
	const (
		introIntf    = "org.freedesktop.DBus.Introspectable"
		respTmpl     = `^<node>\s*<node\s+name="%s"\s*/>\s*</node>$`
		pathstr      = "/org/guelfey/DBus/Test"
		foopathstr   = pathstr + "/Foo"
		barpathstr   = pathstr + "/Bar"
		test1intfstr = "org.guelfey.DBus.Test1"
		test2intfstr = "org.guelfey.DBus.Test2"
		intro        = `
			<node>
			<interface name="` + test1intfstr + `">
				<method name="Foo">
					<arg direction="out" type="s"/>
				</method>
			</interface>
			<interface name="` + test2intfstr + `">
				<method name="Foo">
					<arg direction="out" type="s"/>
				</method>
				<method name="Bar">
					<arg direction="out" type="s"/>
				</method>
			</interface>
			<interface name="` + introIntf + `">
				<method name="Introspect">
					<arg name="out" direction="out" type="s"/>
				</method>
			</interface>
			</node>`
	)
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}

	name := connection.Names()[0]

	foo := &fooExport{}
	bar := &barExport{}
	connection.Export(foo, foopathstr, test1intfstr)
	connection.Export(foo, foopathstr, test2intfstr)
	connection.Export(bar, barpathstr, test2intfstr)
	connection.Export(intro, pathstr, introIntf)

	var response string
	var match bool
	path := strings.Split(pathstr, "/")
	for i := 0; i < len(path)-1; i++ {
		var subpath string
		if i == 0 {
			subpath = "/"
		} else {
			subpath = strings.Join(path[:i+1], "/")
		}

		object := connection.Object(name, ObjectPath(subpath))
		err = object.Call(introIntf+".Introspect", 0).Store(&response)
		if err != nil {
			t.Errorf("Unexpected error calling Introspect on %s: %s", subpath, err)
		}

		exp := fmt.Sprintf(respTmpl, path[i+1])
		match, err = regexp.MatchString(exp, response)
		if err != nil {
			t.Fatalf("Error calling MatchString: %s", err)
		}
		if !match {
			t.Errorf("Unexpected introspection response for %s: %s", subpath, response)
		}
	}

	// Test invalid subpath
	invalSubpath := "/org/guelfey/DBus/Test/Nonexistent"
	object := connection.Object(name, ObjectPath(invalSubpath))
	err = object.Call(introIntf+".Introspect", 0).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Introspect on %s: %s", invalSubpath, err)
	}
	match, err = regexp.MatchString(`^<node>\s*</node>$`, response)
	if err != nil {
		t.Fatalf("Error calling MatchString: %s", err)
	}
	if !match {
		t.Errorf("Unexpected introspection response for %s: %s", invalSubpath, response)
	}
}


text:
package org.jetbrains.plugins.scala
package project.template

import com.intellij.framework.FrameworkTypeEx
import org.jetbrains.plugins.scala.icons.Icons

/**
 * @author Pavel Fatin
 */
class ScalaFrameworkType extends FrameworkTypeEx("Scala") {
  override def getIcon = Icons.SCALA_SMALL_LOGO

  override def getPresentableName = "Scala"

  override def createProvider() = new ScalaSupportProvider()
}

object ScalaFrameworkType {
  val Instance: ScalaFrameworkType = FrameworkTypeEx.EP_NAME.findExtension(classOf[ScalaFrameworkType])
}


text:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from contextlib import contextmanager
from urllib2 import urlopen, URLError
from os import path
from time import time, sleep
import sys
import subprocess
import httplib

class SetupIridaData:

    def __init__(self, base_URL, user, password, branch):

        self.base_URL = base_URL
        self.user = user
        self.password = password
        self.driver = None
	self.branch = branch

        self.IRIDA_PASSWORD_ID = 'password_client'
        self.IRIDA_AUTH_CODE_ID = 'auth_code_client'
        self.IRIDA_USER = "admin"
        self.IRIDA_PASSWORD = "Password1!"  # new password

        self.TIMEOUT = 600  # seconds

        db_name = "irida_uploader_test"

        self.IRIDA_DB_RESET = 'echo '\
            '"drop database if exists ' + db_name + ';'\
            'create database ' + db_name + ';'\
            '"| mysql -u test -ptest'

        self.IRIDA_CMD = ['mvn', 'clean', 'jetty:run',
                          '-Djdbc.url=jdbc:mysql://localhost:3306/' + db_name,
                          '-Djdbc.username=test', '-Djdbc.password=test',
                          '-Dliquibase.update.database.schema=true',
                          '-Dhibernate.hbm2ddl.auto=',
                          '-Dhibernate.hbm2ddl.import_files=']

        self.IRIDA_STOP = 'mvn jetty:stop'

        self.PATH_TO_MODULE = path.dirname(__file__)
        if len(self.PATH_TO_MODULE) == 0:
            self.PATH_TO_MODULE = "."

        self.SCRIPT_FOLDER = path.join(self.PATH_TO_MODULE, "bash_scripts")
        self.INSTALL_IRIDA_EXEC = path.join(
            self.SCRIPT_FOLDER, "install_irida.sh")

        self.REPO_PATH = path.join(self.PATH_TO_MODULE, "repos")
        self.IRIDA_PATH = path.join(self.REPO_PATH, "irida")

    @contextmanager
    def wait_for_page_load(self, timeout=30):
        old_page = self.driver.find_element_by_tag_name('html')
        yield
        WebDriverWait(self.driver, timeout).until(
            EC.staleness_of(old_page)
        )

    def install_irida(self):
        install_proc = subprocess.Popen(
            [self.INSTALL_IRIDA_EXEC, self.branch], cwd=self.PATH_TO_MODULE)
        proc_res = install_proc.wait()
        if proc_res == 1:  # failed to execute
            sys.exit(1)

    def reset_irida_db(self):
        db_reset_proc = subprocess.Popen(self.IRIDA_DB_RESET, shell=True)
        proc_res = db_reset_proc.wait()

        if proc_res == 1:  # failed to execute
            print "Unable to execute:\n {cmd}".format(cmd=self.IRIDA_DB_RESET)
            sys.exit(1)

    def run_irida(self):
        subprocess.Popen(
            self.IRIDA_CMD, cwd=self.IRIDA_PATH)
        self.wait_until_up()

    def wait_until_up(self):

        start_time = time()
        elapsed = 0
        status_code = -1
        print "Waiting for " + self.base_URL

        while(status_code != httplib.OK and elapsed < self.TIMEOUT):

            try:
                status_code = urlopen(self.base_URL).getcode()
                elapsed = time() - start_time

            except URLError:
                sleep(10)

    def start_driver(self):
        self.driver = webdriver.Chrome()
        self.driver.implicitly_wait(30)

    def login(self):

        self.driver.get(self.base_URL + "/login")
        self.driver.find_element_by_id("emailTF").clear()
        self.driver.find_element_by_id("emailTF").send_keys(self.user)
        self.driver.find_element_by_id("passwordTF").clear()
        self.driver.find_element_by_id("passwordTF").send_keys(self.password)
        with self.wait_for_page_load(timeout=10):
                self.driver.find_element_by_id("submitBtn").click()

    def set_new_admin_pw(self):

        self.driver.find_element_by_id("password").clear()
        self.driver.find_element_by_id(
            "password").send_keys(self.IRIDA_PASSWORD)
        self.driver.find_element_by_id("confirmPassword").clear()
        self.driver.find_element_by_id(
            "confirmPassword").send_keys(self.IRIDA_PASSWORD)
        with self.wait_for_page_load(timeout=10):
            xpath = "//button[@type='submit']"
            submit = self.driver.find_element_by_xpath(xpath)
            submit.click()

    def create_client(self):

        self.driver.get(self.base_URL + "/clients/create")
        self.driver.find_element_by_id(
            "clientId").send_keys(self.IRIDA_AUTH_CODE_ID)

        self.driver.find_element_by_id("scope_write").click()  # for sending
        with self.wait_for_page_load(timeout=10):
            self.driver.find_element_by_id("create-client-submit").click()

    def get_irida_secret(self):

        self.driver.get(self.base_URL + "/clients")
        self.driver.find_element_by_xpath(
            "//*[contains(text(), '" + self.IRIDA_AUTH_CODE_ID + "')]").click()
        secret = self.driver.find_element_by_id(
            "client-secret").get_attribute("textContent")

        return secret

    def stop_irida(self):
        stopper = subprocess.Popen(
            self.IRIDA_STOP, cwd=self.IRIDA_PATH, shell=True)
        stopper.wait()

    def close_driver(self):
        self.driver.quit()


text:
require 'date'
require 'google/apis/core/base_service'
require 'google/apis/core/json_representation'
require 'google/apis/core/hashable'
require 'google/apis/errors'

module Google
  module Apis
    module MonitoringV3

      class ListGroupMembersResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CreateCollectdTimeSeriesRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ListMonitoredResourceDescriptorsResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class TimeSeries
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CreateTimeSeriesRequest
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Distribution
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class MonitoredResource
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ListMetricDescriptorsResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class MonitoredResourceDescriptor
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class TypedValue
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CollectdPayload
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Linear
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Option
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Empty
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Explicit
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class TimeInterval
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Exponential
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Point
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Field
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Metric
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class LabelDescriptor
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ListTimeSeriesResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Group
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Type
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class BucketOptions
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class CollectdValue
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class SourceContext
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class MetricDescriptor
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class Range
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ListGroupsResponse
        class Representation < Google::Apis::Core::JsonRepresentation; end

        include Google::Apis::Core::JsonObjectSupport
      end

      class ListGroupMembersResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :members, as: 'members', class: Google::Apis::MonitoringV3::MonitoredResource, decorator: Google::Apis::MonitoringV3::MonitoredResource::Representation

          property :next_page_token, as: 'nextPageToken'
          property :total_size, as: 'totalSize'
        end
      end

      class CreateCollectdTimeSeriesRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :collectd_version, as: 'collectdVersion'
          property :resource, as: 'resource', class: Google::Apis::MonitoringV3::MonitoredResource, decorator: Google::Apis::MonitoringV3::MonitoredResource::Representation

          collection :collectd_payloads, as: 'collectdPayloads', class: Google::Apis::MonitoringV3::CollectdPayload, decorator: Google::Apis::MonitoringV3::CollectdPayload::Representation

        end
      end

      class ListMonitoredResourceDescriptorsResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :next_page_token, as: 'nextPageToken'
          collection :resource_descriptors, as: 'resourceDescriptors', class: Google::Apis::MonitoringV3::MonitoredResourceDescriptor, decorator: Google::Apis::MonitoringV3::MonitoredResourceDescriptor::Representation

        end
      end

      class TimeSeries
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :metric_kind, as: 'metricKind'
          property :metric, as: 'metric', class: Google::Apis::MonitoringV3::Metric, decorator: Google::Apis::MonitoringV3::Metric::Representation

          collection :points, as: 'points', class: Google::Apis::MonitoringV3::Point, decorator: Google::Apis::MonitoringV3::Point::Representation

          property :value_type, as: 'valueType'
          property :resource, as: 'resource', class: Google::Apis::MonitoringV3::MonitoredResource, decorator: Google::Apis::MonitoringV3::MonitoredResource::Representation

        end
      end

      class CreateTimeSeriesRequest
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :time_series, as: 'timeSeries', class: Google::Apis::MonitoringV3::TimeSeries, decorator: Google::Apis::MonitoringV3::TimeSeries::Representation

        end
      end

      class Distribution
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :sum_of_squared_deviation, as: 'sumOfSquaredDeviation'
          property :range, as: 'range', class: Google::Apis::MonitoringV3::Range, decorator: Google::Apis::MonitoringV3::Range::Representation

          property :count, as: 'count'
          property :mean, as: 'mean'
          collection :bucket_counts, as: 'bucketCounts'
          property :bucket_options, as: 'bucketOptions', class: Google::Apis::MonitoringV3::BucketOptions, decorator: Google::Apis::MonitoringV3::BucketOptions::Representation

        end
      end

      class MonitoredResource
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :type, as: 'type'
          hash :labels, as: 'labels'
        end
      end

      class ListMetricDescriptorsResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :metric_descriptors, as: 'metricDescriptors', class: Google::Apis::MonitoringV3::MetricDescriptor, decorator: Google::Apis::MonitoringV3::MetricDescriptor::Representation

          property :next_page_token, as: 'nextPageToken'
        end
      end

      class MonitoredResourceDescriptor
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :labels, as: 'labels', class: Google::Apis::MonitoringV3::LabelDescriptor, decorator: Google::Apis::MonitoringV3::LabelDescriptor::Representation

          property :name, as: 'name'
          property :display_name, as: 'displayName'
          property :description, as: 'description'
          property :type, as: 'type'
        end
      end

      class TypedValue
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :double_value, as: 'doubleValue'
          property :int64_value, as: 'int64Value'
          property :distribution_value, as: 'distributionValue', class: Google::Apis::MonitoringV3::Distribution, decorator: Google::Apis::MonitoringV3::Distribution::Representation

          property :bool_value, as: 'boolValue'
          property :string_value, as: 'stringValue'
        end
      end

      class CollectdPayload
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :values, as: 'values', class: Google::Apis::MonitoringV3::CollectdValue, decorator: Google::Apis::MonitoringV3::CollectdValue::Representation

          property :type_instance, as: 'typeInstance'
          property :type, as: 'type'
          hash :metadata, as: 'metadata', class: Google::Apis::MonitoringV3::TypedValue, decorator: Google::Apis::MonitoringV3::TypedValue::Representation

          property :plugin, as: 'plugin'
          property :plugin_instance, as: 'pluginInstance'
          property :end_time, as: 'endTime'
          property :start_time, as: 'startTime'
        end
      end

      class Linear
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :offset, as: 'offset'
          property :num_finite_buckets, as: 'numFiniteBuckets'
          property :width, as: 'width'
        end
      end

      class Option
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :name, as: 'name'
          hash :value, as: 'value'
        end
      end

      class Empty
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
        end
      end

      class Explicit
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :bounds, as: 'bounds'
        end
      end

      class TimeInterval
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :end_time, as: 'endTime'
          property :start_time, as: 'startTime'
        end
      end

      class Exponential
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :growth_factor, as: 'growthFactor'
          property :scale, as: 'scale'
          property :num_finite_buckets, as: 'numFiniteBuckets'
        end
      end

      class Point
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :value, as: 'value', class: Google::Apis::MonitoringV3::TypedValue, decorator: Google::Apis::MonitoringV3::TypedValue::Representation

          property :interval, as: 'interval', class: Google::Apis::MonitoringV3::TimeInterval, decorator: Google::Apis::MonitoringV3::TimeInterval::Representation

        end
      end

      class Field
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :type_url, as: 'typeUrl'
          property :number, as: 'number'
          property :json_name, as: 'jsonName'
          property :kind, as: 'kind'
          collection :options, as: 'options', class: Google::Apis::MonitoringV3::Option, decorator: Google::Apis::MonitoringV3::Option::Representation

          property :oneof_index, as: 'oneofIndex'
          property :cardinality, as: 'cardinality'
          property :packed, as: 'packed'
          property :default_value, as: 'defaultValue'
          property :name, as: 'name'
        end
      end

      class Metric
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          hash :labels, as: 'labels'
          property :type, as: 'type'
        end
      end

      class LabelDescriptor
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :key, as: 'key'
          property :description, as: 'description'
          property :value_type, as: 'valueType'
        end
      end

      class ListTimeSeriesResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          collection :time_series, as: 'timeSeries', class: Google::Apis::MonitoringV3::TimeSeries, decorator: Google::Apis::MonitoringV3::TimeSeries::Representation

          property :next_page_token, as: 'nextPageToken'
        end
      end

      class Group
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :display_name, as: 'displayName'
          property :is_cluster, as: 'isCluster'
          property :filter, as: 'filter'
          property :name, as: 'name'
          property :parent_name, as: 'parentName'
        end
      end

      class Type
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :syntax, as: 'syntax'
          property :source_context, as: 'sourceContext', class: Google::Apis::MonitoringV3::SourceContext, decorator: Google::Apis::MonitoringV3::SourceContext::Representation

          collection :options, as: 'options', class: Google::Apis::MonitoringV3::Option, decorator: Google::Apis::MonitoringV3::Option::Representation

          collection :fields, as: 'fields', class: Google::Apis::MonitoringV3::Field, decorator: Google::Apis::MonitoringV3::Field::Representation

          property :name, as: 'name'
          collection :oneofs, as: 'oneofs'
        end
      end

      class BucketOptions
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :exponential_buckets, as: 'exponentialBuckets', class: Google::Apis::MonitoringV3::Exponential, decorator: Google::Apis::MonitoringV3::Exponential::Representation

          property :linear_buckets, as: 'linearBuckets', class: Google::Apis::MonitoringV3::Linear, decorator: Google::Apis::MonitoringV3::Linear::Representation

          property :explicit_buckets, as: 'explicitBuckets', class: Google::Apis::MonitoringV3::Explicit, decorator: Google::Apis::MonitoringV3::Explicit::Representation

        end
      end

      class CollectdValue
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :data_source_name, as: 'dataSourceName'
          property :value, as: 'value', class: Google::Apis::MonitoringV3::TypedValue, decorator: Google::Apis::MonitoringV3::TypedValue::Representation

          property :data_source_type, as: 'dataSourceType'
        end
      end

      class SourceContext
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :file_name, as: 'fileName'
        end
      end

      class MetricDescriptor
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :metric_kind, as: 'metricKind'
          property :display_name, as: 'displayName'
          property :description, as: 'description'
          property :unit, as: 'unit'
          collection :labels, as: 'labels', class: Google::Apis::MonitoringV3::LabelDescriptor, decorator: Google::Apis::MonitoringV3::LabelDescriptor::Representation

          property :name, as: 'name'
          property :type, as: 'type'
          property :value_type, as: 'valueType'
        end
      end

      class Range
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :min, as: 'min'
          property :max, as: 'max'
        end
      end

      class ListGroupsResponse
        # @private
        class Representation < Google::Apis::Core::JsonRepresentation
          property :next_page_token, as: 'nextPageToken'
          collection :group, as: 'group', class: Google::Apis::MonitoringV3::Group, decorator: Google::Apis::MonitoringV3::Group::Representation

        end
      end
    end
  end
end


text:
package org.pitest.testapi;

/**
 * @author henry
 *
 */
public abstract class AbstractTestUnit implements TestUnit {

  private final Description description;

  public AbstractTestUnit(final Description description) {
    this.description = description;
  }

  @Override
  public abstract void execute(ResultCollector rc);

  @Override
  public final Description getDescription() {
    return this.description;
  }

}


text:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/linearLayout"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="1dp"
    android:paddingRight="1dp"
    android:paddingTop="0dp"
    tools:context=".ZoneList"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/frameLayout">

        <GridLayout
            android:layout_width="match_parent"
            android:layout_height="78dp"
            android:layout_gravity="center_horizontal|top"
            android:paddingBottom="8dp">

            <TextView
                android:layout_width="103dp"
                android:layout_height="44dp"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="User Info"
                android:id="@+id/textView8"
                android:layout_row="0"
                android:layout_column="36"
                android:layout_gravity="left"
                android:layout_columnSpan="15"
                android:textSize="20dp" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="61dp"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Sector"
                android:id="@+id/textView11"
                android:layout_row="0"
                android:layout_column="59"
                android:layout_gravity="center_horizontal"
                android:textSize="40dp"
                android:singleLine="false" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Back"
                android:id="@+id/button3"
                android:layout_row="0"
                android:layout_column="60" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LogOut"
                android:id="@+id/button2"
                android:layout_row="0"
                android:layout_column="61" />

        </GridLayout>
    </FrameLayout>

    <!--<Button-->
    <!--android:layout_width="wrap_content"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:text="New Button"-->
    <!--android:id="@+id/button"-->
    <!--android:layout_alignRight="@+id/frameLayout"-->
    <!--android:layout_alignEnd="@+id/frameLayout"-->
    <!--android:layout_above="@+id/frameLayout"-->
    <!--android:paddingBottom="8dp"-->
    <!--android:layout_alignParentTop="true" />-->

    <ListView
        android:layout_width="1254dp"
        android:layout_height="737dp"
        android:id="@+id/sector_list"
        android:divider="@null"
        android:longClickable="true"
        android:layout_row="3"
        android:layout_column="1"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/frameLayout"
        android:layout_alignEnd="@+id/frameLayout"
        android:layout_marginTop="73dp" />

</RelativeLayout>


text:
/*
Package d3d9 provides a wrapper for Microsoft's Direct3D9 API in pure Go.
It can only be used on Windows.

When running a Direct3D application you need to have d3d9.dll installed on the
system, which fortunately has been deployed with all Windows versions since XP.
This means if you have Go installed, you also have the DLL installed. This also
means that your application can be deployed without the DirectX DLLs and if you
have no other dependencies you can just give the executable file to the users.

To get going with this wrapper there are some basic samples that demonstrate how
to set up and use the library at:
https://github.com/gonutz/d3d9/tree/master/samples
*/
package d3d9

import (
	"errors"
	"syscall"
	"unsafe"
)

var (
	dll             = syscall.NewLazyDLL("d3d9.dll")
	direct3DCreate9 = dll.NewProc("Direct3DCreate9")
)

// Create takes the SDK version as argument and returns a new Direct3D object.
// Use SDK_VERSION as the parameter.
func Create(version uint) (*Direct3D, error) {
	obj, _, _ := direct3DCreate9.Call(uintptr(version))
	if obj == 0 {
		return nil, errors.New("Direct3DCreate9 returned nil")
	}
	return (*Direct3D)(unsafe.Pointer(obj)), nil
}

// Direct3D and its methods are used to create Direct3D objects and set up the
// environment. Its interface includes methods for enumerating and retrieving
// capabilities of the device.
type Direct3D struct {
	vtbl *direct3DVtbl
}

type direct3DVtbl struct {
	QueryInterface uintptr
	AddRef         uintptr
	Release        uintptr

	RegisterSoftwareDevice      uintptr
	GetAdapterCount             uintptr
	GetAdapterIdentifier        uintptr
	GetAdapterModeCount         uintptr
	EnumAdapterModes            uintptr
	GetAdapterDisplayMode       uintptr
	CheckDeviceType             uintptr
	CheckDeviceFormat           uintptr
	CheckDeviceMultiSampleType  uintptr
	CheckDepthStencilMatch      uintptr
	CheckDeviceFormatConversion uintptr
	GetDeviceCaps               uintptr
	GetAdapterMonitor           uintptr
	CreateDevice                uintptr
}

// AddRef increments the reference count for an interface on an object. This
// method should be called for every new copy of a pointer to an interface on an
// object.
func (obj *Direct3D) AddRef() uint32 {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.AddRef,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint32(ret)
}

// Release has to be called when finished using the object to free its
// associated resources.
func (obj *Direct3D) Release() uint32 {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.Release,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint32(ret)
}

// RegisterSoftwareDevice registers a pluggable software device. Software
// devices provide software rasterization enabling applications to access a
// variety of software rasterizers.
func (obj *Direct3D) RegisterSoftwareDevice(initFunc uintptr) Error {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.RegisterSoftwareDevice,
		2,
		uintptr(unsafe.Pointer(obj)),
		initFunc,
		0,
	)
	return toErr(ret)
}

// GetAdapterCount returns the number of adapters on the system.
func (obj *Direct3D) GetAdapterCount() uint {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterCount,
		1,
		uintptr(unsafe.Pointer(obj)),
		0,
		0,
	)
	return uint(ret)
}

// GetAdapterIdentifier describes the physical display adapters present in the
// system when the IDirect3D9 interface was instantiated.
// Adapter must be a value from 0 to GetAdapterCount()-1.
func (obj *Direct3D) GetAdapterIdentifier(
	adapter uint,
	flags uint32,
) (id ADAPTER_IDENTIFIER, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.GetAdapterIdentifier,
		4,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(flags),
		uintptr(unsafe.Pointer(&id)),
		0,
		0,
	)
	err = toErr(ret)
	return
}

// GetAdapterModeCount returns the number of display modes available on this
// adapter.
func (obj *Direct3D) GetAdapterModeCount(adapter uint, format FORMAT) uint {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterModeCount,
		3,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(format),
	)
	return uint(ret)
}

// EnumAdapterModes queries the device to determine whether the specified
// adapter supports the requested format and display mode. This method could be
// used in a loop to enumerate all the available adapter modes.
//
// Allowed formats are as follows:
//   FMT_A1R5G5B5
//   FMT_A2R10G10B10
//   FMT_A8R8G8B8
//   FMT_R5G6B5
//   FMT_X1R5G5B5
//   FMT_X8R8G8B8
//
// EnumAdapterModes treats pixel formats 565 and 555 as equivalent, and returns
// the correct version. The difference comes into play only when the application
// locks the back buffer and there is an explicit flag that the application must
// set in order to accomplish this.
func (obj *Direct3D) EnumAdapterModes(
	adapter uint,
	format FORMAT,
	mode uint,
) (displayMode DISPLAYMODE, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.EnumAdapterModes,
		5,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(format),
		uintptr(mode),
		uintptr(unsafe.Pointer(&displayMode)),
		0,
	)
	err = toErr(ret)
	return
}

// GetAdapterDisplayMode retrieves the current display mode of the adapter.
func (obj *Direct3D) GetAdapterDisplayMode(
	adapter uint,
) (mode DISPLAYMODE, err Error) {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterDisplayMode,
		3,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(unsafe.Pointer(&mode)),
	)
	err = toErr(ret)
	return
}

// CheckDeviceType verifies whether a hardware accelerated device type can be
// used on this adapter.
func (obj *Direct3D) CheckDeviceType(
	adapter uint,
	deviceType DEVTYPE,
	displayFormat FORMAT,
	backBufferFormat FORMAT,
	windowed bool,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDeviceType,
		6,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(displayFormat),
		uintptr(backBufferFormat),
		uintptrBool(windowed),
	)
	return toErr(ret)
}

func uintptrBool(b bool) uintptr {
	if b {
		return 1
	}
	return 0
}

// CheckDeviceFormat determines whether a surface format is available as a
// specified resource type and can be used as a texture, depth-stencil buffer,
// or render target, or any combination of the three, on a device representing
// this adapter.
func (obj *Direct3D) CheckDeviceFormat(
	adapter uint,
	deviceType DEVTYPE,
	adapterFormat FORMAT,
	usage uint32,
	resType RESOURCETYPE,
	checkFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CheckDeviceFormat,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(adapterFormat),
		uintptr(usage),
		uintptr(resType),
		uintptr(checkFormat),
		0,
		0,
	)
	return toErr(ret)
}

// CheckDeviceMultiSampleType determines if a multisampling technique is
// available on this device.
func (obj *Direct3D) CheckDeviceMultiSampleType(
	adapter uint,
	deviceType DEVTYPE,
	surfaceFormat FORMAT,
	windowed bool,
	multiSampleType MULTISAMPLE_TYPE,
) (qualityLevels uint32, err Error) {
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CheckDeviceMultiSampleType,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(surfaceFormat),
		uintptrBool(windowed),
		uintptr(multiSampleType),
		uintptr(unsafe.Pointer(&qualityLevels)),
		0,
		0,
	)
	err = toErr(ret)
	return
}

// CheckDepthStencilMatch determines whether a depth-stencil format is
// compatible with a render-target format in a particular display mode.
func (obj *Direct3D) CheckDepthStencilMatch(
	adapter uint,
	deviceType DEVTYPE,
	adapterFormat FORMAT,
	renderTargetFormat FORMAT,
	depthStencilFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDepthStencilMatch,
		6,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(adapterFormat),
		uintptr(renderTargetFormat),
		uintptr(depthStencilFormat),
	)
	return toErr(ret)
}

// CheckDeviceFormatConversion tests the device to see if it supports conversion
// from one display format to another.
func (obj *Direct3D) CheckDeviceFormatConversion(
	adapter uint,
	deviceType DEVTYPE,
	sourceFormat FORMAT,
	targetFormat FORMAT,
) Error {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.CheckDeviceFormatConversion,
		5,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(sourceFormat),
		uintptr(targetFormat),
		0,
	)
	return toErr(ret)
}

// GetDeviceCaps retrieves device-specific information about a device.
func (obj *Direct3D) GetDeviceCaps(
	adapter uint,
	deviceType DEVTYPE,
) (caps CAPS, err Error) {
	ret, _, _ := syscall.Syscall6(
		obj.vtbl.GetDeviceCaps,
		4,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(unsafe.Pointer(&caps)),
		0,
		0,
	)
	err = toErr(ret)
	return
}

// GetAdapterMonitor returns the handle of the monitor associated with the
// Direct3D object.
func (obj *Direct3D) GetAdapterMonitor(adapter uint) HMONITOR {
	ret, _, _ := syscall.Syscall(
		obj.vtbl.GetAdapterMonitor,
		2,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		0,
	)
	return HMONITOR(ret)
}

// CreateDevice creates a device to represent the display adapter.
func (obj *Direct3D) CreateDevice(
	adapter uint,
	deviceType DEVTYPE,
	focusWindow HWND,
	behaviorFlags uint32,
	params PRESENT_PARAMETERS,
) (*Device, PRESENT_PARAMETERS, Error) {
	var device *Device
	ret, _, _ := syscall.Syscall9(
		obj.vtbl.CreateDevice,
		7,
		uintptr(unsafe.Pointer(obj)),
		uintptr(adapter),
		uintptr(deviceType),
		uintptr(focusWindow),
		uintptr(behaviorFlags),
		uintptr(unsafe.Pointer(&params)),
		uintptr(unsafe.Pointer(&device)),
		0,
		0,
	)
	return device, params, toErr(ret)
}


text:
/**
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the latest version of the GNU Lesser General
 * Public License as published by the Free Software Foundation;
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program (LICENSE.txt); if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.jamwiki.migrate;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.jamwiki.DataAccessException;
import org.jamwiki.Environment;
import org.jamwiki.WikiBase;
import org.jamwiki.WikiVersion;
import org.jamwiki.model.Namespace;
import org.jamwiki.model.RecentChange;
import org.jamwiki.model.Topic;
import org.jamwiki.model.TopicVersion;
import org.jamwiki.model.VirtualWiki;
import org.jamwiki.model.WikiUser;
import org.jamwiki.parser.WikiLink;
import org.jamwiki.utils.Pagination;
import org.jamwiki.utils.Utilities;
import org.jamwiki.utils.WikiLogger;
import org.jamwiki.utils.WikiUtil;
import org.jamwiki.utils.XMLUtil;

/**
 * Provide functionality for exporting a JAMWiki topic to Mediawiki XML format.
 */
public class MediaWikiXmlExporter implements TopicExporter {

	private static final WikiLogger logger = WikiLogger.getLogger(MediaWikiXmlExporter.class.getName());
	private static final SimpleDateFormat MEDIAWIKI_DATE_FORMATTER = new SimpleDateFormat(MediaWikiConstants.ISO_8601_DATE_FORMAT);

	/**
	 *
	 */
	public void exportToFile(File file, String virtualWiki, List<String> topicNames, boolean excludeHistory) throws MigrationException {
		OutputStreamWriter fileWriter = null;
		BufferedWriter bufferedWriter = null;
		boolean success = false;
		try {
			fileWriter = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
			bufferedWriter = new BufferedWriter(fileWriter);
			bufferedWriter.append("<mediawiki xmlns=\"http://www.mediawiki.org/xml/export-0.7/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.mediawiki.org/xml/export-0.7/ http://www.mediawiki.org/xml/export-0.7.xsd\" version=\"0.7\" xml:lang=\"en\">");
			this.writeSiteInfo(bufferedWriter, virtualWiki);
			this.writePages(bufferedWriter, virtualWiki, topicNames, excludeHistory);
			bufferedWriter.append("\n</mediawiki>");
			success = true;
		} catch (DataAccessException e) {
			throw new MigrationException(e);
		} catch (IOException e) {
			throw new MigrationException(e);
		} finally {
			IOUtils.closeQuietly(bufferedWriter);
			IOUtils.closeQuietly(fileWriter);
			if (!success) {
				// make sure partial files are deleted
				file.delete();
			}
		}
	}

	/**
	 * Return the URL of the index page for the wiki.
	 *
	 * @throws DataAccessException Thrown if any error occurs while retrieving data.
	 */
	private String retrieveBaseUrl() throws DataAccessException {
		VirtualWiki virtualWiki = VirtualWiki.defaultVirtualWiki();
		String url = Environment.getValue(Environment.PROP_SERVER_URL);
		WikiLink wikiLink = new WikiLink(WikiUtil.WEBAPP_CONTEXT_PATH, virtualWiki.getName(), virtualWiki.getRootTopicName());
		url += wikiLink.toRelativeUrl();
		return url;
	}

	/**
	 *
	 */
	private void writeSiteInfo(Writer writer, String virtualWikiName) throws DataAccessException, IOException {
		VirtualWiki virtualWiki = WikiBase.getDataHandler().lookupVirtualWiki(virtualWikiName);
		writer.append("\n<siteinfo>");
		String sitename = virtualWiki.getSiteName();
		writer.append('\n');
		XMLUtil.buildTag(writer, "sitename", sitename, true);
		String base = this.retrieveBaseUrl();
		writer.append('\n');
		XMLUtil.buildTag(writer, "base", base, true);
		String generator = "JAMWiki " + WikiVersion.CURRENT_WIKI_VERSION;
		writer.append('\n');
		XMLUtil.buildTag(writer, "generator", generator, true);
		/*
		Cannot have two titles differing only by case of first letter.  Default behavior through 1.5, $wgCapitalLinks = true
			<enumeration value="first-letter" />
		Complete title is case-sensitive. Behavior when $wgCapitalLinks = false
			<enumeration value="case-sensitive" />
		Cannot have two titles differing only by case. Not yet implemented as of MediaWiki 1.5
			<enumeration value="case-insensitive" />
		*/
		writer.append('\n');
		XMLUtil.buildTag(writer, "case", "case-sensitive", true);
		writer.append("\n<namespaces>");
		Map<String, String> attributes = new LinkedHashMap<String, String>();
		List<Namespace> namespaces = WikiBase.getDataHandler().lookupNamespaces();
		for (Namespace namespace : namespaces) {
			attributes.put("key", Integer.toString(namespace.getId()));
			writer.append('\n');
			XMLUtil.buildTag(writer, "namespace", namespace.getLabel(virtualWikiName), attributes, true);
		}
		writer.append("\n</namespaces>");
		writer.append("\n</siteinfo>");
	}

	/**
	 *
	 */
	private void writePages(Writer writer, String virtualWiki, List<String> topicNames, boolean excludeHistory) throws DataAccessException, IOException, MigrationException {
		// note that effort is being made to re-use temporary objects as this
		// code can generate an OOM "GC overhead limit exceeded" with HUGE (500MB) topics
		// since the garbage collector ends up being invoked excessively.
		TopicVersion topicVersion;
		Topic topic;
		WikiUser user;
		// choose 100,000 as an arbitrary default
		int maxRevisions = (Environment.getIntValue(Environment.PROP_MAX_TOPIC_VERSION_EXPORT) > 0) ? Environment.getIntValue(Environment.PROP_MAX_TOPIC_VERSION_EXPORT) : 100000;
		int revisionsRetrieved = 0;
		List<Integer> topicVersionIds;
		Map<String, String> textAttributes = new LinkedHashMap<String, String>();
		textAttributes.put("xml:space", "preserve");
		for (String topicName : topicNames) {
			topicVersionIds = new ArrayList<Integer>();
			topic = WikiBase.getDataHandler().lookupTopic(virtualWiki, topicName, false);
			if (topic == null) {
				throw new MigrationException("Failure while exporting: topic " + virtualWiki + ':' + topicName + " does not exist");
			}
			writer.append("\n<page>");
			writer.append('\n');
			XMLUtil.buildTag(writer, "title", topic.getName(), true);
			writer.append('\n');
			XMLUtil.buildTag(writer, "ns", topic.getNamespace().getId());
			writer.append('\n');
			XMLUtil.buildTag(writer, "id", topic.getTopicId());
			if (excludeHistory || (maxRevisions - revisionsRetrieved) <= 1) {
				// only include the most recent version
				topicVersionIds.add(topic.getCurrentVersionId());
			} else {
				// FIXME - changes sorted newest-to-oldest, should be reverse
				Pagination pagination = new Pagination(maxRevisions - revisionsRetrieved, 0);
				List<RecentChange> changes = WikiBase.getDataHandler().getTopicHistory(topic, pagination, true);
				revisionsRetrieved += changes.size();
				for (int i = (changes.size() - 1); i >= 0; i--) {
					topicVersionIds.add(changes.get(i).getTopicVersionId());
				}
			}
			for (int topicVersionId : topicVersionIds) {
				topicVersion = WikiBase.getDataHandler().lookupTopicVersion(topicVersionId);
				writer.append("\n<revision>");
				writer.append('\n');
				XMLUtil.buildTag(writer, "id", topicVersion.getTopicVersionId());
				writer.append('\n');
				XMLUtil.buildTag(writer, "timestamp", this.parseJAMWikiTimestamp(topicVersion.getEditDate()), true);
				writer.append("\n<contributor>");
				user = (topicVersion.getAuthorId() != null) ? WikiBase.getDataHandler().lookupWikiUser(topicVersion.getAuthorId()) : null;
				if (user != null) {
					writer.append('\n');
					XMLUtil.buildTag(writer, "username", user.getUsername(), true);
					writer.append('\n');
					XMLUtil.buildTag(writer, "id", user.getUserId());
				} else if (Utilities.isIpAddress(topicVersion.getAuthorDisplay())) {
					writer.append('\n');
					XMLUtil.buildTag(writer, "ip", topicVersion.getAuthorDisplay(), true);
				} else {
					writer.append('\n');
					XMLUtil.buildTag(writer, "username", topicVersion.getAuthorDisplay(), true);
				}
				writer.append("\n</contributor>");
				writer.append('\n');
				if (topicVersion.getEditType() == TopicVersion.EDIT_MINOR) {
					XMLUtil.buildTag(writer, "minor", "", true);
					writer.append('\n');
				}
				XMLUtil.buildTag(writer, "comment", topicVersion.getEditComment(), true);
				writer.append('\n');
				textAttributes.put("bytes", Long.toString(topicVersion.getVersionContent().getBytes().length));
				XMLUtil.buildTag(writer, "text", topicVersion.getVersionContent(), textAttributes, true);
				writer.append("\n</revision>");
				// explicitly null out temp variables to improve garbage collection and
				// avoid OOM "GC overhead limit exceeded" errors on HUGE (500MB) topics
				topicVersion = null;
				user = null;
			}
			writer.append("\n</page>");
		}
	}

	/**
	 *
	 */
	private String parseJAMWikiTimestamp(Timestamp timestamp) {
		return MEDIAWIKI_DATE_FORMATTER.format(timestamp);
	}
}


text:
« Back

Template Source: <samp>{{ template_name }}</samp>

{{ source }}