text:
import { connect } from "react-redux";
import RemoteExplorer from "../components/RemoteExplorer.js";
import { setDirectoryContents, setDirectoryLoading } from "../actions/remoteFiles.js";
import { getDropboxDirectoryContents, getGoogleDriveDirectoryContents, getWebDAVClient } from "../library/remote.js";
import { notifyError } from "../library/notify.js";
import log from "../../shared/library/log.js";
import { webdavContentsToTree } from "../library/webdav.js";
import { dropboxContentsToTree } from "../library/dropbox.js";
import {
    googleDriveContentsToTree,
    groupContentsByDirectory as groupGoogleDriveContentsByDirectory
} from "../../shared/library/googleDrive.js";
import { getAllDirectoryContents, getDirectoryContents, getDirectoriesLoading } from "../selectors/remoteFiles.js";
import { getLocalDirectoryContents, localContentsToTree } from "../library/localFile.js";

function contentsToTree(contents, fetchType) {
    switch (fetchType) {
        case "webdav":
            return webdavContentsToTree(contents);
        case "dropbox":
            return dropboxContentsToTree(contents);
        case "googledrive":
            return googleDriveContentsToTree(contents);
        case "localfile":
            return localContentsToTree(contents);
        default:
            notifyError(
                "Failed processing directory contents",
                "The remote source type was invalid for processing directory contents"
            );
            throw new Error(`Failed converting remote contents to tree: Unknown type: ${fetchType}`);
    }
}

function fetchRemoteDirectory(dispatch, directory, fetchType) {
    let fetchRemoteContents;
    switch (fetchType) {
        case "webdav":
            fetchRemoteContents = dir => getWebDAVClient().getDirectoryContents(dir);
            break;
        case "dropbox":
            fetchRemoteContents = dir => getDropboxDirectoryContents(dir);
            break;
        case "googledrive":
            fetchRemoteContents = () => getGoogleDriveDirectoryContents();
            break;
        case "localfile":
            fetchRemoteContents = dir => getLocalDirectoryContents(dir);
            break;
        default:
            notifyError(
                "Failed fetching directory contents",
                "The remote source type was invalid for making requests against"
            );
            throw new Error(`Unknown remote fetch type: ${fetchType}`);
    }
    dispatch(
        setDirectoryLoading({
            directory,
            isLoading: true
        })
    );
    log.info(`Fetching remote contents for path: ${directory}`);
    return fetchRemoteContents(directory)
        .then(contents => {
            log.info(`Received ${fetchType} directory contents: ${directory}`, contents);
            if (fetchType === "googledrive") {
                // ALL contents are returned, so sort
                const dirIndex = groupGoogleDriveContentsByDirectory(contents);
                ["/", ...Object.keys(dirIndex)].forEach(subDir => {
                    dispatch(
                        setDirectoryContents({
                            directory: subDir,
                            contents: dirIndex[subDir]
                        })
                    );
                });
            } else {
                dispatch(
                    setDirectoryContents({
                        directory,
                        contents
                    })
                );
            }
            dispatch(
                setDirectoryLoading({
                    directory,
                    isLoading: false
                })
            );
        })
        .catch(err => {
            notifyError(
                "Failed fetching directory contents",
                `Failed fetching the remote contents of '${directory}': ${err.message}`
            );
            log.error(`Failed fetching ${fetchType} contents of '${directory}': ${err.message}`);
            console.error(err);
            dispatch(
                setDirectoryLoading({
                    directory,
                    isLoading: false
                })
            );
        });
}

export default connect(
    (state, ownProps) => ({
        directoriesLoading: getDirectoriesLoading(state),
        rootDirectory: contentsToTree(getAllDirectoryContents(state), ownProps.fetchType)
    }),
    {
        onOpenDirectory: (directory, fetchType) => (dispatch, getState) => {
            const state = getState();
            const dirContents = getDirectoryContents(state, directory);
            if (!dirContents) {
                fetchRemoteDirectory(dispatch, directory, fetchType);
            }
        },
        onReady: fetchType => dispatch => {
            fetchRemoteDirectory(dispatch, "/", fetchType);
        }
    }
)(RemoteExplorer);

redpajama_set_name: RedPajamaGithub


text:
package org.apache.hadoop.hbase.stargate;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.HTablePool;
import org.apache.hadoop.hbase.util.Bytes;

import com.sun.jersey.server.impl.container.servlet.ServletAdaptor;

/**
 * Singleton class encapsulating global REST servlet state and functions.
 */
public class RESTServlet extends ServletAdaptor {

  private static final long serialVersionUID = 1L;
  public static final int DEFAULT_MAX_AGE = 60 * 60 * 4;       // 4 hours
  public static final String VERSION_STRING = "0.0.1";

  private static RESTServlet instance;

  private final HBaseConfiguration conf;
  protected Map<String,Integer> maxAgeMap =
    Collections.synchronizedMap(new HashMap<String,Integer>());

  /**
   * @return the RESTServlet singleton instance
   * @throws IOException
   */
  public synchronized static RESTServlet getInstance() throws IOException {
    if (instance == null) {
      instance = new RESTServlet();
    }
    return instance;
  }

  /**
   * Constructor
   * @throws IOException
   */
  public RESTServlet() throws IOException {
    this.conf = new HBaseConfiguration();
  }

  /**
   * Get or create a table pool for the given table.
   * @param name the table name
   * @return the table pool
   */
  protected HTablePool getTablePool(String name) {
    return HTablePool.getPool(conf, Bytes.toBytes(name));
  }

  /**
   * @return the servlet's global HBase configuration
   */
  protected HBaseConfiguration getConfiguration() {
    return conf;
  }

  /**
   * @param tableName the table name
   * @return the maximum cache age suitable for use with this table, in
   *  seconds
   * @throws IOException
   */
  public int getMaxAge(String tableName) throws IOException {
    Integer i = maxAgeMap.get(tableName);
    if (i != null) {
      return i.intValue();
    }
    HTablePool pool = this.getTablePool(tableName);
    HTable table = pool.get();
    if (table != null) {
      int maxAge = DEFAULT_MAX_AGE;
      for (HColumnDescriptor family:
          table.getTableDescriptor().getFamilies()) {
        int ttl = family.getTimeToLive();
        if (ttl < 0) {
          continue;
        }
        if (ttl < maxAge) {
          maxAge = ttl;
        }
      }
      maxAgeMap.put(tableName, maxAge);
      return maxAge;
    }
    return DEFAULT_MAX_AGE;
  }

  /**
   * Signal that a previously calculated maximum cache age has been
   * invalidated by a schema change.
   * @param tableName the table name
   */
  public void invalidateMaxAge(String tableName) {
    maxAgeMap.remove(tableName);
  }
}


text:
package z_archive;

import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.system.Txn;
import org.apache.jena.system.progress.MonitorOutputs;
import org.apache.jena.tdb2.TDB2Factory;
import org.apache.jena.tdb2.loader.DataLoader;
import org.apache.jena.tdb2.loader.LoaderFactory;

public class Jena1619_TransactionException {
    // Fix: Complete copy when copying, not materialization
    // QueryEngineTDB: QueryIteratorMaterializeBinding - needed?

    public static void main(String[] arguments) {
        // load sample data from backup file into tdb
        Dataset dataset = TDB2Factory.connectDataset("/home/afs/tmp/sample-data");
        if (Txn.calculateRead(dataset, dataset::isEmpty)) {
            DataLoader loader = LoaderFactory.createLoader(dataset.asDatasetGraph(), MonitorOutputs.outputTo(System.out));
            loader.startBulk();
            loader.load("/home/afs/Desktop/sample-data.nq.gz");
            loader.finishBulk();
        }

        // get all triples
        String sparql = "SELECT * WHERE { ?s ?p ?o . }";
        ResultSet results = query(dataset, sparql);

        Binding b = results.nextBinding();

        // print subject of first solution
        RDFNode subject = results.next().get("s");
        }

    private static ResultSet query(Dataset dataset, String sparql) {
        Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
        Model model = dataset.getNamedModel("urn:x-arq:UnionGraph");
        return Txn.calculateRead(dataset, () -> {
            try(QueryExecution queryExecution = QueryExecutionFactory.create(query, model)) {
                return ResultSetFactory.copyResults(queryExecution.execSelect());
            }
        });
    }

}


text:
#ifndef _GL_LOCALE_H

#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
@PRAGMA_COLUMNS@

/* The include_next requires a split double-inclusion guard.  */
#@INCLUDE_NEXT@ @NEXT_LOCALE_H@

#ifndef _GL_LOCALE_H
#define _GL_LOCALE_H

/* NetBSD 5.0 mis-defines NULL.  */
#include <stddef.h>

/* MacOS X 10.5 defines the locale_t type in <xlocale.h>.  */
#if @HAVE_XLOCALE_H@
# include <xlocale.h>
#endif

/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */

/* The definition of _GL_ARG_NONNULL is copied here.  */

/* The definition of _GL_WARN_ON_USE is copied here.  */

/* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
   On systems that don't define it, use the same value as GNU libintl.  */
#if !defined LC_MESSAGES
# define LC_MESSAGES 1729
#endif

#if @GNULIB_DUPLOCALE@
# if @REPLACE_DUPLOCALE@
#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
#   undef duplocale
#   define duplocale rpl_duplocale
#  endif
_GL_FUNCDECL_RPL (duplocale, locale_t, (locale_t locale) _GL_ARG_NONNULL ((1)));
_GL_CXXALIAS_RPL (duplocale, locale_t, (locale_t locale));
# else
#  if @HAVE_DUPLOCALE@
_GL_CXXALIAS_SYS (duplocale, locale_t, (locale_t locale));
#  endif
# endif
# if @HAVE_DUPLOCALE@
_GL_CXXALIASWARN (duplocale);
# endif
#elif defined GNULIB_POSIXCHECK
# undef duplocale
# if HAVE_RAW_DECL_DUPLOCALE
_GL_WARN_ON_USE (duplocale, "duplocale is buggy on some glibc systems - "
                 "use gnulib module duplocale for portability");
# endif
#endif

#endif /* _GL_LOCALE_H */
#endif /* _GL_LOCALE_H */


text:
package org.apache.camel.itest.osgi.core.seda;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;

/**
 * @version
 */
@RunWith(PaxExam.class)
public class SedaTest extends OSGiIntegrationTestSupport {

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() {
                from("seda:foo").to("mock:bar");
            }
        };
    }

    @Test
    public void testSendMessage() throws Exception {
        MockEndpoint mock =  getMandatoryEndpoint("mock:bar", MockEndpoint.class);
        assertNotNull("The mock endpoint should not be null", mock);

        mock.expectedBodiesReceived("Hello World");
        template.sendBody("seda:foo", "Hello World");
        assertMockEndpointsSatisfied();
    }

}


text:
author: spolsky
comments: true
date: 2010-10-29 15:44:21+00:00
layout: post
redirect_from: /2010/10/stack-overflow-results-featured-in-msdn-search
hero:
slug: stack-overflow-results-featured-in-msdn-search
title: Stack Overflow results featured in MSDN Search
wordpress_id: 5895
tags:
- company
- community
---

Did you notice anything different about [MSDN](http://msdn.microsoft.com/en-us/default.aspx) search lately?

[![Stack Overflow results on MSDN](/images/wordpress/stackoverflow-on-msdn.png)](/images/wordpress/stackoverflow-on-msdn.png)

MSDN is Microsoft's mega huge developer information portal, and we're happy to announce that starting today, Stack Overflow search results will be incorporated into the results when you search for something on MSDN. That lets you see official Microsoft developer documentation alongside the community conversations that you need to actually make sense of the "official" developer documentation.

Let me just say that I have been using Microsoft developer documentation since the Windows 1.0 API. In those days it was a big .HLP file with one entry for every Windows API call, and searching on my Zeos 386SX was instantaneous. In the early 1990s MSDN first appeared (it predated the web by a few years), shipped as a subscription service on monthly CD-ROMs.

Now programming has gotten so complicated that the official documentation never tells you everything you need to know. So I think it's just incredibly awesome that Microsoft has recognized that there has been a developer landslide from the vendor forums onto Stack Overflow. Give it a try!


text:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Reflection;

namespace WebsitePanel.Templates
{
    internal class BuiltinFunctions
    {
        public int Line { get; set; }
        public int Column { get; set; }
        public TemplateContext Context { get; set; }

        public bool IsDefined(string variable)
        {
            return Context.Variables.ContainsKey(variable);
        }

        public object IfDefined(string variable, object val)
        {
            return IsDefined(variable) ? val : "";
        }

        public new bool Equals(object objA, object objB)
        {
            return Object.Equals(objA, objB);
        }

        public bool NotEquals(object objA, object objB)
        {
            return !Equals(objA, objB);
        }

        public bool IsEven(object number)
        {
            try
            {
                Int32 num = Convert.ToInt32(number);
                return num % 2 == 0;
            }
            catch
            {
                throw new ParserException("Cannot convert IsEven() function parameter to integer", Line, Column);
            }
        }

        public bool IsOdd(object number)
        {
            try
            {
                Int32 num = Convert.ToInt32(number);
                return num % 2 == 1;
            }
            catch
            {
                throw new ParserException("Cannot convert IsOdd() function parameter to integer", Line, Column);
            }
        }

        public bool IsEmpty(string str)
        {
            return String.IsNullOrEmpty(str);
        }

        public bool IsNotEmpty(string str)
        {
            return !IsEmpty(str);
        }

        public bool IsNumber(object val)
        {
            try
            {
                int number = Convert.ToInt32(val);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public string ToUpper(string str)
        {
            if (str == null)
                return null;

            return str.ToUpper();
        }

        public string ToLower(string str)
        {
            if (str == null)
                return null;

            return str.ToLower();
        }

        public int Len(string str)
        {
            return String.IsNullOrEmpty(str) ? 0 : str.Length;
        }

        public string ToList(object collection, string propertyName, string delimiter)
        {
            IEnumerable list = collection as IEnumerable;
            if (list == null)
                throw new ParserException("Supplied collection must implement IEnumerable", Line, Column);

            // get property descriptor
            List<string> items = new List<string>();
            foreach (object item in list)
            {
                PropertyInfo prop = null;
                if(!String.IsNullOrEmpty(propertyName))
                {
                    prop = item.GetType().GetProperty(propertyName,
                        BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
                }

                if (prop != null)
                    items.Add(prop.GetValue(item, null).ToString());
                else
                    items.Add(item.ToString());
            }
            return String.Join(delimiter, items.ToArray());
        }

        public bool IsNull(object val)
        {
            return val == null;
        }

        public object IIf(bool condition, object trueValue, object falseValue)
        {
            return condition ? trueValue : falseValue;
        }

        public object Format(object val, string format)
        {
            if (val == null || !(val is IFormattable))
                return val;

            if (val is Int32)
                return ((Int32)val).ToString(format);
            else if (val is Decimal)
                return ((Decimal)val).ToString(format);
            else
                return val.ToString();
        }

        public string Trim(string str)
        {
            return str != null ? str.Trim() : null;
        }

        public int Compare(object obj1, object obj2)
        {
            if (obj1 == null || obj2 == null)
                throw new ParserException("Function argument cannot be NULL", Line, Column);

            if (!(obj1 is IComparable) || !(obj2 is IComparable))
                throw new ParserException("Function arguments must implement IComparable", Line, Column);

            return ((IComparable)obj1).CompareTo(obj2);
        }

        public bool CompareNoCase(string str1, string str2)
        {
            return String.Compare(str1, str2, true) == 0;
        }

        public string StripNewLines(string str)
        {
            return str != null ? str.Replace("\r\n", " ") : null;
        }

        public string TypeOf(object obj)
        {
            return obj != null ? obj.GetType().Name : null;
        }

        public Int32 CInt(object val)
        {
            try
            {
                return Convert.ToInt32(val);
            }
            catch
            {
                throw new ParserException("Value cannot be converted to Int32", Line, Column);
            }
        }

        public Double CDouble(object val)
        {
            try
            {
                return Convert.ToDouble(val);
            }
            catch
            {
                throw new ParserException("Value cannot be converted to Double", Line, Column);
            }
        }

        public DateTime CDate(object val)
        {
            try
            {
                return Convert.ToDateTime(val);
            }
            catch
            {
                throw new ParserException("Value cannot be converted to DateTime", Line, Column);
            }
        }
    }
}


text:
from unittest import TestCase

import simplejson as json

class TestDefault(TestCase):
    def test_default(self):
        self.assertEqual(
            json.dumps(type, default=repr),
            json.dumps(repr(type)))


text:
package com.voxela.gov.commands.government.sub.manage;

import java.util.ArrayList;

import org.bukkit.entity.Player;

import com.voxela.gov.Main;
import com.voxela.gov.checker.CheckFed;

import net.md_5.bungee.api.ChatColor;

public class LeaveCommand {

	public static void leave(Player player, String[] args) {

		if (CheckFed.getPlayerFed(player) == null) {
			player.sendMessage(Main.gamePrefix + ChatColor.RED + "You are not in a federation!");
			return;
		}

		String fed = CheckFed.getPlayerFed(player);

		if ( CheckFed.getChief(fed).equals(player.getUniqueId().toString()) ) {
			player.sendMessage(Main.gamePrefix + ChatColor.RED + "You can't abandon your federation!");
			return;
		}

		CheckFed.removeMember(player.getName(), fed);

	    player.sendMessage(Main.gamePrefix + ChatColor.GREEN + "You have left " + ChatColor.GOLD + CheckFed.getNiceName(fed) + ".");

		ArrayList<Player> online = CheckFed.getOnlinePlayersInFed(fed);

		for (Player fedPlayer : online) fedPlayer.sendMessage(Main.gamePrefix + ChatColor.DARK_AQUA + player.getName() + ChatColor.GRAY + " has left the federation.");

	    return;

	}
}


text:
'use strict'
module.exports = {
  up: function (queryInterface, Sequelize) {
    return queryInterface.addColumn('Users', 'accessToken', Sequelize.STRING).then(function () {
      return queryInterface.addColumn('Users', 'refreshToken', Sequelize.STRING)
    })
  },

  down: function (queryInterface, Sequelize) {
    return queryInterface.removeColumn('Users', 'accessToken').then(function () {
      return queryInterface.removeColumn('Users', 'refreshToken')
    })
  }
}


text:
.. Watson - Framework documentation master file, created by
   sphinx-quickstart on Fri Jan 17 14:49:48 2014.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

.. role:: python(code)
   :language: python

Watson - A Python 3 Web Framework
==============================================

    It's elementary my dear Watson

|Build Status| |Coverage Status| |Version| |Downloads| |Licence|

Watson is an easy to use framework designed to get out of your way and
let you code your application rather than spend time wrangling with the
framework. It follows the convention over configuration ideal, although
the convention can be overriden if required. Out of the box it comes
with a standard set of defaults to allow you to get coding straight
away!

Requirements
------------

Watson is designed for Python 3.3 and up.

Dependencies
------------

Watson currently requires the following modules to work out of the box:

-  `Jinja2`_
    - For view templating

These will be installed automatically if you have installed Watson via
pip.

Optional Dependencies
---------------------

Some packages within Watson require third party packages to run
correctly, these include:

-  `Memcached`_
    - pip package: python3-memcached

-  `Redis`_
    - pip package: redis

Notes about these dependencies can be found within the relevant
documentation in the :ref:`reference_library`.

Installation
------------

``pip install watson-framework``

Testing
-------

Watson can be tested with py.test. Simply activate your virtualenv and run :python:`python setup.py test`.

Benchmarks
----------

Using falcon-bench, Watson received the following requests per second (Django and Flask supplied for comparative purposes).

1. watson.........11,920 req/sec or 83.89 μs/req  (3x)
2. django..........7,696 req/sec or 129.94 μs/req (2x)
3. flask...........4,281 req/sec or 233.58 μs/req (1x)

Contributing
------------

If you would like to contribute to Watson, please feel free to issue a
pull request via Github with the associated tests for your code. Your
name will be added to the AUTHORS file under contributors.

Table of Contents
-----------------

.. include:: toc.rst.inc

.. _Jinja2: http://jinja.pocoo.org/docs/
.. _Memcached: http://pypi.python.org/pypi/python3-memcached/
.. _Redis: https://github.com/andymccurdy/redis-py

.. |Build Status| image:: https://api.travis-ci.org/watsonpy/watson-framework.png?branch=master
   :target: https://travis-ci.org/watsonpy/watson-framework
.. |Coverage Status| image:: https://coveralls.io/repos/watsonpy/watson-framework/badge.png
   :target: https://coveralls.io/r/watsonpy/watson-framework
.. |Version| image:: https://pypip.in/v/watson-framework/badge.png
   :target: https://pypi.python.org/pypi/watson-framework/
.. |Downloads| image:: https://pypip.in/d/watson-framework/badge.png
   :target: https://pypi.python.org/pypi/watson-framework/
.. |Licence| image:: https://pypip.in/license/watson-framework/badge.png
   :target: https://pypi.python.org/pypi/watson-framework/


text:
using namespace System::ComponentModel;
using namespace System::Collections::Generic;

namespace CefSharp
{
    interface class ILifeSpanHandler;
    interface class ILoadHandler;
    interface class IRequestHandler;
    interface class IMenuHandler;
    interface class IKeyboardHandler;

    public ref class BrowserCore : INotifyPropertyChanged
    {
    private:
        RtzCountdownEvent^ _loadCompleted;

        bool _isBrowserInitialized;
        bool _isLoading;
        bool _canGoBack;
        bool _canGoForward;

        int _contentsWidth;
        int _contentsHeight;

        String^ _tooltip;
        String^ _address;
        String^ _title;

        ILifeSpanHandler^ _lifeSpanHandler;
        ILoadHandler^ _loadHandler;
        IRequestHandler^ _requestHandler;
        IMenuHandler^ _menuHandler;
        IKeyboardHandler^ _keyboardHandler;

        IDictionary<String^, Object^>^ _boundObjects;

    public:
        virtual event PropertyChangedEventHandler^ PropertyChanged;

        BrowserCore(String^ address)
        {
            _loadCompleted = gcnew RtzCountdownEvent();
            _address = address;
            _boundObjects = gcnew Dictionary<String^, Object^>();
        }

        property bool IsBrowserInitialized
        {
            bool get() { return _isBrowserInitialized; }
        }

        property bool IsLoading
        {
            bool get() { return _isLoading; }
        }

        property bool CanGoBack
        {
            bool get() { return _canGoBack; }
        }

        property bool CanGoForward
        {
            bool get() { return _canGoForward; }
        }

        property int ContentsWidth
        {
            int get() { return _contentsWidth; }

            void set(int contentsWidth)
            {
                if (_contentsWidth != contentsWidth)
                {
                    _contentsWidth = contentsWidth;
                    PropertyChanged(this, gcnew PropertyChangedEventArgs(L"ContentsWidth"));
                }
            }
        }

        property int ContentsHeight
        {
            int get() { return _contentsHeight; }

            void set(int contentsHeight)
            {
                if (_contentsHeight != contentsHeight)
                {
                    _contentsHeight = contentsHeight;
                    PropertyChanged(this, gcnew PropertyChangedEventArgs(L"ContentsHeight"));
                }
            }
        }

        property String^ Address
        {
            String^ get() { return _address; }

            void set(String^ address)
            {
                if (_address != address)
                {
                    _address = address;
                    PropertyChanged(this, gcnew PropertyChangedEventArgs(L"Address"));

                    TooltipText = nullptr;
                }
            }
        }

        property String^ Title
        {
            String^ get() { return _title; }

            void set(String^ title)
            {
                if (_title != title)
                {
                    _title = title;
                    PropertyChanged(this, gcnew PropertyChangedEventArgs(L"Title"));
                }
            }
        }

        property String^ TooltipText
        {
            String^ get() { return _tooltip; }

            void set(String^ text)
            {
                if (_tooltip != text)
                {
                    _tooltip = text;
                   PropertyChanged(this, gcnew PropertyChangedEventArgs(L"TooltipText"));
                }
            }
        }

        virtual property ILifeSpanHandler^ LifeSpanHandler
        {
            ILifeSpanHandler^ get() { return _lifeSpanHandler; }
            void set(ILifeSpanHandler^ handler) { _lifeSpanHandler = handler; }
        }

        virtual property ILoadHandler^ LoadHandler
        {
            ILoadHandler^ get() { return _loadHandler; }
            void set(ILoadHandler^ handler) { _loadHandler = handler; }
        }

        virtual property IRequestHandler^ RequestHandler
        {
            IRequestHandler^ get() { return _requestHandler; }
            void set(IRequestHandler^ handler) { _requestHandler = handler; }
        }

        virtual property IMenuHandler^ MenuHandler
        {
            IMenuHandler^ get() { return _menuHandler; }
            void set(IMenuHandler^ handler) { _menuHandler = handler; }
        }

        virtual property IKeyboardHandler^ KeyboardHandler
        {
            IKeyboardHandler^ get() { return _keyboardHandler; }
            void set(IKeyboardHandler^ handler) { _keyboardHandler = handler; }
        }

        void CheckBrowserInitialization();

        void RegisterJsObject(String^ name, Object^ objectToBind);
        IDictionary<String^, Object^>^ GetBoundObjects();

        void SetNavState(bool isLoading, bool canGoBack, bool canGoForward);

        void OnInitialized();
        void OnLoad();
        void OnFrameLoadStart();
        void OnFrameLoadEnd();
    };
}


text:
using System;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MGTK.Tileset
{
    public class Tileset
    {
        public string Name;
        public List<TilesetItem> Items = new List<TilesetItem>();

        public Texture2D GetPicture(string assetName, int index)
        {
            TilesetItem item = Items.Find(i => i.AssetName == assetName);

            if (item == null || item.Sprites.Count - 1 < index)
                return null;

            return item.Sprites[index];
        }

        public Texture2D GetPicture(string assetName, string attribute, object value, int index)
        {
            TilesetItem item = Items.Find(i => i.AssetName == assetName && i.Attributes.Exists(a => a.Name == attribute && a.Value.ToString() == value.ToString()));

            if (item == null || item.Sprites.Count - 1 < index)
                return null;

            return item.Sprites[index];
        }

        public Texture2D GetPicture(string assetName, string attribute, object value)
        {
            return GetPicture(assetName, attribute, value, 0);
        }

        public Texture2D GetPicture(string assetName)
        {
            return GetPicture(assetName, 0);
        }
    }
}


text:
package org.apache.servicecomb.foundation.vertx.client.tcp;

import org.junit.Assert;
import org.junit.Test;

import io.vertx.core.Context;
import io.vertx.core.Vertx;
import io.vertx.core.impl.VertxImpl;
import mockit.Expectations;
import mockit.Mocked;

public class TestAbstractTcpClientPoolFactory {
  private TcpClientConfig normalClientConfig = new TcpClientConfig();

  private TcpClientConfig sslClientConfig = new TcpClientConfig();

  TcpClientPoolFactory factory = new TcpClientPoolFactory(normalClientConfig, sslClientConfig);

  @Test
  public void createClientPool(@Mocked Vertx vertx, @Mocked Context context) {
    new Expectations(VertxImpl.class) {
      {
        context.owner();
        result = vertx;
      }
    };
    TcpClientConnectionPool pool = factory.createClientPool(context);

    Assert.assertSame(normalClientConfig, pool.netClientWrapper.getClientConfig(false));
    Assert.assertSame(sslClientConfig, pool.netClientWrapper.getClientConfig(true));
  }
}


text:
package com.google.gerrit.server.restapi.project;

import com.google.common.base.Strings;
import com.google.gerrit.exceptions.InvalidNameException;
import com.google.gerrit.extensions.common.ChangeInfo;
import com.google.gerrit.extensions.common.ChangeInput;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
import com.google.gerrit.server.project.ProjectResource;
import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.UpdateException;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;

@Singleton
public class CreateChange implements RestModifyView<ProjectResource, ChangeInput> {
  private final com.google.gerrit.server.restapi.change.CreateChange changeCreateChange;
  private final Provider<CurrentUser> user;
  private final BatchUpdate.Factory updateFactory;

  @Inject
  public CreateChange(
      Provider<CurrentUser> user,
      BatchUpdate.Factory updateFactory,
      com.google.gerrit.server.restapi.change.CreateChange changeCreateChange) {
    this.updateFactory = updateFactory;
    this.changeCreateChange = changeCreateChange;
    this.user = user;
  }

  @Override
  public Response<ChangeInfo> apply(ProjectResource rsrc, ChangeInput input)
      throws PermissionBackendException, IOException, ConfigInvalidException,
          InvalidChangeOperationException, InvalidNameException, UpdateException, RestApiException {
    if (!user.get().isIdentifiedUser()) {
      throw new AuthException("Authentication required");
    }

    if (!Strings.isNullOrEmpty(input.project) && !rsrc.getName().equals(input.project)) {
      throw new BadRequestException("project must match URL");
    }

    input.project = rsrc.getName();
    return changeCreateChange.execute(updateFactory, input, rsrc);
  }
}


text:
using namespace std;

void loadFile(vector<unsigned char> & buffer, string const & filename) //designed for loading files from hard disk in an std::vector
{
  ifstream file(filename.c_str(), ios::in | ios::binary | ios::ate);

  // get filesize
  streamsize size = 0;
  if (file.seekg(0, ios::end).good())
    size = file.tellg();
  if (file.seekg(0, ios::beg).good())
    size -= file.tellg();

  // read contents of the file into the vector
  if (size > 0)
  {
    buffer.resize((size_t)size);
    file.read((char*)(&buffer[0]), size);
  }
  else
    buffer.clear();
}

UNIT_TEST(PngDecode)
{
//  // load and decode
//  vector<unsigned char> buffer, image;
//  loadFile(buffer, "../../data/font_0.png");
//  unsigned long w, h;
//  int error = DecodePNG(image, w, h, buffer.empty() ? 0 : &buffer[0], (unsigned long)buffer.size());
//
//  // if there's an error, display it
//  TEST_EQUAL(error, 0, ());
//  // the pixels are now in the vector "image", use it as texture, draw it, ...
//  TEST_GREATER(image.size(), 4, ("Image is empty???"));
//  TEST_EQUAL(w, 1024, ());
//  TEST_EQUAL(h, 1024, ());
}


text:
void setup(struct IridiumContext * context) {
  IR_early_init_Object(context);
  IR_init_Object(context);
}


text:
<?php

namespace Selkis\Elastix\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Selkis\Elastix\Components\ECCP;
use Selkis\Elastix\Components\phpAMI;
use Log;

class ControllerTelephonePanel extends Controller
{

    function __construct(){
		$this->ECCP = new ECCP();
		$this->host = config('elastix.host');
		$this->user = config('elastix.user');
		$this->pass = config('elastix.password');
		$this->model = config('elastix.ext_model');
		$this->port = config('elastix.port');
		$this->phpAMI = new phpAMI($this->user,$this->pass,$this->host,$this->port);
	}

	public function prueba(Request $request){
        return "hola";
    }

    public function getVista(Request $request){
		return view('elastix::barra');
	}

	public function getIndex(Request $request){
		try {
			$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        $r = $ECCP->getagentstatus($ext[config('elastix.value_ext_in')]);
	        $this->ECCP->disconnect();
	        return ['status' => $r->status, 'onhold'=>floatval($r->onhold)];
		} catch (Exception $e) {
			Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::getIndex', $e);
			return;
		}
	}
    /**
     * [agentlogin description]
     * @return [type] [description]
     */
    public function agentlogin(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        $r = $ECCP->loginagent($ext[config('elastix.value_ext_in')]);
	        $bFalloLogin = FALSE;
	        $this->ECCP->disconnect();
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::agentlogin', $e);
        }

    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function agentlogout(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        $r = $ECCP->logoutagent($ext[config('elastix.value_ext_in')]);
	        $bFalloLogin = FALSE;
	        $this->ECCP->disconnect();
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::agentlogout', $e);
        }
    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function abreak(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        $r = $ECCP->pauseagent($ext[config('elastix.value_ext_in')]);
	        $bFalloLogin = FALSE;
	        $this->ECCP->disconnect();
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::abreak', $e);
        }
    }

     /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function unbreak(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        $r = $this->ECCP->unpauseagent('2');
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::unbreak', $e);
        }
    }

     /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function hold(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $channel="DAHDI/i2/2126264000-";
	        $parkinglot="70";
			$timeout="30000";
			$login = $this->phpAMI->login();
			if ($login["Response"]=="Success") {
				$this->phpAMI->park($channel,$agent,$parkinglot,$timeout);
				$this->phpAMI->logoff();
			}
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::abreak', $e);
        }
    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function unhold(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        print_r($this->ECCP->getAgentStatus());
	        $r = $this->ECCP->unhold();
	        $this->ECCP->disconnect();
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::abreak', $e);
        }
    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function hangup(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        print_r($this->ECCP->getAgentStatus());
	        $r = $this->ECCP->hangup();
	        $this->ECCP->disconnect();
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::abreak', $e);
        }
    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function colgar(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
			$login = $this->phpAMI->login();
			if ($login["Response"]=="Success") {
				$array = $this->phpAMI->coreShowChannels();
				$SIP 	= "SIP/".$ext[config('elastix.value_ext_out')]."-";
				foreach($array as $datos2){
					foreach($datos2 as $datos3){
						foreach($datos3 as $dato){
							if (strpos($dato, $SIP) !== false) {
								$SIP = $dato;
							}
						}
					}
			 	}
			 	print_r($this->phpAMI->hangup($SIP));
				$this->phpAMI->logoff();

			}
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::abreak', $e);
        }
    }

    /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function call(Request $request)
    {
        try {
        	if ($request->destino != null) {
        		$ext = $this->model::where('ip', $request->ip())->first();
        		#Especificamos el contexto
                $strContext = "default";
				#indicamos el tiempo de espera de la marcación
                $strWaitTime = config('elastix.waitTime');
				#La prioridad para colocar la llamada
                $strPriority = 1;
				#maximo de reintentos
                $strMaxRetry = "1";
				#Troncal (Linea)
				$troncal=config('elastix.troncal');
				#Extensión origen
                $extension=$ext[config('elastix.value_ext_out')];
        		$errno=0;
                $errstr=0;
                $oSocket = fsockopen($this->host, $this->port, $errno, $errstr, 20);
                if (!$oSocket) {
                	return ['mgs'=>$errstr, 'code' => $errno];
                }else{
                	puts($oSocket, "Action: login\r\n");
                    fputs($oSocket, "Events: off\r\n");
                    fputs($oSocket, "Username: ".$strUser."\r\n");
                    fputs($oSocket, "Secret: ".$strSecret."\r\n\r\n");
                    fputs($oSocket, "Action: originate\r\n");
                    fputs($oSocket, "Channel: ".$troncal."".$destino."\r\n");
                    fputs($oSocket, "WaitTime: ".$strWaitTime."\r\n");
                    fputs($oSocket, "CallerId: ".$destino."\r\n");
                    fputs($oSocket, "Exten: ".$extension."\r\n");
                    fputs($oSocket, "Context: ".$strContext."\r\n");
                    fputs($oSocket, "Priority: ".$strPriority."\r\n\r\n");
                    fputs($oSocket, "Action: Logoff\r\n\r\n");
                    sleep(2);
                    fclose($oSocket);
                    return ['mgs' => $extension.' llamando a '.$request->destino, 'code'=>'WS001'];
                }
        	}
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::call', $e);
        }
    }

     /**
     * [agentlogin description]$this->ECCP
     * @return [type] [description]
     */
    public function transfer(Request $request)
    {
        try {
        	$ext = $this->model::where('ip', $request->ip())->first();
	        $agent = "Agent/".$ext[config('elastix.value_ext_in')]."";
	        $this->ECCP->connect($this->host, $this->user, $this->pass);
	        $this->ECCP->setAgentNumber($agent);
	        $this->ECCP->setAgentPass($ext[config('elastix.value_ext_in')]);
	        print_r($this->ECCP->getAgentStatus());
	        $r = $this->ECCP->transfercall($request->extnum);
	        $this->ECCP->disconnect();
	        return ['msg'=>'Transferido','code'=>'WS001'];
        } catch (Exception $e) {
        	Log::erro('Ha ocurrido un error inesperado en ControllerTelephonePanel::transfer', $e);
        }
    }
}


text:
var _ = require('./underscore_ext').default;
var Rx = require('./rx').default;

// XXX Should also do a takeUntil componentWillUnmount, perhaps
// via rx-react.
var rxEvents = (comp, ...args) => {
	var ev = {};
	comp.on = {};
	_.each(args, name => {
		var sub = new Rx.Subject();
		ev[name] = sub;
		comp.on[name] = sub.next.bind(sub);
	});
	return ev;
};

module.exports = {
	rxEvents
};


text:
package io.digdag.standards.command;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Optional;
import io.digdag.client.config.Config;
import io.digdag.client.config.ConfigFactory;
import io.digdag.core.archive.ProjectArchiveLoader;
import io.digdag.core.storage.StorageManager;
import io.digdag.spi.CommandContext;
import io.digdag.spi.CommandLogger;
import io.digdag.spi.CommandRequest;
import io.digdag.spi.CommandStatus;
import io.digdag.spi.TaskRequest;
import io.digdag.standards.command.kubernetes.KubernetesClient;
import io.digdag.standards.command.kubernetes.KubernetesClientConfig;
import io.digdag.standards.command.kubernetes.KubernetesClientFactory;
import io.digdag.standards.command.kubernetes.TemporalConfigStorage;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class KubernetesCommandExecutorTest
{
    private final ObjectMapper om = new ObjectMapper();
    private final ConfigFactory configFactory = new ConfigFactory(om);

    private Config systemConfig;
    @Mock private KubernetesClientFactory kubernetesClientFactory;
    @Mock private DockerCommandExecutor dockerCommandExecutor;
    @Mock private StorageManager storageManager;
    @Mock private ProjectArchiveLoader projectArchiveLoader;
    @Mock private CommandLogger commandLogger;

    @Before
    public void setUp()
            throws Exception
    {
        this.systemConfig = configFactory.create();
    }

    @Test
    public void testRun()
            throws Exception
    {
        final KubernetesCommandExecutor executor = spy(new KubernetesCommandExecutor(
                systemConfig, kubernetesClientFactory, dockerCommandExecutor,
                storageManager, projectArchiveLoader, commandLogger));
        final KubernetesCommandStatus commandStatus = KubernetesCommandStatus.of(false, om.createObjectNode().put("foo", "bar"));
        doReturn(mock(KubernetesClientConfig.class)).when(executor).createKubernetesClientConfig(any(Optional.class), any(Config.class), any(Config.class));
        doReturn(mock(TemporalConfigStorage.class)).when(executor).createTemporalConfigStorage(any(Config.class), any(String.class));
        doReturn(commandStatus).when(executor).runOnKubernetes(any(CommandContext.class), any(CommandRequest.class), any(KubernetesClient.class), any(TemporalConfigStorage.class), any(TemporalConfigStorage.class));
        when(kubernetesClientFactory.newClient(any(KubernetesClientConfig.class))).thenReturn(mock(KubernetesClient.class));

        CommandContext commandContext = mock(CommandContext.class);
        CommandRequest commandRequest = mock(CommandRequest.class);
        when(commandContext.getTaskRequest()).thenReturn(mock(TaskRequest.class));

        CommandStatus actual = executor.run(commandContext, commandRequest);
        assertThat(actual.isFinished(), is(commandStatus.isFinished()));
        assertThat(actual.toJson(), is(commandStatus.toJson()));
    }

    @Test
    public void testPoll()
            throws Exception
    {
        final KubernetesCommandExecutor executor = spy(new KubernetesCommandExecutor(
                systemConfig, kubernetesClientFactory, dockerCommandExecutor,
                storageManager, projectArchiveLoader, commandLogger));
        final KubernetesCommandStatus commandStatus = KubernetesCommandStatus.of(false, om.createObjectNode().put("foo", "bar"));
        doReturn(commandStatus).when(executor).getCommandStatusFromKubernetes(any(CommandContext.class), any(ObjectNode.class), any(KubernetesClient.class), any(TemporalConfigStorage.class));
        doReturn(mock(KubernetesClientConfig.class)).when(executor).createKubernetesClientConfig(any(Optional.class), any(Config.class), any(Config.class));
        doReturn(mock(TemporalConfigStorage.class)).when(executor).createTemporalConfigStorage(any(Config.class), any(String.class));
        when(kubernetesClientFactory.newClient(any(KubernetesClientConfig.class))).thenReturn(mock(KubernetesClient.class));

        CommandContext commandContext = mock(CommandContext.class);
        when(commandContext.getTaskRequest()).thenReturn(mock(TaskRequest.class));
        ObjectNode previousStatusJson = om.createObjectNode().put("cluster_name", "my_cluster");

        CommandStatus actual = executor.poll(commandContext, previousStatusJson);
        assertThat(actual.isFinished(), is(commandStatus.isFinished()));
        assertThat(actual.toJson(), is(commandStatus.toJson()));
    }
}


text:
package org.apache.gora.hbase.store;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.avro.util.Utf8;
import org.apache.gora.examples.generated.Employee;
import org.apache.gora.examples.generated.WebPage;
import org.apache.gora.hbase.GoraHBaseTestDriver;
import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.store.DataStoreMetadataFactory;
import org.apache.gora.store.DataStoreTestBase;
import org.apache.gora.store.impl.DataStoreMetadataAnalyzer;
import org.apache.gora.util.GoraException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

/**
 * Test case for HBaseStore.
 */
public class TestHBaseStore extends DataStoreTestBase {

  private Configuration conf;

  static {
    setTestDriver(new GoraHBaseTestDriver());
  }

  @Override
  public void setUp() throws Exception {
    super.setUp();
    conf = getTestDriver().getConf();
  }

  public GoraHBaseTestDriver getTestDriver() {
    return (GoraHBaseTestDriver) testDriver;
  }

  @Override
  public void assertSchemaExists(String schemaName) throws Exception {
    Admin admin = getTestDriver().getHbaseUtil().getAdmin();
    assertTrue("Table should exist for...", admin.tableExists(TableName.valueOf(schemaName)));
  }

  @Override
  public void assertPutArray() throws IOException {
    Connection conn = ConnectionFactory.createConnection(conf);
    TableName webPageTab = TableName.valueOf("WebPage");
    Table table = conn.getTable(webPageTab);
    Get get = new Get(Bytes.toBytes("com.example/http"));
    org.apache.hadoop.hbase.client.Result result = table.get(get);

    assertEquals(result.getFamilyMap(Bytes.toBytes("parsedContent")).size(), 4);
    assertTrue(Arrays.equals(result.getValue(Bytes.toBytes("parsedContent")
        ,Bytes.toBytes(0)), Bytes.toBytes("example")));

    assertTrue(Arrays.equals(result.getValue(Bytes.toBytes("parsedContent")
        ,Bytes.toBytes(3)), Bytes.toBytes("example.com")));
    table.close();
  }

  /**
   * Asserts that writing bytes actually works at low level in HBase.
   * Checks writing null unions too.
   */
  @Override
  public void assertPutBytes(byte[] contentBytes) throws IOException {

    // Check first the parameter "contentBytes" if written+read right.
    Connection conn = ConnectionFactory.createConnection(conf);
    TableName webPageTab = TableName.valueOf("WebPage");
    Table table = conn.getTable(webPageTab);

    Get get = new Get(Bytes.toBytes("com.example/http"));
    org.apache.hadoop.hbase.client.Result result = table.get(get);

    byte[] actualBytes = result.getValue(Bytes.toBytes("content"), null);
    assertNotNull(actualBytes);
    assertTrue(Arrays.equals(contentBytes, actualBytes));
    table.close();

    // Since "content" is an optional field, we are forced to reopen the DataStore
    // to retrieve the union correctly

    // Test writing+reading a null value. FIELD in HBASE MUST become DELETED
    webPageStore = testDriver.createDataStore(String.class, WebPage.class);
    WebPage page = webPageStore.get("com.example/http") ;
    page.setContent(null) ;
    webPageStore.put("com.example/http", page) ;
    webPageStore.close() ;
    webPageStore = testDriver.createDataStore(String.class, WebPage.class);
    page = webPageStore.get("com.example/http") ;
    assertNull(page.getContent()) ;
    // Check directly with HBase
    table = conn.getTable(webPageTab);
    get = new Get(Bytes.toBytes("com.example/http"));
    result = table.get(get);
    actualBytes = result.getValue(Bytes.toBytes("content"), null);
    assertNull(actualBytes);
    table.close();

    // Test writing+reading an empty bytes field. FIELD in HBASE MUST
    // become EMPTY (byte[0])
    page = webPageStore.get("com.example/http") ;
    page.setContent(ByteBuffer.wrap("".getBytes(Charset.defaultCharset()))) ;
    webPageStore.put("com.example/http", page) ;
    webPageStore.close() ;
    webPageStore = testDriver.createDataStore(String.class, WebPage.class);
    page = webPageStore.get("com.example/http") ;
    assertTrue(Arrays.equals("".getBytes(Charset.defaultCharset()),page.getContent().array())) ;
    // Check directly with HBase

    table = conn.getTable(TableName.valueOf("WebPage"));
    get = new Get(Bytes.toBytes("com.example/http"));
    result = table.get(get);
    actualBytes = result.getValue(Bytes.toBytes("content"), null);
    assertNotNull(actualBytes);
    assertEquals(0, actualBytes.length) ;
    table.close();
  }

  /**
   * Checks that when writing a top level union ['null','type']
   * the value is written in raw format
   * @throws Exception
   */
  @Test
  public void assertTopLevelUnions() throws Exception {
    WebPage page = webPageStore.newPersistent();

    // Write webpage data
    page.setUrl(new Utf8("http://example.com"));
    byte[] contentBytes = "example content in example.com".getBytes(Charset.defaultCharset());
    ByteBuffer buff = ByteBuffer.wrap(contentBytes);
    page.setContent(buff);
    webPageStore.put("com.example/http", page);
    webPageStore.flush() ;

    // Read directly from HBase
    Connection conn = ConnectionFactory.createConnection(conf);
    Table table = conn.getTable(TableName.valueOf("WebPage"));
    Get get = new Get(Bytes.toBytes("com.example/http"));
    org.apache.hadoop.hbase.client.Result result = table.get(get);

    byte[] bytesRead = result.getValue(Bytes.toBytes("content"), null);

    assertNotNull(bytesRead) ;
    assertTrue(Arrays.equals(bytesRead, contentBytes));
    table.close();
  }

  /**
   * Checks that when writing a top level union ['null','type']
   * with the option RAW_ROOT_FIELDS_OPTION=true
   * the column is not created, and when RAW_ROOT_FIELDS_OPTION=false
   * the null value is serialized
   * with Avro.
   * @throws Exception
   */
  @Test
  public void assertTopLevelUnionsNull() throws Exception {
    WebPage page = webPageStore.newPersistent();

    // Write webpage data
    page.setUrl(new Utf8("http://example.com"));
    page.setContent(null);     // This won't change internal field status to dirty, so
    page.setDirty("content") ; // need to change it manually
    webPageStore.put("com.example/http", page);
    webPageStore.flush() ;

    // Read directly from HBase
    Connection conn = ConnectionFactory.createConnection(conf);
    TableName webPageTab = TableName.valueOf("WebPage");
    Table table = conn.getTable(webPageTab);
    Get get = new Get(Bytes.toBytes("com.example/http"));
    org.apache.hadoop.hbase.client.Result result = table.get(get);
    table.close();
    byte[] contentBytes = result.getValue(Bytes.toBytes("content"), null);

    assertNull(webPageStore.get("com.example/http", new String[]{"content"})) ;
    assertTrue(contentBytes == null || contentBytes.length == 0) ;
  }

  @Override
  public void assertPutMap() throws IOException {
    Connection conn = ConnectionFactory.createConnection(conf);
    TableName webPageTab = TableName.valueOf("WebPage");
    Table table = conn.getTable(webPageTab);
    Get get = new Get(Bytes.toBytes("com.example/http"));
    org.apache.hadoop.hbase.client.Result result = table.get(get);

    byte[] anchor2Raw = result.getValue(Bytes.toBytes("outlinks")
        , Bytes.toBytes("http://example2.com"));
    assertNotNull(anchor2Raw);
    String anchor2 = Bytes.toString(anchor2Raw);
    assertEquals("anchor2", anchor2);
    table.close();
  }

  @Test
  public void assertScannerCachingValue() {
    assertEquals(1000, ((HBaseStore<String,WebPage>)this.webPageStore).getScannerCaching()) ;
    assertEquals(1000, ((HBaseStore<String,Employee>)this.employeeStore).getScannerCaching()) ;
  }

  @Test
  public void assertMetadataAnalyzer() throws GoraException, ClassNotFoundException {
      String analyzerName = this.getTestDriver().getDataStoreClass().getCanonicalName() + "MetadataAnalyzer" ;
      DataStoreMetadataAnalyzer metadataAnalyzer = DataStoreMetadataFactory.createAnalyzer(analyzerName, this.conf) ;
      assertEquals("HBASE", metadataAnalyzer.getType()) ;

      // Expectations
      List<String> expectedTables = new ArrayList<String>() ;
      expectedTables.add("Employee");
      expectedTables.add("WebPage");

      List<String> expectedEmployeeFamilies = new ArrayList<String>();
      expectedEmployeeFamilies.add("info");

      List<String> expectedWebPageFamilies = new ArrayList<String>();
      expectedWebPageFamilies.add("byteData");
      expectedWebPageFamilies.add("common");
      expectedWebPageFamilies.add("content");
      expectedWebPageFamilies.add("headers");
      expectedWebPageFamilies.add("outlinks");
      expectedWebPageFamilies.add("parsedContent");
      expectedWebPageFamilies.add("stringData");

      Map<String, List<String>> expectedFamilies = new HashMap<>();
      expectedFamilies.put("Employee", expectedEmployeeFamilies);
      expectedFamilies.put("WebPage", expectedWebPageFamilies);

      // Tests
      List<String> tables = metadataAnalyzer.getTablesNames() ;
      assertEquals(expectedTables, tables) ;

      for (String tableName: tables) {
          Object tableInfo = metadataAnalyzer.getTableInfo(tableName);
          assertTrue("fieldsInfo expected to be class HBaseTableMetadata", tableInfo instanceof HBaseTableMetadata);
          assertEquals(expectedFamilies.get(tableName), ((HBaseTableMetadata)tableInfo).getColumnFamilies());
      }
  }

  @Rule
  public ExpectedException expectedException = ExpectedException.none();

  @Test
  public void assertConfigurationException() throws GoraException {
    expectedException.expect(GoraException.class);
    expectedException.expectMessage("Gora-hbase-mapping does not include the name and keyClass in the databean.");

    Configuration exceptionalConf = HBaseConfiguration.create(conf);
    exceptionalConf.set("gora.hbase.mapping.file","gora-hbase-mapping-mismatch.xml");
    DataStoreFactory.createDataStore(HBaseStore.class, String.class, WebPage.class, exceptionalConf);
  }

  @Test
  @Ignore("HBase does not support Result#size() without limit set")
  @Override
  public void testResultSize() throws Exception {
  }

  @Test
  @Ignore("HBase does not support Result#size() without limit set")
  @Override
  public void testResultSizeStartKey() throws Exception {
  }

  @Ignore("HBase does not support Result#size() without limit set")
  @Override
  public void testResultSizeEndKey() throws Exception {
  }

  @Test
  @Ignore("HBase does not support Result#size() without limit set")
  @Override
  public void testResultSizeKeyRange() throws Exception {
  }

  @Test
  public void testNewVersionBehavior() throws IOException {
    // Following Test fails in HBase 2.0.5 when NEW_VERSION_BEHAVIOR == true
    // Persisting for cases where qualifier ==  null, deleting row does not delete the column family.
    // Once these issues are fixed, we could remove the workarounds we have added on
    // HBaseDataStore #put method.
    Connection conn = ConnectionFactory.createConnection(conf);

    TableName test = TableName.valueOf("Test");
    TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(test);
    ColumnFamilyDescriptorBuilder columnDescBuilder = ColumnFamilyDescriptorBuilder
            .newBuilder(Bytes.toBytes("test-family"));
    columnDescBuilder.setNewVersionBehavior(true);
    ColumnFamilyDescriptor columnDescriptor = columnDescBuilder.build();
    tableDescBuilder.setColumnFamily(columnDescriptor);
    TableDescriptor tableDescriptor = tableDescBuilder.build();

    conn.getAdmin().createTable(tableDescriptor);

    Table table = conn.getTable(test);

    Put put = new Put(Bytes.toBytes("com.example/http"));
    put.addColumn(Bytes.toBytes("test-family"), null, Bytes.toBytes("test-value"));
    table.put(put);

    Delete del = new Delete(Bytes.toBytes("com.example/http"));
    table.delete(del);

    Get get = new Get(Bytes.toBytes("com.example/http"));
    //get.addColumn(Bytes.toBytes("test-family"), null);
    Result result = table.get(get);
    byte[] value = result.getValue(Bytes.toBytes("test-family"), null);

    if (value != null) {
      // Test failed, this should be null after the delete row operation.
    }
  }
}


text:
package org.apache.mxnet

import org.apache.mxnet.init.Base._
import org.apache.mxnet.utils.CToScalaUtils
import java.io._
import java.security.MessageDigest

import scala.collection.mutable.{ArrayBuffer, ListBuffer}

/**
  * This object will generate the Scala documentation of the new Scala API
  * Two file namely: SymbolAPIBase.scala and NDArrayAPIBase.scala
  * The code will be executed during Macros stage and file live in Core stage
  */
private[mxnet] object APIDocGenerator{
  case class absClassArg(argName : String, argType : String, argDesc : String, isOptional : Boolean)
  case class absClassFunction(name : String, desc : String,
                           listOfArgs: List[absClassArg], returnType : String)

  def main(args: Array[String]) : Unit = {
    val FILE_PATH = args(0)
    val hashCollector = ListBuffer[String]()
    hashCollector += absClassGen(FILE_PATH, true)
    hashCollector += absClassGen(FILE_PATH, false)
    hashCollector += nonTypeSafeClassGen(FILE_PATH, true)
    hashCollector += nonTypeSafeClassGen(FILE_PATH, false)
    val finalHash = hashCollector.mkString("\n")
  }

  def MD5Generator(input : String) : String = {
    val md = MessageDigest.getInstance("MD5")
    md.update(input.getBytes("UTF-8"))
    val digest = md.digest()
    org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest)
  }

  def absClassGen(FILE_PATH : String, isSymbol : Boolean) : String = {
    // scalastyle:off
    val absClassFunctions = getSymbolNDArrayMethods(isSymbol)
    // Defines Operators that should not generated
    val notGenerated = Set("Custom")
    // TODO: Add Filter to the same location in case of refactor
    val absFuncs = absClassFunctions.filterNot(_.name.startsWith("_"))
      .filterNot(ele => notGenerated.contains(ele.name))
      .map(absClassFunction => {
      val scalaDoc = generateAPIDocFromBackend(absClassFunction)
      val defBody = generateAPISignature(absClassFunction, isSymbol)
      s"$scalaDoc\n$defBody"
    })
    val packageName = if (isSymbol) "SymbolAPIBase" else "NDArrayAPIBase"
    val apacheLicence = "/*\n* Licensed to the Apache Software Foundation (ASF) under one or more\n* contributor license agreements.  See the NOTICE file distributed with\n* this work for additional information regarding copyright ownership.\n* The ASF licenses this file to You under the Apache License, Version 2.0\n* (the \"License\"); you may not use this file except in compliance with\n* the License.  You may obtain a copy of the License at\n*\n*    http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n"
    val scalaStyle = "// scalastyle:off"
    val packageDef = "package org.apache.mxnet"
    val imports = "import org.apache.mxnet.annotation.Experimental"
    val absClassDef = s"abstract class $packageName"
    val finalStr = s"$apacheLicence\n$scalaStyle\n$packageDef\n$imports\n$absClassDef {\n${absFuncs.mkString("\n")}\n}"
    val pw = new PrintWriter(new File(FILE_PATH + s"$packageName.scala"))
    pw.write(finalStr)
    pw.close()
    MD5Generator(finalStr)
  }

  def nonTypeSafeClassGen(FILE_PATH : String, isSymbol : Boolean) : String = {
    // scalastyle:off
    val absClassFunctions = getSymbolNDArrayMethods(isSymbol)
    val absFuncs = absClassFunctions.map(absClassFunction => {
      val scalaDoc = generateAPIDocFromBackend(absClassFunction, false)
      if (isSymbol) {
        val defBody = s"def ${absClassFunction.name}(name : String = null, attr : Map[String, String] = null)(args : org.apache.mxnet.Symbol*)(kwargs : Map[String, Any] = null): org.apache.mxnet.Symbol"
        s"$scalaDoc\n$defBody"
      } else {
        val defBodyWithKwargs = s"def ${absClassFunction.name}(kwargs: Map[String, Any] = null)(args: Any*) : org.apache.mxnet.NDArrayFuncReturn"
        val defBody = s"def ${absClassFunction.name}(args: Any*) : org.apache.mxnet.NDArrayFuncReturn"
        s"$scalaDoc\n$defBodyWithKwargs\n$scalaDoc\n$defBody"
      }
    })
    val packageName = if (isSymbol) "SymbolBase" else "NDArrayBase"
    val apacheLicence = "/*\n* Licensed to the Apache Software Foundation (ASF) under one or more\n* contributor license agreements.  See the NOTICE file distributed with\n* this work for additional information regarding copyright ownership.\n* The ASF licenses this file to You under the Apache License, Version 2.0\n* (the \"License\"); you may not use this file except in compliance with\n* the License.  You may obtain a copy of the License at\n*\n*    http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* See the License for the specific language governing permissions and\n* limitations under the License.\n*/\n"
    val scalaStyle = "// scalastyle:off"
    val packageDef = "package org.apache.mxnet"
    val imports = "import org.apache.mxnet.annotation.Experimental"
    val absClassDef = s"abstract class $packageName"
    val finalStr = s"$apacheLicence\n$scalaStyle\n$packageDef\n$imports\n$absClassDef {\n${absFuncs.mkString("\n")}\n}"
    import java.io._
    val pw = new PrintWriter(new File(FILE_PATH + s"$packageName.scala"))
    pw.write(finalStr)
    pw.close()
    MD5Generator(finalStr)
  }

  // Generate ScalaDoc type
  def generateAPIDocFromBackend(func : absClassFunction, withParam : Boolean = true) : String = {
    val desc = ArrayBuffer[String]()
    desc += "  * <pre>"
      func.desc.split("\n").foreach({ currStr =>
      desc += s"  * $currStr"
    })
    desc += "  * </pre>"
    val params = func.listOfArgs.map({ absClassArg =>
      val currArgName = absClassArg.argName match {
                case "var" => "vari"
                case "type" => "typeOf"
                case _ => absClassArg.argName
      }
      s"  * @param $currArgName\t\t${absClassArg.argDesc}"
    })
    val returnType = s"  * @return ${func.returnType}"
    if (withParam) {
      s"  /**\n${desc.mkString("\n")}\n${params.mkString("\n")}\n$returnType\n  */"
    } else {
      s"  /**\n${desc.mkString("\n")}\n$returnType\n  */"
    }
  }

  def generateAPISignature(func : absClassFunction, isSymbol : Boolean) : String = {
    var argDef = ListBuffer[String]()
    func.listOfArgs.foreach(absClassArg => {
      val currArgName = absClassArg.argName match {
        case "var" => "vari"
        case "type" => "typeOf"
        case _ => absClassArg.argName
      }
      if (absClassArg.isOptional) {
        argDef += s"$currArgName : Option[${absClassArg.argType}] = None"
      }
      else {
        argDef += s"$currArgName : ${absClassArg.argType}"
      }
    })
    var returnType = func.returnType
    if (isSymbol) {
      argDef += "name : String = null"
      argDef += "attr : Map[String, String] = null"
    } else {
      argDef += "out : Option[NDArray] = None"
      returnType = "org.apache.mxnet.NDArrayFuncReturn"
    }
    val experimentalTag = "@Experimental"
    s"$experimentalTag\ndef ${func.name} (${argDef.mkString(", ")}) : $returnType"
  }

  // List and add all the atomic symbol functions to current module.
  private def getSymbolNDArrayMethods(isSymbol : Boolean): List[absClassFunction] = {
    val opNames = ListBuffer.empty[String]
    val returnType = if (isSymbol) "Symbol" else "NDArray"
    _LIB.mxListAllOpNames(opNames)
    // TODO: Add '_linalg_', '_sparse_', '_image_' support
    // TODO: Add Filter to the same location in case of refactor
    opNames.map(opName => {
      val opHandle = new RefLong
      _LIB.nnGetOpHandle(opName, opHandle)
      makeAtomicSymbolFunction(opHandle.value, opName, "org.apache.mxnet." + returnType)
    }).toList.filterNot(_.name.startsWith("_"))
  }

  // Create an atomic symbol function by handle and function name.
  private def makeAtomicSymbolFunction(handle: SymbolHandle, aliasName: String, returnType : String)
  : absClassFunction = {
    val name = new RefString
    val desc = new RefString
    val keyVarNumArgs = new RefString
    val numArgs = new RefInt
    val argNames = ListBuffer.empty[String]
    val argTypes = ListBuffer.empty[String]
    val argDescs = ListBuffer.empty[String]

    _LIB.mxSymbolGetAtomicSymbolInfo(
      handle, name, desc, numArgs, argNames, argTypes, argDescs, keyVarNumArgs)
    val argList = argNames zip argTypes zip argDescs map { case ((argName, argType), argDesc) =>
      val typeAndOption = CToScalaUtils.argumentCleaner(argName, argType, returnType)
      new absClassArg(argName, typeAndOption._1, argDesc, typeAndOption._2)
    }
    new absClassFunction(aliasName, desc.value, argList.toList, returnType)
  }
}


text:
/* Short forms of external names for systems with brain-damaged linkers. */

#ifndef __jdhuff_h__
#define __jdhuff_h__

#ifdef NEED_SHORT_EXTERNAL_NAMES
#define jpeg_make_d_derived_tbl	jMkDDerived
#define jpeg_fill_bit_buffer	jFilBitBuf
#define jpeg_huff_decode	jHufDecode
#endif /* NEED_SHORT_EXTERNAL_NAMES */

/* Derived data constructed for each Huffman table */

#define HUFF_LOOKAHEAD	8	/* # of bits of lookahead */

typedef struct {
  /* Basic tables: (element [0] of each array is unused) */
  INT32 maxcode[18];		/* largest code of length k (-1 if none) */
  /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */
  INT32 valoffset[17];		/* huffval[] offset for codes of length k */
  /* valoffset[k] = huffval[] index of 1st symbol of code length k, less
   * the smallest code of length k; so given a code of length k, the
   * corresponding symbol is huffval[code + valoffset[k]]
   */

  /* Link to public Huffman table (needed only in jpeg_huff_decode) */
  JHUFF_TBL *pub;

  /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of
   * the input data stream.  If the next Huffman code is no more
   * than HUFF_LOOKAHEAD bits long, we can obtain its length and
   * the corresponding symbol directly from these tables.
   */
  int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
} d_derived_tbl;

/* Expand a Huffman table definition into the derived format */
EXTERN(void) jpeg_make_d_derived_tbl
	JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
	     d_derived_tbl ** pdtbl));

/*
 * Fetching the next N bits from the input stream is a time-critical operation
 * for the Huffman decoders.  We implement it with a combination of inline
 * macros and out-of-line subroutines.  Note that N (the number of bits
 * demanded at one time) never exceeds 15 for JPEG use.
 *
 * We read source bytes into get_buffer and dole out bits as needed.
 * If get_buffer already contains enough bits, they are fetched in-line
 * by the macros CHECK_BIT_BUFFER and GET_BITS.  When there aren't enough
 * bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer
 * as full as possible (not just to the number of bits needed; this
 * prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer).
 * Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension.
 * On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains
 * at least the requested number of bits --- dummy zeroes are inserted if
 * necessary.
 */

typedef INT32 bit_buf_type;	/* type of bit-extraction buffer */
#define BIT_BUF_SIZE  32	/* size of buffer in bits */

/* If long is > 32 bits on your machine, and shifting/masking longs is
 * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE
 * appropriately should be a win.  Unfortunately we can't define the size
 * with something like  #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)
 * because not all machines measure sizeof in 8-bit bytes.
 */

typedef struct {		/* Bitreading state saved across MCUs */
  bit_buf_type get_buffer;	/* current bit-extraction buffer */
  int bits_left;		/* # of unused bits in it */
} bitread_perm_state;

typedef struct {		/* Bitreading working state within an MCU */
  /* Current data source location */
  /* We need a copy, rather than munging the original, in case of suspension */
  const JOCTET * next_input_byte; /* => next byte to read from source */
  size_t bytes_in_buffer;	/* # of bytes remaining in source buffer */
  /* Bit input buffer --- note these values are kept in register variables,
   * not in this struct, inside the inner loops.
   */
  bit_buf_type get_buffer;	/* current bit-extraction buffer */
  int bits_left;		/* # of unused bits in it */
  /* Pointer needed by jpeg_fill_bit_buffer. */
  j_decompress_ptr cinfo;	/* back link to decompress master record */
} bitread_working_state;

/* Macros to declare and load/save bitread local variables. */
#define BITREAD_STATE_VARS  \
	register bit_buf_type get_buffer;  \
	register int bits_left;  \
	bitread_working_state br_state

#define BITREAD_LOAD_STATE(cinfop,permstate)  \
	br_state.cinfo = cinfop; \
	br_state.next_input_byte = cinfop->src->next_input_byte; \
	br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
	get_buffer = permstate.get_buffer; \
	bits_left = permstate.bits_left;

#define BITREAD_SAVE_STATE(cinfop,permstate)  \
	cinfop->src->next_input_byte = br_state.next_input_byte; \
	cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
	permstate.get_buffer = get_buffer; \
	permstate.bits_left = bits_left

/*
 * These macros provide the in-line portion of bit fetching.
 * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer
 * before using GET_BITS, PEEK_BITS, or DROP_BITS.
 * The variables get_buffer and bits_left are assumed to be locals,
 * but the state struct might not be (jpeg_huff_decode needs this).
 *	CHECK_BIT_BUFFER(state,n,action);
 *		Ensure there are N bits in get_buffer; if suspend, take action.
 *      val = GET_BITS(n);
 *		Fetch next N bits.
 *      val = PEEK_BITS(n);
 *		Fetch next N bits without removing them from the buffer.
 *	DROP_BITS(n);
 *		Discard next N bits.
 * The value N should be a simple variable, not an expression, because it
 * is evaluated multiple times.
 */

#define CHECK_BIT_BUFFER(state,nbits,action) \
	{ if (bits_left < (nbits)) {  \
	    if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits))  \
	      { action; }  \
	    get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }

#define GET_BITS(nbits) \
	(((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))

#define PEEK_BITS(nbits) \
	(((int) (get_buffer >> (bits_left -  (nbits)))) & ((1<<(nbits))-1))

#define DROP_BITS(nbits) \
	(bits_left -= (nbits))

/* Load up the bit buffer to a depth of at least nbits */
EXTERN(boolean) jpeg_fill_bit_buffer
	JPP((bitread_working_state * state, register bit_buf_type get_buffer,
	     register int bits_left, int nbits));

/*
 * Code for extracting next Huffman-coded symbol from input bit stream.
 * Again, this is time-critical and we make the main paths be macros.
 *
 * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits
 * without looping.  Usually, more than 95% of the Huffman codes will be 8
 * or fewer bits long.  The few overlength codes are handled with a loop,
 * which need not be inline code.
 *
 * Notes about the HUFF_DECODE macro:
 * 1. Near the end of the data segment, we may fail to get enough bits
 *    for a lookahead.  In that case, we do it the hard way.
 * 2. If the lookahead table contains no entry, the next code must be
 *    more than HUFF_LOOKAHEAD bits long.
 * 3. jpeg_huff_decode returns -1 if forced to suspend.
 */

#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
{ register int nb, look; \
  if (bits_left < HUFF_LOOKAHEAD) { \
    if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
    get_buffer = state.get_buffer; bits_left = state.bits_left; \
    if (bits_left < HUFF_LOOKAHEAD) { \
      nb = 1; goto slowlabel; \
    } \
  } \
  look = PEEK_BITS(HUFF_LOOKAHEAD); \
  if ((nb = htbl->look_nbits[look]) != 0) { \
    DROP_BITS(nb); \
    result = htbl->look_sym[look]; \
  } else { \
    nb = HUFF_LOOKAHEAD+1; \
slowlabel: \
    if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
	{ failaction; } \
    get_buffer = state.get_buffer; bits_left = state.bits_left; \
  } \
}

/* Out-of-line case for Huffman code fetching */
EXTERN(int) jpeg_huff_decode
	JPP((bitread_working_state * state, register bit_buf_type get_buffer,
	     register int bits_left, d_derived_tbl * htbl, int min_bits));

#endif


text:
<!-- List of person-box's -->

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/core-selector/core-selector.html">
<link rel="import" href="person-box.html">
<link rel="import" href="box-list.html">

<polymer-element name="person-list" attributes="people query">
	<template>
		<style>
			:host {
				display: block;
				width: 100%;
			}
		</style>
		<box-list id="list" multi selector valueattr="crsid">
			<template repeat="{{person in people | filter(query) }}">
					<person-box
						class="itemBox"
						name="{{person.user.displayName}}"
						crsid="{{person.user._id}}"
						college="{{person.user.college == 'Unknown' ? (person.user.institutions.length > 0 ? person.user.institutions[0] : '&nbsp') : person.user.college}}"
						isStudent="{{person.user.isStudent}}"
						photo="{{person.user.photo === 'undefined' ? null : person.user.photo}}"
						roles="{{person.roles}}">
					</person-box>
			</template>
		</box-list>
	</template>
	<script>
		Polymer('person-list', {

			listFilter: function(item) {
				var q = this.query.toLowerCase();
				return (item.user.displayName.toLowerCase().indexOf(q) > -1 ||
						item.user._id.toLowerCase().indexOf(q) > -1 ||
						item.user.college.toLowerCase().indexOf(q) > -1 ||
						this.arraySearch(item.roles, q.toUpperCase()));
			},

			filter: function(items, q) {
				if (items && q) {
					return items.filter(this.listFilter.bind(this));
				}
				return items;
			},

			arraySearch: function (arr, q) {
				for (var i = 0; i < arr.length; i++) {
					if (arr[i].indexOf(q) > -1) return true;
				}
				return false;
			}
		});
	</script>
</polymer-element>


text:
title: Image Preloading

redirect_from:
  - os/v1.1/en/configuration/prepacking-docker-images/

---

## Image Preloading
---

On boot, RancherOS scans `/var/lib/rancher/preload/docker` and `/var/lib/rancher/preload/system-docker` directories and tries to load container image archives it finds there, with `docker load` and `system-docker load`.

The archives are `.tar` files, optionally compressed with `xz` or `gzip`. These can be produced by `docker save` command, e.g.:

```
$ docker save my-image1 my-image2 some-other/image3 | xz > my-images.tar.xz
```

The resulting files should be placed into `/var/lib/rancher/preload/docker` or `/var/lib/rancher/preload/system-docker` (depending on whether you want it preloaded into Docker or System Docker).

Pre-loading process only reads each new archive once, so it won't take time on subsequent boots (`<archive>.done` files are created to mark the read archives). If you update the archive (place a newer archive with the same name) it'll get read on the next boot as well.

Pre-packing docker images is handy when you're customizing your RancherOS distribution (perhaps, building cloud VM images for your infrastructure).