text:
<?php

namespace Eva\Mvc\View\Http;

use Zend\EventManager\EventManagerInterface;
use Zend\Mvc\MvcEvent;
use Zend\Mvc\View\Http\CreateViewModelListener;
use Zend\Mvc\View\Http\InjectViewModelListener;

/**
 * Eva Mvc View Bootstrap Manager
 * 1. Register  Eva\Mvc\View\InjectTemplateListener on bootstrap
 * 2. Add controller alias automatic when route is Eva default router
 * 3. Reset view root path by modules
 *
 * @category   Eva
 * @package    Eva_Mvc
 * @subpackage View
 * @copyright  Copyright (c) 2012 AlloVince (http://avnpc.com/)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class ViewManager extends \Zend\Mvc\View\Http\ViewManager
{

    protected $viewRootPath;

    /**
     * Prepares the view layer
     *
     * @param  ApplicationInterface $application
     * @return void
     */
    public function onBootstrap($event)
    {
        $application  = $event->getApplication();
        $services     = $application->getServiceManager();
        $config       = $services->get('Config');
        $events       = $application->getEventManager();
        $sharedEvents = $events->getSharedManager();

        $this->config   = isset($config['view_manager']) && (is_array($config['view_manager']) || $config['view_manager'] instanceof ArrayAccess)
                        ? $config['view_manager']
                        : array();
        $this->services = $services;
        $this->event    = $event;

        $routeNotFoundStrategy   = $this->getRouteNotFoundStrategy();
        $exceptionStrategy       = $this->getExceptionStrategy();
        $mvcRenderingStrategy    = $this->getMvcRenderingStrategy();
        $createViewModelListener = new CreateViewModelListener();
        $injectTemplateListener  = new InjectTemplateListener();
        $injectViewModelListener = new InjectViewModelListener();

        $this->registerMvcRenderingStrategies($events);
        $this->registerViewStrategies();

        $events->attach($routeNotFoundStrategy);
        $events->attach($exceptionStrategy);
        $events->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($injectViewModelListener, 'injectViewModel'), -100);
        $events->attach(MvcEvent::EVENT_RENDER_ERROR, array($injectViewModelListener, 'injectViewModel'), -100);
        $events->attach($mvcRenderingStrategy);

        $sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromArray'), -80);
        $sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($routeNotFoundStrategy, 'prepareNotFoundViewModel'), -90);
        $sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($createViewModelListener, 'createViewModelFromNull'), -80);
        $sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($injectTemplateListener, 'injectTemplate'), -90);
        $sharedEvents->attach('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH, array($injectViewModelListener, 'injectViewModel'), -100);
    }

    public function attach(EventManagerInterface $events)
    {
        $this->listeners[] = $events->attach('bootstrap', array($this, 'onBootstrap'), 10000);
        $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'beforeDispatch'), 100);
        $this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'), 0);
        //$this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, array($this, 'onRender'), 0);
    }

    public function beforeDispatch(MvcEvent $e)
    {
        //TODO: add here for temporary
        //Auto add controller Di alias by global router
        $configuration    = $e->getApplication()->getConfig();
        $routeMatch = $e->getRouteMatch();
        if($routeMatch && $routeMatch  instanceof \Zend\Mvc\Router\RouteMatch){
            $routeMatchName =  $routeMatch->getMatchedRouteName();
            $controllerName =  $routeMatch->getParam('controller');

            if(isset($configuration['router']['routes'][$routeMatchName])
                && $routeConfiguration = $configuration['router']['routes'][$routeMatchName]
            ){
                if(isset($routeConfiguration['type'])
                   && $routeConfiguration['type'] === 'Eva\Mvc\Router\Http\ModuleRoute'
                   && class_exists($controllerName)){
                    $configuration['controller']['classes'][$controllerName] = $controllerName;
                }
            }
        }
        $controllerLoader = $e->getApplication()->getServiceManager()->get('ControllerLoader');
        if (isset($configuration['controller'])) {
            foreach ($configuration['controller'] as $type => $specs) {
                if ($type == 'classes') {
                    foreach ($specs as $name => $value) {
                        $controllerLoader->setInvokableClass($name, $value);
                    }
                }
                if ($type == 'factories') {
                    foreach ($specs as $name => $value) {
                        $controllerLoader->setFactory($name, $value);
                    }
                }
            }
        }
    }

    /**
     * Set module view root path to module/{module name}/view
     * Reset layout by config->module_namespace_layout_map
     *
     * @return ViewHelperLoader
     */
    public function onDispatch(MvcEvent $e)
    {
        $routeParams = $e->getRouteMatch()->getParams();
        if(false === isset($routeParams['module']) || !$routeParams['module']){
            return false;
        }

        $controller = $e->getTarget();
        if(!$controller instanceof \Zend\Mvc\Controller\AbstractActionController && !$controller instanceof \Zend\Mvc\Controller\AbstractRestfulController){
            //Event should trigger after route matched and found controller
            throw new \Zend\Mvc\Exception\RuntimeException(printf(
                '%s should be only trigger on mvc dispatch event',
                __METHOD__
            ));
        }
        $object = new \ReflectionObject($controller);
        $controllerFullPath = $object->getFileName();
        $controllerClassname = $object->getName();

        $classRootPath = substr($controllerFullPath, 0, 0 - strlen($controllerClassname . '.php'));
        $moduleRootPath = $classRootPath . '..';
        $this->viewRootPath = $moduleRootPath . DIRECTORY_SEPARATOR . 'view';

        $moduleNamespace = isset($routeParams['moduleNamespace']) ? $routeParams['moduleNamespace'] : '';
        if($moduleNamespace && $routeParams['moduleNamespace'] && $routeParams['moduleNamespace'] != $routeParams['module']){
            $this->viewRootPath .= DIRECTORY_SEPARATOR . '_' . strtolower($routeParams['moduleNamespace']);
        }

        if($moduleNamespace && isset($this->config['module_namespace_layout_map'])
            && !isset($this->config['layout'])
            && isset($this->config['module_namespace_layout_map'][ucfirst($moduleNamespace)])
        ) {
            $viewModel = $this->getViewModel();
            $template = $viewModel->getTemplate();
            if($template == 'layout/layout'){
                $controller->layout('layout/' . $moduleNamespace);
            }
        }

        $templatePathStack = new \Zend\View\Resolver\TemplatePathStack();
        //All path defined in config will be clear here
        $templatePathStack->setPaths(array($this->viewRootPath));
        $this->resolver->attach($templatePathStack);
    }

    /*
    public function onRender(MvcEvent $event)
    {
        $application  = $event->getApplication();
        $services     = $application->getServiceManager();
        $services->get('Translator');
    }
    */

}


text:
'use strict';
var gulp 		= require('gulp'),
	postcss 	= require('gulp-postcss'),
	autoprefix 	= require('autoprefixer');

const s = require('sass');
const sass = require('gulp-sass')(s);

var dir = './',
	source = './source/';

/**
 * Generate new style from css/sass/style/*.scss
 */
gulp.task('css', function () {
	return gulp.src(source + 'main.scss')
		//.src(requiredSource + 'main.scss')
		.pipe(sass({
			outputStyle: 'expanded', // expanded compressed compact nested
		}).on('error', sass.logError))
		.pipe(postcss([
			autoprefix()
        ]))
		.pipe(gulp.dest(dir));
});

/**
 * Watch files
 */
gulp.task('watch', function () {
	gulp.series('css')();
	gulp.watch(source + '**/*', gulp.series('css'));
});

redpajama_set_name: RedPajamaGithub


text:
package org.lockss.util;

import java.util.Arrays;
import java.util.TimeZone;

import org.lockss.test.LockssTestCase;

public class TestTimeZoneUtil extends LockssTestCase {

  public void testIsBasicTimeZoneDataAvailable() {
    assertTrue(TimeZoneUtil.isBasicTimeZoneDataAvailable());
  }

  public void testGoodTimeZones() throws Exception {
    for (String id : TimeZoneUtil.BASIC_TIME_ZONES) {
      TimeZone tz = TimeZoneUtil.getExactTimeZone(id);
      assertEquals(id, tz.getID());
      assertEquals("GMT".equals(id), "GMT".equals(tz.getID()));
    }
  }

  public void testBadTimeZones() throws Exception {
    for (String id : Arrays.asList(null,
                                   "Foo",
                                   "America/Copenhagen",
                                   "Europe/Tokyo")) {
      try {
        TimeZone tz = TimeZoneUtil.getExactTimeZone(id);
        fail("Should have thrown IllegalArgumentException: " + id);
      }
      catch (IllegalArgumentException iae) {
        if (id == null) {
          assertEquals("Time zone identifier cannot be null", iae.getMessage());
        }
        else {
          assertEquals("Unknown time zone identifier: " + id, iae.getMessage());
        }
      }
    }
  }

}


text:
export type FlipperPluginReceiverRes =
  | object
  | string
  | number
  | boolean
  | null
  | undefined
  | void;
export type FlipperPluginReceiver = (
  data: any,
) => FlipperPluginReceiverRes | Promise<FlipperPluginReceiverRes>;
export interface FlipperPluginConnection {
  /**
   * Send an `execute` message to Flipper.
   * Here is what client sends over the wire:
   * { method: 'execute', params: { api: pluginID, method, params } }
   *
   * @param method Method name that needs to be executed by Flipper
   * @param params Any extra params required for the method execution
   */
  send(method: string, params?: unknown): void;
  /**
   * Listen to messages for the method provided and execute a callback when one arrives.
   * Send response back to Flipper.
   * Read more about responses at https://fbflipper.com/docs/extending/new-clients#responding-to-messages
   *
   * @param method Method name that Flipper sent to the client
   * @param receiver A callback executed by the client when a message with the specified method arrives.
   * If this callback throws or returns a rejected Promise, client send an error message to Flipper.
   * If this callback returns any value (even undefined) synchronously, client sends it as a success message to Flipper.
   * If this callback returns a Promise, clients sends the value it is resolved with as a success message to Flipper.
   */
  receive(method: string, receiver: FlipperPluginReceiver): void;
}

// DOCS_FLIPPER_PLUGIN_START
export interface FlipperPlugin {
  /**
   * @return The id of this plugin. This is the namespace which Flipper desktop plugins will call
   *     methods on to route them to your plugin. This should match the id specified in your React
   *     plugin.
   */
  getId(): string;

  /**
   * Called when a connection has been established. The connection passed to this method is valid
   * until {@link FlipperPlugin#onDisconnect()} is called.
   */
  onConnect(connection: FlipperPluginConnection): void;

  /**
   * Called when the connection passed to `FlipperPlugin#onConnect(FlipperConnection)` is no
   * longer valid. Do not try to use the connection in or after this method has been called.
   */
  onDisconnect(): void;

  /**
   * Returns true if the plugin is meant to be run in background too, otherwise it returns false.
   */
  runInBackground?(): boolean;
}
// DOCS_FLIPPER_PLUGIN_END


text:
package org.onosproject.net.pi.runtime;

import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;

/**
 * Data of a counter cell of a protocol-independent pipeline.
 */

@Beta
public final class PiCounterCellData {

    private final long packets;
    private final long bytes;

    /**
     * Creates a new counter cell data for the given number of packets and bytes.
     *
     * @param packets  number of packets
     * @param bytes  number of bytes
     */
    public PiCounterCellData(long packets, long bytes) {
        this.packets = packets;
        this.bytes = bytes;
    }

    /**
     * Returns the packet count value contained by this counter data.
     *
     * @return number of packets
     */
    public long packets() {
        return packets;
    }

    /**
     * Returns the byte count value contained by this counter data.
     *
     * @return number of bytes
     */
    public long bytes() {
        return bytes;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof PiCounterCellData)) {
            return false;
        }
        PiCounterCellData that = (PiCounterCellData) o;
        return packets == that.packets &&
                bytes == that.bytes;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(packets, bytes);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("packets", packets)
                .add("bytes", bytes)
                .toString();
    }
}


text:
package org.artifactory.api.governance;

import org.apache.commons.lang.StringUtils;
import org.artifactory.api.maven.MavenArtifactInfo;
import org.artifactory.api.module.ModuleInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * @author Dan Feldman
 * @author Chen Keinan
 */
public class ExtComponentCoordinates implements Serializable {
    private static final Logger log = LoggerFactory.getLogger(ExtComponentCoordinates.class);

    //Packages that are separated by '/' and have a version that consists of 4 numbers are converted to links by browsers
    private static final String MAIL_COMPATIBLE_DELIMITER = ":";

    //Namespace prefixes
    public enum PackageType {
        MAVEN("org.apache.maven"), NUGET("org.nuget"), UNSPECIFIED("");

        private final String stringValue;

        PackageType(final String s) {
            stringValue = s;
        }

        public String toString() {
            return stringValue;
        }
    }

    private PackageType packageType;
    private String coordinates;
    private String groupId;
    private String name;
    private String nameSpace;
    private String version;
    private String externalId;
    private String mailCompatibleCoordinates; // :(

    public ExtComponentCoordinates() {

    }

    /**
     * To be used only when coordinates are not used to directly resolve components (i.e.
     */
    public ExtComponentCoordinates(String coordinates) {
        name = "";
        version = "";
        packageType = PackageType.UNSPECIFIED;
        this.coordinates = coordinates;
    }

    /**
     * No groupId (i.e. NuGet)
     */
    public ExtComponentCoordinates(String packageName, String packageVersion, PackageType packageType) {
        this.name = StringUtils.isNotBlank(packageName) ? packageName : "";
        this.version = StringUtils.isNotBlank(packageVersion) ? packageVersion : "";
        this.packageType = packageType;
        this.coordinates = assembleCoordinates(packageType, null, packageName, packageVersion);
    }

    /**
     * Maven
     */
    public ExtComponentCoordinates(MavenArtifactInfo artifactInfo) {
        this.name = StringUtils.isNotBlank(artifactInfo.getArtifactId()) ? artifactInfo.getArtifactId() : "";
        this.version = StringUtils.isNotBlank(artifactInfo.getVersion()) ? artifactInfo.getVersion() : "";
        this.groupId = StringUtils.isNotBlank(artifactInfo.getGroupId()) ? artifactInfo.getGroupId() : "";
        this.packageType = PackageType.MAVEN;
        this.coordinates = assembleCoordinates(packageType, groupId, name, version);
    }

    public ExtComponentCoordinates(ModuleInfo moduleInfo, PackageType packageType) {
        this.groupId = StringUtils.isNotBlank(moduleInfo.getOrganization()) ? moduleInfo.getOrganization() : "";
        this.name = StringUtils.isNotBlank(moduleInfo.getModule()) ? moduleInfo.getModule() : "";
        StringBuilder version = new StringBuilder(StringUtils.isNotBlank(moduleInfo.getBaseRevision())
                ? moduleInfo.getBaseRevision() : "");
        version.append(StringUtils.isNotBlank(moduleInfo.getFolderIntegrationRevision())
                ? "-" + moduleInfo.getFolderIntegrationRevision() : "");
        this.version = version.toString();
        this.packageType = packageType;
        this.coordinates = assembleCoordinates(packageType, groupId, name, this.version);
    }

    private String assembleCoordinates(PackageType packageType, String groupId, String name, String version) {
        String delimiter = getDelimiterByPackageType(packageType);
        StringBuilder coordinates = new StringBuilder();
        StringBuilder mailCoordinates = new StringBuilder();
        if (StringUtils.isNotBlank(groupId)) {
            coordinates.append(groupId).append(delimiter);
            mailCoordinates.append(groupId).append(MAIL_COMPATIBLE_DELIMITER);
        }
        if (StringUtils.isNotBlank(name)) {
            coordinates.append(name);
            mailCoordinates.append(name);
        }
        if (StringUtils.isNotBlank(version)) {
            coordinates.append(delimiter).append(version);
            mailCoordinates.append(MAIL_COMPATIBLE_DELIMITER).append(version);
        }
        log.debug("Creating Black Duck component coordinates for {} package: {}, version: {}, with Code Center " +
                        "Namespace: {}.  Coordinates are: {}",
                StringUtils.isBlank(groupId) ? "" : "groupId: " + groupId,
                name, version, packageType, coordinates);
        this.mailCompatibleCoordinates = mailCoordinates.toString();
        return coordinates.toString();
    }

    public String getNamespace() {
        return this.nameSpace;
    }

    public String getCoordinates() {
        return coordinates;
    }

    public String getMailCompatibleCoordinates() {
        return mailCompatibleCoordinates;
    }

    public String getName() {
        return name;
    }

    public String getVersion() {
        return version;
    }

    /**
     * @return externalId if set, coordinates if not
     */
    public String getExternalId() {
        return StringUtils.isNotBlank(externalId) ? externalId : coordinates;
    }

    public void setExternalId(String externalId) {
        this.externalId = externalId;
    }

    public boolean isValid() {
        return StringUtils.isNotBlank(name) && StringUtils.isNotBlank(version) && StringUtils.isNotBlank(coordinates)
                && packageType != null;
    }

    private String getDelimiterByPackageType(PackageType packageType) {
        if (PackageType.MAVEN.equals(packageType)) {
            return ":";
        } else if (PackageType.NUGET.equals(packageType)) {
            return "/";
        }
        return "";
    }

    public PackageType getPackageType() {
        return packageType;
    }

    public void setPackageType(PackageType packageType) {
        this.packageType = packageType;
    }

    public void setCoordinates(String coordinates) {
        this.coordinates = coordinates;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public void setMailCompatibleCoordinates(String mailCompatibleCoordinates) {
        this.mailCompatibleCoordinates = mailCompatibleCoordinates;
    }

    public void setNameSpace(String nameSpace) {
        this.nameSpace = nameSpace;
    }
}


text:
import string
import copy
import os
import gzip
import gtk
import commands

try:
    from backports import lzma
except ImportError:
    from lzma import LZMAFile as lzma

import singletons
from common import *
import common; _ = common._
from Source import *
from Package import *
from Category import *

def czfind(istr):
    l = len(istr)
    i = 0
    word = ''
    flag = False
    while i < l:
      if istr[i] == '\n':
        if flag:
          flag = False
        else:
          break
        word = ''
      elif istr[i] == ' ':
        flag = True
      else:
        word += istr[i]
      i += 1
    return word

class PackagePool:
    """This class retrieves and structures every packages that are accessible
        from the system."""

    HASHED_LEN = 2  # used by GetUpgradeableState

    def __init__(self):
        self.initialized = False

    def Init(self):
        """Reinitialize the inner state of the package pool.  Must be called
            in case of manipulating the package registry."""
        self.initialized = False
        self.all_packages = []
        self.package_name_pool = {}
        self.installed_package_names = {}
        singletons.application.DisplayProgress(_('Reading package sources'))
        self.RegisterUpgradablePackages()
        self.all_sources = self.GetSources()
        singletons.application.DisplayProgress(_('Querying installed packages'))
        self.RegisterInstalledPackages()
        self.RegisterInstallablePackages()
        self.initialized = True

    def GetSources(self):
        """Retrieve and return the Source objects containted in urpmi.cfg."""

        def get_source_name(line):
            """Extract the source name from the line of the file."""
            prev_chr = line[0]
            name = line[0]
            for c in line[1:-1]:
                if c == ' ':
                    if prev_chr == '\\':
                        name += ' '
                    else:
                        break
                elif c != '\\':
                    name += c
                prev_chr = c
            return name

        file = open('/etc/urpmi/urpmi.cfg')
        sources = []
        word = ''
        flag0 = False
        flag1 = False
        name_flag = False
        while 1:
          c = file.read(1)
          if c == '':
              break
          elif c == '{':
              if flag0 == False:
                 flag0 = True
              else:
                 name_flag = False
                 name = get_source_name(word)
                 source = Source(name)
                 source.hdlist = czfind(commands.getoutput('find /var/lib/urpmi/ | grep cz | grep ' + name))
                 print 'HL:', source.hdlist
                 if source.hdlist != '':
                     sources.append(source)
                 word = ''
          elif c == '}':
              if flag1 == False:
                 flag1 = True
                 name_flag = True
              else:
                 name_flag = True
          elif name_flag == True and c not in ['\\', '\n']:
              word += c
        return sources

    def GetActiveSources(self, new=False):
        """Return the active Source objects."""
        if new:
            all_sources = self.GetSources()
        else:
            all_sources = self.all_sources
        return [source for source in all_sources if not source.ignore]

    def RegisterInstalledPackages(self):
        """Retrieve a dictionary containing every installed packages on the system."""
        file = os.popen('rpmquery --all "--queryformat=%{name}-%{version}-%{release}.%{arch}:%{size}:%{group}:%{installtime}\n"')
        for line in file:
            fields = line.strip().split(':')
            name = fields[0]
            size = int(fields[1])
            category = fields[2]
            btime = int(fields[3])
            self.AddPackage(name, size, category, time=btime)

    def RegisterInstallablePackages(self):
        """Get the list of every packages that are installable on the system."""
        for source in self.GetActiveSources():
            #disable gzip file = gzip.open(source.hdlist)
#            print "DEBUG " + lzma.open(source.hdlist).read()
            file = lzma(source.hdlist)
            for line in file:
                if line[:6] != '@info@':
                    continue
                fields = line.strip()[7:].split('@')
                longname = fields[0]
                size = int(fields[2])
                category = fields[3]
                self.AddPackage(longname, size, category, source)

    def RegisterUpgradablePackages(self):
        upl  = commands.getoutput('urpmq --auto-select --whatrequires').split()
        l = len (upl)
        i = 0
        self.upgradable_packages = []
        self.upgradable_packages_long = []
        while i < l:
          self.upgradable_packages.append(self.generate_shortname(upl[i]))
          self.upgradable_packages_long.append(upl[i])
          i += 1

    def generate_shortname(self, longname):
        """Generate shortname from a longname. This is a workaround if association failed."""
        print("LONGN:", longname)
        pos1 = longname.rfind("-")
        if pos1 > 0:
            pos2 = longname[:pos1].rfind("-")
            return longname[:pos2]
        else:
            return ""

    def RegisterCategory(self, category_str, package):
        """Register category 'category' in the category tree."""
        category_path = category_str.split('/')
        current_category = self.category_tree
        for subcategory_name in category_path:
            current_category = current_category.GetSubCategory(subcategory_name)
        current_category.AddPackage(package)

    def AddPackage(self, longname, size, category, source=None, time=-1):
        """Add package to the registry."""
        if self.package_name_pool.has_key(longname):
            self.package_name_pool[longname].AddSource(source)
            return
        package = Package()
        package.longname = longname
        package.shortname = self.generate_shortname(longname) ### Ezt raktam be !!!
        package.size = size
        package.category = category
        if source:
            package.AddSource(source)
            package.is_installed = False
        else:
            package.is_installed = True
        package.time = time
        if len(package.longname) >= 3:
            if package.longname.lower().find('lib') != -1:
                package.is_library = True
            else:
                package.is_library = False
        else:
            package.is_library = False
        if package.shortname in self.upgradable_packages and package.is_installed:
          package.is_upgradable = True
        else:
          package.is_upgradable = False
        self.package_name_pool[longname] = package
        self.all_packages.append(package)

    def GetPackagesContainingDescription(self, text):
        """Get the list of every packages that are installable on the system."""
        active_sources = self.GetActiveSources()  #[source for source in self.all_sources if not source.ignore]
        containing_longnames = {}
        for source in active_sources:
            file = lzma.open(source.hdlist)
            for line in file:
                if line[:9] == '@summary@':
                    fields = line.strip().split('@')
                    description = fields[2]
                elif line[:6] == '@info@':
                    fields = line.strip().split('@')
                    longname = fields[2]
                    if description.lower().find(text) != -1:
                        containing_longnames[longname] = True
        return containing_longnames

    FILTER_PACKAGENAME = 0
    FILTER_DESCRIPTION = 1
    FILTER_FILENAME = 2

    def GetPackagesContainingFiles(self, search_text):
        pass
#        active_sources = self.GetActiveSources()
#        active_source_paths = ''
#        containing_longnames = {}
#        for source in active_sources:
#            active_source_paths += escape(source.hdlist) + ' '
#        command = 'parsehdlist --fileswinfo ' + active_source_paths + ' | grep ".*:files:.*'+escape(search_text)+'.*"'
#        file = os.popen(command)
#        for line in file:
#            containing_longnames[ line.split(':')[0] ] = True
#        return containing_longnames

    def Filter(self, application, library, installed, noninstalled, search_mode, search_text):
        """Filter packages."""
        # reset pacage registry
        self.packages = []
        self.category_tree = Category('root')
        search_text = search_text.lower()
        if search_mode == self.FILTER_DESCRIPTION:
            containing_longnames = self.GetPackagesContainingDescription(search_text)
        elif search_mode == self.FILTER_FILENAME:
            containing_longnames = self.GetPackagesContainingFiles(search_text)
        for source in self.all_sources:
            source.packages = []
        for package in self.all_packages:
            inst = (package.is_installed and installed) or (not package.is_installed and noninstalled)
            ptype = (package.is_library and library) or (not package.is_library and application)
            if search_mode == self.FILTER_PACKAGENAME:
                search_inc = package.longname.lower().find(search_text)!=-1
            elif search_mode == self.FILTER_DESCRIPTION:
                search_inc = containing_longnames.has_key(package.longname)
            elif search_mode == self.FILTER_FILENAME:
                search_inc = containing_longnames.has_key(package.shortname)
            else:
                search_inc = True
            included = inst and ptype and search_inc
            if included:
                for source in package.sources:
                    source.AddPackage(package)
                self.RegisterCategory(package.category, package)
                self.packages.append(package)


text:
/*
 * File: app/view/MyLineSeries.js
 *
 * This file was generated by Sencha Architect version 3.0.2.
 * http://www.sencha.com/products/architect/
 *
 * This file requires use of the Ext JS 4.2.x library, under independent license.
 * License of Sencha Architect does not include license for Ext JS 4.2.x. For more
 * details see http://www.sencha.com/license or contact license@sencha.com.
 *
 * This file will be auto-generated each and everytime you save your project.
 *
 * Do NOT hand edit this file.
 */

Ext.define('Clientv1.view.MyLineSeries', {
    extend: 'Ext.chart.series.Line',
    alias: 'widget.mylineseries',

    xField: 'start_date_time',
    yField: 'ch01',
    fill: true,
    smooth: 3,

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            type: 'line'
        }, cfg)]);
    }
});


text:
[![Build Status](https://img.shields.io/travis/walle/wiki.svg?style=flat)](https://travis-ci.org/walle/wiki)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/walle/wiki)
[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/walle/wiki/master/LICENSE)
[![Go Report Card](https://goreportcard.com/badge/walle/wiki)](http:/goreportcard.com/report/walle/wiki)

# wiki

Command line tool to get Wikipedia summaries.

The tool can fetch summaries from any MediaWiki wiki with the API active, but
defaults to the English Wikipedia.

## Installation

To be able to install with `go get` requires you to have your `$GOPATH` setup
and your `$GOPATH/bin` added to path as described here
http://golang.org/doc/code.html#GOPATH.

If you don't want the man file you can just install it with `go get`.

```shell
$ go get github.com/walle/wiki/cmd/wiki
```

If you want to install the man file you can install with `go get`,
but then use the `make install` command from the source directory.

```shell
$ go get github.com/walle/wiki
$ cd $GOPATH/src/github.com/walle/wiki
$ make install
```

or just copy the man file in `_doc/wiki.1` to `/usr/local/share/man/man1` or
where you keep your man files.

## Usage

To get a summary from Wikipedia in English just invoke the tool with a query.

```shell
$ wiki golang
Redirected from Golang to Go (programming language)

Go, also commonly referred to as golang, is a programming language developed at Google in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. It is a statically typed language with syntax loosely derived from that of C, adding garbage collection, type safety, some structural typing capabilities, additional built-in types such as variable-length arrays & key-value maps, and a large standard library.
The language was announced in November 2009 and is now used in some of Google's production systems. Go's "gc" compiler targets the Linux, OS X, FreeBSD, NetBSD, OpenBSD, Plan 9, DragonFly BSD, Solaris, and Windows operating systems and the i386, Amd64, ARM and IBM POWER processor architectures. A second compiler, gccgo, is a GCC frontend.
Android support was added in version 1.4, which has since been ported to also run on iOS.

Read more: https://en.wikipedia.org/wiki/Go_(programming_language)
```

To get a localized result, e.g. in Swedish use the -l flag.

```shell
$ wiki -l sv ruby
```

or using System Environment:

```shell
$ WIKI_LANG="sv" wiki ruby
```

Use the -h flag to see all options (or `man wiki` if you have it installed)

```shell
$wiki -h
wiki is a tool used to fetch exerpts from wikipedia
Usage: wiki [options...] query
Options:

  -h    Print help information and exit.
  -l string
        The language to use (default "en")
  -n    If the output should not be colorized
  -no-check-certificate
        Skip verification of certificates
  -s    If simple output should be used
  -short
        If short output should be used
  -u string
        The api url (default "https://%s.wikipedia.org/w/api.php")
  -version
        Print version information and exit.
  -w int
        The width text should be wrapped at. 0 is no wrap.
```

### Use another wiki

To get excerpts from another wiki use the -u flag to give another url to the
API to use.

```shell
$ wiki -u https://en.wikiversity.org/w/api.php physics
```

This gives the excerpt from the wiki at wikiversity.org instead of Wikipedia.

#### Advice

If you frequently use the tool to fetch data from a custom url, add an alias.
E.g. for bash. Add an alias to your `.bash_profile` or `.bashrc` file.

```bash
alias uwiki='wiki -u https://en.wikiversity.org/w/api.php '
```
And call it using

```shell
$ uwiki physics
```

or using System Environment in your `.bash_profile` or `.bashrc`file.

```bash
echo "export WIKI_URL=https://en.wikiversity.org/w/api.php" >> .bashrc
# reload shell / source .bashrc
wiki physics
```

## Testing

Run the tests using the make target test `make test`, this runs both the unit and
the integration tests. For running only one type of tests use `go test -cover`
and `./integration-tests.sh` respectively.

```shell
$ make test
```

## Contributing

All contributions are welcome! See [CONTRIBUTING](CONTRIBUTING.md) for more
info.

## License

The code is under the MIT license. See [LICENSE](LICENSE) for more
information.


text:
/*
 * @title Svg
 * @description A task to combine svgs into a <symbol> element with paths
 * @example (cli) gulp svg
 */

/*********************************************************************************
 1. DEPENDENCIES
 *********************************************************************************/

import sharedPaths  from '../shared/paths.js';
import sharedEvents from '../shared/events.js';
import gulp         from 'gulp';
import plumber      from 'gulp-plumber';
import svgstore     from 'gulp-svgstore';
import rename       from 'gulp-rename';

/*********************************************************************************
 2. TASK
 *********************************************************************************/

export default () => {
    return gulp
        .src(sharedPaths.iconsSrcFiles)
        .pipe(rename((path)=> path.basename = `${path.basename}-icon`))
        .pipe(plumber({errorHandler: sharedEvents.onError}))
        .pipe(svgstore({inlineSvg: true}))
        .pipe(gulp.dest(sharedPaths.imagesOutputFiles));
};


text:
cd Release

echo Starting NFMasterServer...
start "NFMasterServer" "NFPluginLoader.exe" "Server=MasterServer" "ID=3"

choice /t 2 /d y /n >nul
echo Starting NFWorldServer...
start "NFWorldServer" "NFPluginLoader.exe" "Server=WorldServer" "ID=7"

choice /t 5 /d y /n >nul

echo Starting NFLoginServer...
start "NFLoginServer" "NFPluginLoader.exe" "Server=LoginServer" "ID=4"

choice /t 2 /d y /n >nul

echo Starting NFGameServer...
start "NFGameServer" "NFPluginLoader.exe" "Server=GameServer" "ID=6"

choice /t 4 /d y /n >nul

echo Starting NFProxyServer...
start "NFProxyServer" "NFPluginLoader.exe" "Server=ProxyServer" "ID=5"


text:
/**
 * events raised here:
 * 'my_timeline_refresh'
 */

function MyTimelineAssistant(argFromPusher) {

	/* this is the creator function for your scene assistant object. It will be passed all the
	   additional parameters (after the scene name) that were passed to pushScene. The reference
	   to the scene controller (this.controller) has not be established yet, so any initialization
	   that needs the scene controller should be done in the setup function below. */
	scene_helpers.addCommonSceneMethods(this);

	var thisA = this;

	/*
		this connects App to this property of the appAssistant
	*/
	App = Spaz.getAppObj();

	Mojo.Log.error('argFromPusher: %j', argFromPusher);
	if (argFromPusher && argFromPusher.filter) {
		sch.error('argFromPusher.filter:'+argFromPusher.filter);
	}

	if (argFromPusher && argFromPusher.firstload === true) {
		// console.debug();
		// this.clearTimelineCache();
	}

	if (argFromPusher && argFromPusher.filter) {
		this.setFilterState(argFromPusher.filter);
		this.toggleCmd = argFromPusher.filter;
		// this.filterTimeline(null, true);
	}

	if (argFromPusher && argFromPusher.mark_cache_as_read === false) {
		this.markCacheAsRead = false;
	} else {
	this.markCacheAsRead = true;
}

	/**
	 * empties the timeline and resets the lastids in the twit object
	 *
	 * bound to temp_cache_cleared
	 *
	 * we define this here to get the closure thisA
	 */
	this.resetTwitState = function() {
		Mojo.Log.error('Resetting twit state');
		App.master_timeline_model.items = [];
		thisA.timeline_model.items = [];
		thisA.controller.modelChanged(thisA.timeline_model);
		thisA.twit.setLastId(SPAZCORE_SECTION_HOME, 0);
		thisA.twit.setLastId(SPAZCORE_SECTION_REPLIES, 0);
		thisA.twit.setLastId(SPAZCORE_SECTION_DMS,     0);

	};

	/*
		we might need to NOT save the cache on deactivate, if we switch users from here
	*/
	this.doNotSaveCacheOnDeactivate = false;

	/*
		when we first create this, the cache is definitely NOT loaded
	*/
	this.cacheLoaded = false;

}

MyTimelineAssistant.prototype.aboutToActivate = function(callback){
	callback.defer(); //delays displaying scene, looks better
};

MyTimelineAssistant.prototype.setup = function() {
	Mojo.Log.error("SETUP");

	var thisA = this;

	this.scroller = this.controller.getSceneScroller();

	/* this function is for setup tasks that have to happen when the scene is first created */

	this.initAppMenu({ 'items':LOGGEDIN_APPMENU_ITEMS });

	this.initTwit('DOM');
	//Sets up meta-tap + scroll handler

	this.listenForMetaTapScroll();

	/*
		this will set the state for this.isFullScreen
	*/
	this.trackStageActiveState();

	this.setupCommonMenus({
		viewMenuItems: [
			{
				items: [
					{label: $L('Refresh'),  icon:'sync', command:'refresh', shortcut:'R'},
					{label: App.username, command:'toggle-accounts-panel', width:200},
					{label: $L('Compose'),  icon:'compose', command:'compose', shortcut:'N'}
				]
			}

		],
		cmdMenuItems: [
			{},
			{
				/*
					So we don't get the hard-to-see disabled look on the selected button,
					we make the current toggle command "IGNORE", which will not trigger an action
				*/
				toggleCmd:this.toggleCmd||'filter-timeline-all',
				items: [
					{label:$L('My Timeline'), icon:'conversation', command:'filter-timeline-all', shortcut:'T', 'class':"palm-header left"},
					{label:'@',	icon:'at', command:'filter-timeline-replies'},
					{label:$L('DM'), icon: 'dms', secondaryIconPath:'', command:'filter-timeline-dms'},
					{label:$L('Favorites'), icon:'favorite', command:'favorites', shortcut:'F'},
					{label:$L('Friends and Followers'), icon:'friends-followers', command:'friends-followers', shortcut:'L'},
					{label:$L('Search'), icon:'search', command:'search', shortcut:'S'}
				]
			},
			{}
		]
	});

	/*
	 * Accounts list
	 */
	this.Users = new SpazAccounts(App.prefs);
	this.Users.load();

	sch.debug(this.Users);

	this.controller.setupWidget("accountList",
		this.accountsAtts = {
			itemTemplate: 'account-panel/user-list-entry',
			listTemplate: 'account-panel/user-list-container',
			dividerTemplate:'account-panel/user-list-separator',
			swipeToDelete: false,
			autoconfirmDelete: false,
			reorderable: false
		},
		this.accountsModel = {
			listTitle: $L('Accounts'),
			items : this.Users.getAll()
		}
	);
	Mojo.Event.listen(jQuery('#accountList')[0], Mojo.Event.listTap, function(e) {

		/*
			remap if we have an originalEvent
		*/
		if (e.originalEvent) {
			Mojo.Log.error('originalEvent target: %s', e.originalEvent.target.outerHTML);
			event_target = e.originalEvent.target;
		} else {
			event_target = e.target;
		}

		var jqtarget = jQuery(event_target);

		if (jqtarget.is('.account-item .info')) {
			var userid, account_type, account_api_url;

			Mojo.Log.info('tap on .account-item.info, pushing user-detail');
			userid = e.item.username;
			account_type = e.item.type;

			if (account_type === SPAZCORE_ACCOUNT_CUSTOM) {
				account_api_url = Spaz.Prefs.getCustomAPIUrl(e.item.id);
			}

			Mojo.Controller.stageController.pushScene(
				'user-detail',
				{
					'userid':'@'+userid,
					'account_type':account_type,
					'account_api_url':account_api_url,
					'auth_obj':Spaz.Prefs.getAuthObject(e.item.id)
				}
			);
			return;

		} else if (App.username // ick
						&& App.type
						&& (App.username.toLowerCase() === e.item.username.toLowerCase())
						&& (App.type.toLowerCase() === e.item.type.toLowerCase())) {

			Mojo.Log.error('This is the same account we are currently using. Closing panel');
			thisA.controller.stageController.sendEventToCommanders({'type':Mojo.Event.command, 'command':'toggle-accounts-panel'});

		} else {
			/*
			save current user's cache and don't save on deactivate
			*/
			thisA.saveTimelineCache();
			thisA.doNotSaveCacheOnDeactivate = true;

			sch.debug('CLICKED ON ITEM');
			sch.debug(sch.enJSON(e.item));

			/*
			set properties for new user
			*/
			App.username = e.item.username;
			App.auth		= e.item.auth;
			App.type     = e.item.type;
			App.userid	= e.item.id;

			sch.debug('App.username:' + App.username);
			sch.debug('App.auth:'     + App.auth);
			sch.debug('App.type:'     + App.type);
			sch.debug('App.userid:'	 + App.userid);

			App.prefs.set('last_userid', App.userid);

			Spaz.popAllAndPushScene("my-timeline");
		}

	});

	this.setupInlineSpinner('activity-spinner-my-timeline');

	this.refreshOnActivate = true;

	this.controller.setupWidget("my-timeline",
		this.timeline_attributes = {
			itemTemplate: 'timeline-entry',
			listTemplate: 'timeline-container',
			emptyTemplate: 'timeline-container-empty',
			swipeToDelete: false,
			reorderable: false,
			hasNoWidgets: true,
			lookahead:   30,
			renderLimit: 10,
			formatters: {
				'data': function(value, model) {
					return thisA.renderItem(value);
				}
			}
		},
		this.timeline_model = {
			items : []
		}
	);
	this.timeline_list = this.controller.get('my-timeline');

	/*
		more button
	*/
	jQuery('#more-mytimeline-button').bind(Mojo.Event.tap, function() {
		thisA.loadMore.call(thisA);
	});
	this.moreButtonAttributes = {};
	this.moreButtonModel = {
		"buttonLabel" : "More",
		"buttonClass" : 'Primary'
	};
	this.controller.setupWidget('more-mytimeline-button', this.moreButtonAttributes, this.moreButtonModel);

	/*
		all of the data goes here. this data is filtered and copied to
		this.timeline_model as appropriate
	*/
	App.master_timeline_model = {
		'items':[]
	};

	this.showFollowSpazPopup();

	this.showDonationPopup();

	this.showNewVersionPopup();
};

MyTimelineAssistant.prototype.activate = function(params) {

	if (!params) {
		params = {};
	}

	Mojo.Log.error('ACTIVATE');

	Mojo.Log.error('params: %j', params);

	var thisA = this; // for closures

	if (!params.returnFromPop && !this.cacheLoaded) { // don't run this if returnFromPop = true was passed

		this.showInlineSpinner('activity-spinner-my-timeline', 'Loading cache…');

		/*
			load the App cache, and fire callback when it loads
		*/
		this.getAppAssistant().loadTimelineCache(function(e) {

			/*
				grab our data for this user in the cache
			*/
			thisA.loadTimelineCache();

			/*
				always mark the cached data as read, no matter what
			*/
			thisA.markAllAsRead();

			thisA.hideInlineSpinner('activity-spinner-my-timeline');

			var tts = App.prefs.get('timeline-text-size');
			thisA.setTimelineTextSize('#my-timeline', tts);

			/*
				start the mytimeline
			*/
			if (thisA.refreshOnActivate || (params && params.refresh === true)) {
				thisA.refresh(thisA.markCacheAsRead);
				thisA.refreshOnActivate = false;
				if (params && params.refresh) {
					params.refresh = false;
				}
				thisA.markCacheAsRead = true;
				thisA.cacheLoaded = true;
			}
			thisA.cacheLoaded = true;

		}.bind(this));
	}

	/*
	Prepare for timeline entry taps
	*/
	thisA.bindTimelineEntryTaps('my-timeline');

	thisA.bindScrollToRefresh();

	this.showBetaWarningAlert();

};

MyTimelineAssistant.prototype.deactivate = function(event) {

	var thisA = this;

	Mojo.Log.error('DEACTIVATE');

	/*
		stop listening for timeline entry taps
	*/
	this.unbindTimelineEntryTaps('my-timeline');

	thisA.unbindScrollToRefresh();

	if(!this.scroller){
		this.scroller = this.controller.getSceneScroller();
	}
	App[this._filterState + "-scroll-position"] = this.scroller.mojo.getState();

};

MyTimelineAssistant.prototype.cleanup = function(event) {

	Mojo.Log.error('CLEANUP');

	/* this function should do any cleanup needed before the scene is destroyed as
	   a result of being popped off the scene stack */

	// jQuery(document).unbind('load_from_mytimeline_cache_done');

	jQuery('#more-mytimeline-button').unbind(Mojo.Event.tap);

	this.stopTrackingStageActiveState();

	// this.stopRefresher();
};

MyTimelineAssistant.prototype.considerForNotification = function(params){
	Mojo.Log.error('NOTIFICATION RECEIVED in MyTimelineAssistant:%j', params);

	if (params) {
	    switch(params.event) {

            case "temp_cache_cleared":
                this.resetTwitState();
                break;

    	    case "refresh":
    	        this.refresh(this.markCacheAsRead);
    	        break;
    	}
	}

	return params;
};

MyTimelineAssistant.prototype.refresh = function(mark_as_read, page) {
	var thisA = this;

	Mojo.Log.info('refresh()');

	if (mark_as_read !== false) {
		mark_as_read = true;
	}

	if (page && !sch.isNumber(page)) {
		page = 1;
	}

	if (thisA.isTopmostScene() && mark_as_read) {
		thisA.markAllAsRead();
	}

	this.showInlineSpinner('activity-spinner-my-timeline', 'Loading…');

	this.resetScrollstate();

	function getCombinedTimeline(statusobj) {

		if ( statusobj.isInternetConnectionAvailable === true) {

			var combined_opts = {
				'friends_count':App.prefs.get('timeline-friends-getcount'),
				'replies_count':App.prefs.get('timeline-replies-getcount'),
				'dm_count':App.prefs.get('timeline-dm-getcount'),
				'home_page':page,
				'replies_page':page,
				'dm_page':page
			};
			if (page >= 2) {
				combined_opts.home_since	= 1;
				combined_opts.replies_since = 1;
				combined_opts.dm_since		= 1;
			}

			thisA.twit.getCombinedTimeline(
				combined_opts,
				function(data) {

					Mojo.Log.info('getCombinedTimeline success');

					var new_count = 0, new_mention_count = 0, new_dm_count = 0, previous_count = 0;

					previous_count = App.master_timeline_model.items.length;

					if (sch.isArray(data)) {
						data = data.reverse();
						var no_dupes = [];

						for (var i=0; i < data.length; i++) {

							/*
							only add if it doesn't already exist
							*/
							if (!thisA.itemExistsInModel(data[i])) {

								App.Tweets.save(data[i]);

								/*
									rework for RTs
								*/
								if (data[i].SC_is_retweet) {
									data[i].retweeting_user = data[i].user;
									data[i].user = data[i].retweeted_status.user;
									data[i].id = data[i].retweeted_status.id;
									data[i].in_reply_to_status_id = data[i].retweeted_status.in_reply_to_status_id;
									data[i].isSent = data[i].isSent;
									data[i].text = data[i].retweeted_status.text;
								}

								data[i].text = Spaz.makeItemsClickable(data[i].text);
								data[i].Spaz_is_new = true;

								no_dupes.push(data[i]);

								new_count++;

								if (data[i].SC_is_reply) {
									new_mention_count++;
								} else if (data[i].SC_is_dm) {
									new_dm_count++;
								}
							}

						}

						thisA.addItems(no_dupes);
					}

					thisA.hideInlineSpinner('activity-spinner-my-timeline');

					/*
					if we're not fullscreen, show a dashboard notification of new count(s)
					*/
					if (!thisA.isFullScreen) {

						if (new_count > 0 && App.prefs.get('notify-newmessages')) {
							thisA.newMsgBanner(new_count, 'newMessages', 'notifications');
						}
						if (new_mention_count > 0 && App.prefs.get('notify-mentions')) {
							thisA.newMsgBanner(new_mention_count, 'newMentions', 'notifications');
						}
						if (new_dm_count > 0 && App.prefs.get('notify-dms')) {
							thisA.newMsgBanner(new_dm_count, 'newDirectMessages', 'notifications');
						}

					} else {
						Mojo.Log.info("I am not showing a banner! in "+thisA.controller.sceneElement.id);
					}

				},
				function(errors) {
					var num_errors = 1;
					var err_msg = '';

					if (sch.isArray(errors)) {
						num_errors = errors.length;
					}

					if (num_errors > 1) {
						err_msg = $L("There were #{num_errors} errors:").interpolate({'num_errors':num_errors});
					} else {
						err_msg = $L("There was #{num_errors} error:").interpolate({'num_errors':num_errors});
					}
					thisA.displayErrorInfo(err_msg, errors);

					thisA.hideInlineSpinner('activity-spinner-my-timeline');
				}
			);

		} else {
			thisA.showBanner('Not connected to Internet');
		}

	}

	/*
		only get data if we're connected
	*/
	this.checkInternetStatus( getCombinedTimeline );

};

/*
	redefine addItems to work with list model
*/
MyTimelineAssistant.prototype.addItems = function(new_items) {

	Mojo.Log.error("addItems");

	var lastTweetID = false;
	if (!App.prefs.get('timeline-scrollonupdate')) {
		// remember first visible item
		for (var i=0; i<this.timeline_model.items.length; i++) {
			Mojo.Log.error("index", i);
			var itemNode = this.timeline_list.mojo.getNodeByIndex(i);
			if (itemNode !== undefined) {
				Mojo.Log.error("node %j", itemNode);
				var offset = Element.viewportOffset (itemNode);
				Mojo.Log.error("offset", offset.top);
				if (offset.top > 0) {
					lastTweetID = this.timeline_model.items[i].data.id;
					Mojo.Log.error("index", i, "offset", offset.top, "id", lastTweetID, this.timeline_model.items[i].data.text);
					break;
				}
			}
		}
	}

	// now we have all the existing items from the model
	var model_items = App.master_timeline_model.items.clone();

	var model_item;
	for (var i=0; i < new_items.length; i++) {
		model_item = {
			'id':new_items[i].id,
			'data':sch.clone(new_items[i])
		};
		// add each item to the model
		model_items.push(model_item);
	}

	// sort, in reverse
	model_items.sort(function(a,b){
		return b.data.SC_created_at_unixtime - a.data.SC_created_at_unixtime; // newest first
	});

	// re-assign the cloned items back to the model object
	App.master_timeline_model.items = model_items;

	var thisA = this;
	setTimeout(function() {
		thisA.saveTimelineCache();
	}, 1000);

	this.resetScrollstate();

	// this filters and updates the model
	this.filterTimeline(null, false, true);

	if (!App.prefs.get('timeline-scrollonupdate') && lastTweetID) {
		var lastidx = -1;
		for (var i=0; i < this.timeline_model.items.length; i++) {
			if (this.timeline_model.items[i].data.id == lastTweetID) {
				lastidx = i;
				break;
			}
		}

		if (lastidx >= 0 && (lastidx < this.timeline_model.items.length-1) ) {
			Mojo.Log.error('Revealing item:', lastidx, this.timeline_model.items[i].data.text);
			this.timeline_list.mojo.revealItem(lastidx, false);
			var itemNode = this.timeline_list.mojo.getNodeByIndex(i);
			if (itemNode !== undefined) {
				Mojo.Log.error("node %j", itemNode);
				Element.scrollTo(itemNode);
			}
		}
	}
};

MyTimelineAssistant.prototype.renderItem = function(obj) {

    var html = '';

    Mojo.Timing.resume("timing_this.mytl.renderer");
	try {
		if (obj.SC_is_dm) {
			html = App.tpl.parseTemplate('dm', obj);
		} else {
			html = App.tpl.parseTemplate('tweet', obj);
		}
		Mojo.Timing.pause("timing_this.mytl.renderer");
		return html;

	} catch(err) {
		sch.error("There was an error rendering the object: "+sch.enJSON(obj));
		sch.error("Error:"+sch.enJSON(err));
		Mojo.Timing.pause("timing_this.mytl.renderer");

		return '';
	}

};

MyTimelineAssistant.prototype.loadMore = function(event) {
	if (this.mytimeline_more_page) {
		this.mytimeline_more_page++;
	} else {
		this.mytimeline_more_page = 2;
	}

	this.refresh(true, this.mytimeline_more_page);
};

MyTimelineAssistant.prototype.itemExistsInModel = function(obj) {

	for (var i=0; i < App.master_timeline_model.items.length; i++) {
		if (App.master_timeline_model.items[i].id == obj.id) {
			Mojo.Log.info(obj.id +' exists in model');
			return true;
		}
	}
	Mojo.Log.info(obj.id +' does not exist in model');
	return false;
};

/**
 * loop through items in master_timeline_model and set Spaz_is_new = false, Spaz_is_read = true
 */
MyTimelineAssistant.prototype.markAllAsRead = function() {

	// die early
	// return;

	Mojo.Log.error("markAllAsRead");

	Mojo.Timing.resume("timing_html_markAllAsRead");

	for (var i=0; i < App.master_timeline_model.items.length; i++) {
		App.master_timeline_model.items[i].data.Spaz_is_new = false;
		App.master_timeline_model.items[i].data.Spaz_is_read = true;
	}

	Mojo.Timing.pause("timing_html_markAllAsRead");

	Mojo.Log.error(Mojo.Timing.createTimingString("timing_html", "Updating HTML element times"));

	this.filterTimeline(null, false, false);
	// this.controller.modelChanged(this.timeline_model);
};

MyTimelineAssistant.prototype.loadTimelineCache = function() {

	sch.error('LOADTIMELINECACHE MyTimelineAssistant');

	Mojo.Timing.resume("timing_loadTimelineCache");

	var data = App.cache.load('mytimelinecache');

	if (data !== null) {
		this.twit.setLastId(SPAZCORE_SECTION_HOME, data[SPAZCORE_SECTION_HOME + '_lastid']);
		this.twit.setLastId(SPAZCORE_SECTION_REPLIES, data[SPAZCORE_SECTION_REPLIES + '_lastid']);
		this.twit.setLastId(SPAZCORE_SECTION_DMS,     data[SPAZCORE_SECTION_DMS     + '_lastid']);

		if (data['my_master_timeline_model_items']) {
			App.master_timeline_model.items = data['my_master_timeline_model_items'];
		} else {
			App.master_timeline_model.items = [];
		}

		this.filterTimeline(null, true, false, true);

	}

	Mojo.Timing.pause("timing_loadTimelineCache");

	Mojo.Log.error(Mojo.Timing.createTimingString("timing_", "Cache op times"));
};

MyTimelineAssistant.prototype.saveTimelineCache = function() {

	this.getAppAssistant().saveTimelineCache(this.twit);

};

/**
 * this filters and updates the model
 */
MyTimelineAssistant.prototype.filterTimeline = function(command, scroll_to_top, scroll_to_new, loadingCache) {

	if (!command) {
		if (this._filterState) {
			command = this._filterState;
		} else {
			command = 'filter-timeline-all';
		}
	}
	if(!loadingCache && !scroll_to_new){
		if(!this.scroller){
			this.scroller = this.controller.getSceneScroller();
		}
		App[this._filterState + "-scroll-position"] = this.scroller.mojo.getState();
	}
	Mojo.Log.error('COMMAND:'+command);

	var states = [
					'filter-timeline-all',
					'filter-timeline-replies-dm',
					'filter-timeline-replies',
					'filter-timeline-dms'
	];

	var valid = false;
	for (i=0; i < states.length; i++) {
		if (command === states[i]) {
			valid = true;
		}
	};

	if (!valid) {
		sch.error('Not a valid command');
		this.controller.modelChanged(this.timeline_model);
		return;
	}

	// reset the timeline_model
	this.timeline_model.items = [];

	Mojo.Log.info('App.master_timeline_model.items length: %s', App.master_timeline_model.items.length);
	Mojo.Log.info('this.timeline_model.items length: %s', this.timeline_model.items.length);

	switch(command) {
		case 'filter-timeline-all':
			this.timeline_model.items = App.master_timeline_model.items;
			break;

		case 'filter-timeline-replies':
			for (i=0; i < App.master_timeline_model.items.length; i++) {
				if (App.master_timeline_model.items[i].data.SC_is_reply) {
					this.timeline_model.items.push(App.master_timeline_model.items[i]);
				}
			}
			break;

		case 'filter-timeline-dms':
			for (i=0; i < App.master_timeline_model.items.length; i++) {
				if (App.master_timeline_model.items[i].data.SC_is_dm) {
					this.timeline_model.items.push(App.master_timeline_model.items[i]);
				}
			}
			break;

		case 'filter-timeline-replies-dm':
			for (i=0; i < App.master_timeline_model.items.length; i++) {
				if (App.master_timeline_model.items[i].data.SC_is_dm || App.master_timeline_model.items[i].data.SC_is_reply) {
					this.timeline_model.items.push(App.master_timeline_model.items[i]);
				}
			}
			break;

		default:
			this.timeline_model.items = App.master_timeline_model.items;
			break;
	}

	Mojo.Log.info('this.timeline_model.items length: %s', this.timeline_model.items.length);

	if (this.controller) { // sanity check in case we change context
		this.controller.modelChanged(this.timeline_model);
	}

	this.setFilterState(command);

	/*
		scroll me!
	*/

	if (App.prefs.get('timeline-scrollonupdate')) {
		if (scroll_to_top || scroll_to_new) {
			this.resetScrollstate();

			if (scroll_to_top) {
				if(App[command + "-scroll-position"]){
					this.scroller.mojo.setState(App[command + "-scroll-position"], false);
				}else {
					this.scrollToTop();
				}
			}
			if (App.prefs.get('timeline-scrollonupdate') && scroll_to_new) {
				if (this.isTopmostScene()) {
					this.scrollToNew();
				}
			}
		} else {
			this.resetScrollstate();
		}
	}

};

MyTimelineAssistant.prototype.resetScrollstate = function() {
	/*
		reset scrollstate to avoid white flash
	*/
	var scrollstate = this.scroller.mojo.getState();
	this.scroller.mojo.setState(scrollstate, false);
};

/**
 * set the filterstate directly to be applied next time around
 */
MyTimelineAssistant.prototype.setFilterState = function(state) {
    Mojo.Log.info('NEW FILTER STATE:'+state);
    this._filterState = state;
};


text:
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.chromium.chrome.browser.contacts_picker;

import android.content.ContentResolver;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import org.chromium.base.task.AsyncTask;

/**
 * Holds on to a {@link ContactView} that displays information about a contact.
 */
public class ContactViewHolder
        extends ViewHolder implements FetchIconWorkerTask.IconRetrievedCallback {
    // Our parent category.
    private final PickerCategoryView mCategoryView;

    // The Content Resolver to use for the lookup.
    private final ContentResolver mContentResolver;

    // The contact view we are holding on to.
    private final ContactView mItemView;

    // The details for the contact.
    private ContactDetails mContact;

    // A worker task for asynchronously retrieving icons off the main thread.
    private FetchIconWorkerTask mWorkerTask;

    // The icon to use when testing.
    private static Bitmap sIconForTest;

    /**
     * The PickerBitmapViewHolder.
     * @param itemView The {@link ContactView} for the contact.
     * @param categoryView The {@link PickerCategoryView} showing the contacts.
     * @param contentResolver The {@link ContentResolver} to use for the lookup.
     */
    public ContactViewHolder(ContactView itemView, PickerCategoryView categoryView,
            ContentResolver contentResolver) {
        super(itemView);
        mCategoryView = categoryView;
        mContentResolver = contentResolver;
        mItemView = itemView;
    }

    /**
     * Sets the contact details to show in the itemview. If the image is not found in the cache,
     * an asynchronous worker task is created to load it.
     * @param contact The contact details to show.
     */
    public void setContactDetails(ContactDetails contact) {
        mContact = contact;

        if (sIconForTest != null) {
            mItemView.initialize(contact, sIconForTest);
            return;
        }

        Drawable drawable = contact.getSelfIcon();
        if (drawable != null) {
            assert drawable instanceof BitmapDrawable;
            Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
            mItemView.initialize(contact, bitmap);
        } else {
            Bitmap icon = mCategoryView.getIconCache().getBitmap(mContact.getId());
            if (icon == null) {
                mWorkerTask = new FetchIconWorkerTask(mContact.getId(), mContentResolver, this);
                mWorkerTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
            mItemView.initialize(contact, icon);
        }
    }

    /**
     * Cancels the worker task to retrieve the icon.
     */
    public void cancelIconRetrieval() {
        mWorkerTask.cancel(true);
        mWorkerTask = null;
    }

    // FetchIconWorkerTask.IconRetrievedCallback:

    @Override
    public void iconRetrieved(Bitmap icon, String contactId) {
        if (mCategoryView.getIconCache().getBitmap(contactId) == null) {
            mCategoryView.getIconCache().putBitmap(contactId, icon);
        }

        if (icon != null && contactId.equals(mContact.getId())) {
            mItemView.setIconBitmap(icon);
        }
    }

    /** Sets the icon to use when testing. */
    @VisibleForTesting
    public static void setIconForTesting(Bitmap icon) {
        sIconForTest = icon;
    }
}


text:
An Embedded Language for Accelerated Array Computations
=======================================================

`Data.Array.Accelerate` defines an embedded language of array computations for high-performance computing in Haskell. Computations on multi-dimensional, regular arrays are expressed in the form of parameterised collective operations (such as maps, reductions, and permutations). These computations are online-compiled and executed on a range of architectures.

For more details, see our recent paper [Accelerating Haskell Array Codes with Multicore GPUs][CKLM+11]. There are also some slightly outdated slides and a video of a talk that I gave at the [Haskell Implementors Workshop 2009][HIW'09] (in Edinburgh): [Haskell Arrays, Accelerated (Using GPUs).][Cha09]

A simple example
----------------

As a simple example, consider the computation of a dot product of two vectors of single-precision floating-point numbers:

    dotp :: Acc (Vector Float) -> Acc (Vector Float) -> Acc (Scalar Float)
    dotp xs ys = fold (+) 0 (zipWith (*) xs ys)

Except for the type, this code is almost the same as the corresponding Haskell code on lists of floats. The types indicate that the computation may be online-compiled for performance — for example, using `Data.Array.Accelerate.CUDA.run` it may be on-the-fly off-loaded to a GPU.

Availability
------------

Package accelerate is available from

 * Hackage: [accelerate][Hackage] — install with `cabal install accelerate`
 * GitHub: [mchakravarty/accelerate][GitHub] - get the source with `git clone https://github.com/mchakravarty/accelerate.git`

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

  * Glasgow Haskell Compiler (GHC), 6.12.1 or later
  * Haskell libraries as specified in `accelerate.cabal`
  * For the CUDA backend, CUDA version 3.0 or later

Contacts
--------

The maintainer of this package is Manuel M T Chakravarty <chak@cse.unsw.edu.au> (aka TacticalGrace on #haskell and related channels).

Both user and developer questions and discussions are welcome at `accelerate@projects.haskell.org`.  **Sorry, this mailing list is temporarily unavailable.**

What's missing?
---------------

Here is a list of features that are currently missing:

 * Reification of sharing in scalar expressions (sharing is being recovered for array computations)
 * The CUDA backend does not support arrays of type Char and Bool at the moment.
 * The CUDA backend does not implement stencil computations yet.
 * Preliminary API (the current functionality is limited)

Documentation
-------------

Haddock documentation is included in the package and linked from the Hackage page. Furthermore, the source package contains a few simple examples in the `accelerate-examples/` directory.

The idea behind the HOAS (higher-order abstract syntax) to de-Bruijn conversion used in the library is [described separately.][HOAS-conv]

  [CKLM+11]:   http://www.cse.unsw.edu.au/~chak/papers/CKLM+11.html
  [HIW'09]:    http://haskell.org/haskellwiki/HaskellImplementorsWorkshop
  [Cha09]:     http://justtesting.posterous.com/running-haskell-array-computations-on-a-gpu
  [Hackage]:   http://hackage.haskell.org/package/accelerate
  [GitHub]:    https://github.com/mchakravarty/accelerate
  [HOAS-conv]: http://www.cse.unsw.edu.au/~chak/haskell/term-conv/


text:
import bisect
import collections
import copy
import time

import six

from spectrometer.openstack.common import log as logging
from spectrometer.processor import utils

LOG = logging.getLogger(__name__)

class RecordProcessor(object):
    def __init__(self, runtime_storage_inst):
        self.runtime_storage_inst = runtime_storage_inst

        self.domains_index = runtime_storage_inst.get_by_key('companies')

        self.releases = runtime_storage_inst.get_by_key('releases')
        self.releases_dates = [r['end_date'] for r in self.releases]

        self.modules = None
        self.alias_module_map = None

    def _get_release(self, timestamp):
        release_index = bisect.bisect(self.releases_dates, timestamp)
        if release_index >= len(self.releases):
            LOG.warn('Timestamp %s is beyond releases boundaries, the last '
                     'release will be used. Please consider adding a '
                     'new release into default_data.json', timestamp)
            release_index = len(self.releases) - 1
        return self.releases[release_index]['release_name']

    def _get_modules(self):
        if self.modules is None:
            self.modules = set()
            self.alias_module_map = dict()

            for repo in utils.load_repos(self.runtime_storage_inst):
                module = repo['module'].lower()
                module_aliases = repo.get('aliases') or []

                add = True
                for module_name in ([module] + module_aliases):
                    for m in self.modules:
                        if module_name.find(m) >= 0:
                            add = False
                            break
                        if m.find(module_name) >= 0:
                            self.modules.remove(m)
                            break
                    if add:
                        self.modules.add(module_name)

                for alias in module_aliases:
                    self.alias_module_map[alias] = module

        return self.modules, self.alias_module_map

    def _find_company(self, companies, date):
        for r in companies:
            if date < r['end_date']:
                return r['company_name']
        return companies[-1]['company_name']

    def _get_company_by_email(self, email):
        if not email:
            return None

        name, at, domain = email.partition('@')
        if domain:
            parts = domain.split('.')
            for i in range(len(parts), 1, -1):
                m = '.'.join(parts[len(parts) - i:])
                if m in self.domains_index:
                    return self.domains_index[m]
        return None

    def _create_user(self, ldap_id, email, user_name):
        company = (self._get_company_by_email(email) or
                   self._get_independent())
        user = {
            'user_id': ldap_id or email,
            'ldap_id': ldap_id,
            'user_name': user_name or '',
            'companies': [{
                'company_name': company,
                'end_date': 0,
            }],
        }
        if email:
            user['emails'] = [email]
        else:
            user['emails'] = []
        return user

    def _get_independent(self):
        return '*independent'

    def _update_user_affiliation(self, user):
        for email in user.get('emails'):
            company_name = self._get_company_by_email(email)
            uc = user['companies']
            if (company_name and (len(uc) == 1) and
                    (uc[0]['company_name'] == self._get_independent())):
                LOG.debug('Updating affiliation of user %s to %s',
                          user['user_id'], company_name)
                uc[0]['company_name'] = company_name
                break

    def _get_user_exact_company(self, user):
        if len(user.get('companies', [])) == 1:
            return user['companies'][0]['company_name']
        return None

    def _merge_user_profiles(self, user_a, user_b, user_c):
        user = {}
        for key in ['seq', 'user_name', 'user_id',
                    'ldap_id', 'companies']:
            user[key] = user_a.get(key) or user_b.get(key) or user_c.get(key)

        if user['ldap_id'] and user['user_id'] != user['ldap_id']:
            user['user_id'] = user['ldap_id']

        emails = set([])
        core_in = set([])
        for u in [user_a, user_b, user_c]:
            emails |= set(u.get('emails', []))
            core_in |= set(u.get('core', []))
        user['emails'] = list(emails)
        user['core'] = list(core_in)

        self._update_user_affiliation(user)

        if user_a.get('seq') and user_b.get('seq'):
            LOG.debug('Delete user: %s', user_b)
            utils.delete_user(self.runtime_storage_inst, user_b)
        return user

    def update_user(self, record):
        email = record.get('author_email')
        user_e = utils.load_user(self.runtime_storage_inst, email) or {}

        user_name = record.get('author_name')

        ldap_id = record.get('ldap_id')
        user_l = utils.load_user(self.runtime_storage_inst, ldap_id) or {}

        user = self._create_user(ldap_id, email, user_name)

        if (user_e.get('seq') == user_l.get('seq')) and user_e.get('seq'):
            # sequence numbers are set and the same, merge is not needed
            user = user_e
        else:
            if user_e or user_l:
                user = self._merge_user_profiles(user_e, user_l, user)
            else:
                # Create New
                LOG.debug('Created new user: %s', user)

            utils.store_user(self.runtime_storage_inst, user)

        return user

    def _update_record_and_user(self, record):
        user = self.update_user(record)

        record['user_id'] = user['user_id']
        record['ldap_id'] = user['ldap_id']

        if user.get('user_name'):
            record['author_name'] = user['user_name']

        company = self._find_company(user['companies'], record['date'])
        if company != '*robots':
            company = (self._get_company_by_email(record.get('author_email'))
                       or company)
        record['company_name'] = company

    def _process_commit(self, record):
        record['primary_key'] = record['commit_id']
        record['loc'] = record['lines_added'] + record['lines_deleted']
        record['author_email'] = record['author_email'].lower()
        record['commit_date'] = record['date']

        coauthors = record.get('coauthor')
        if not coauthors:
            self._update_record_and_user(record)

            if record['company_name'] != '*robots':
                yield record
        else:
            coauthors.append({'author_name': record['author_name'],
                              'author_email': record['author_email']})
            for coauthor in coauthors:
                coauthor['date'] = record['date']
                self._update_record_and_user(coauthor)

            for coauthor in coauthors:
                new_record = copy.deepcopy(record)
                new_record.update(coauthor)
                new_record['primary_key'] += coauthor['author_email']

                yield new_record

    def _make_review_record(self, record):
        # copy everything except patchsets and flatten user data
        review = dict([(k, v) for k, v in six.iteritems(record)
                       if k not in ['patchSets', 'owner', 'createdOn']])
        owner = record['owner']

        review['primary_key'] = review['id']
        review['ldap_id'] = owner['username']
        review['author_name'] = owner['name']
        review['author_email'] = owner['email'].lower()
        review['date'] = record['createdOn']

        patch_sets = record.get('patchSets', [])
        review['updated_on'] = review['date']
        if patch_sets:
            patch = patch_sets[-1]
            if 'approvals' in patch:
                review['value'] = min([int(p['value'])
                                       for p in patch['approvals']])
                review['updated_on'] = patch['approvals'][0]['grantedOn']
            else:
                review['updated_on'] = patch['createdOn']

        if 'value' not in review:
            review['value'] = 0

        self._update_record_and_user(review)
        return review

    def _make_patch_record(self, review, patch):
        patch_record = dict()
        patch_record['record_type'] = 'patch'
        patch_record['primary_key'] = utils.get_patch_id(
            review['id'], patch['number'])
        patch_record['number'] = patch['number']
        patch_record['date'] = patch['createdOn']
        uploader = patch['uploader']
        patch_record['ldap_id'] = uploader['username']
        patch_record['author_name'] = uploader['name']
        patch_record['author_email'] = uploader['email'].lower()
        patch_record['module'] = review['module']
        patch_record['branch'] = review['branch']
        patch_record['review_id'] = review['id']

        self._update_record_and_user(patch_record)
        return patch_record

    def _make_mark_record(self, review, patch, approval):
        # copy everything and flatten user data
        mark = dict([(k, v) for k, v in six.iteritems(approval)
                     if k not in ['by', 'grantedOn', 'value', 'description']])
        reviewer = approval['by']

        mark['record_type'] = 'mark'
        mark['value'] = int(approval['value'])
        mark['date'] = approval['grantedOn']
        mark['primary_key'] = (review['id'] + str(mark['date']) + mark['type'])
        mark['ldap_id'] = reviewer['username']
        mark['author_name'] = reviewer['name']
        mark['author_email'] = reviewer['email'].lower()
        mark['module'] = review['module']
        mark['branch'] = review['branch']
        mark['review_id'] = review['id']
        mark['patch'] = int(patch['number'])

        self._update_record_and_user(mark)
        return mark

    def _process_review(self, record):
        """
         Process a review. Review spawns into records of three types:
          * review - records that a user created review request
          * patch - records that a user submitted another patch set
          * mark - records that a user set approval mark to given review
        """
        owner = record['owner']
        if 'email' not in owner or 'username' not in owner:
            return  # ignore

        yield self._make_review_record(record)

        for patch in record.get('patchSets', []):
            if (('email' not in patch['uploader']) or
                    ('username' not in patch['uploader'])):
                continue  # ignore

            yield self._make_patch_record(record, patch)

            if 'approvals' not in patch:
                continue  # not reviewed by anyone

            for approval in patch['approvals']:
                if approval['type'] not in ('Code-Review', 'Workflow'):
                    continue  # keep only Code-Review and Workflow
                if ('email' not in approval['by'] or
                        'username' not in approval['by']):
                    continue  # ignore

                yield self._make_mark_record(record, patch, approval)

    def _guess_module(self, record):
        subject = record['subject'].lower()
        pos = len(subject)
        best_guess_module = None

        modules, alias_module_map = self._get_modules()
        for module in modules:
            find = subject.find(module)
            if (find >= 0) and (find < pos):
                pos = find
                best_guess_module = module

        if best_guess_module:
            if (((pos > 0) and (subject[pos - 1] == '[')) or
                    (not record.get('module'))):
                record['module'] = best_guess_module

        if not record.get('module'):
            record['module'] = 'unknown'
        elif record['module'] in alias_module_map:
            record['module'] = alias_module_map[record['module']]

    def _process_email(self, record):
        record['primary_key'] = record['message_id']
        record['author_email'] = record['author_email'].lower()

        self._update_record_and_user(record)
        self._guess_module(record)

        if not record.get('blueprint_id'):
            del record['body']

        yield record

    def _process_blueprint(self, record):
        bpd_author = record.get('drafter') or record.get('owner')

        bpd = dict([(k, v) for k, v in six.iteritems(record)
                    if k.find('_link') < 0])
        bpd['record_type'] = 'bpd'
        bpd['primary_key'] = 'bpd:' + record['id']
        bpd['launchpad_id'] = bpd_author
        bpd['date'] = record['date_created']

        self._update_record_and_user(bpd)

        yield bpd

        if record.get('assignee') and record['date_completed']:
            bpc = dict([(k, v) for k, v in six.iteritems(record)
                        if k.find('_link') < 0])
            bpc['record_type'] = 'bpc'
            bpc['primary_key'] = 'bpc:' + record['id']
            bpc['launchpad_id'] = record['assignee']
            bpc['date'] = record['date_completed']

            self._update_record_and_user(bpc)

            yield bpc

    def _process_member(self, record):
        user_id = "member:" + record['member_id']
        record['primary_key'] = user_id
        record['date'] = utils.member_date_to_timestamp(record['date_joined'])
        record['author_name'] = record['member_name']
        record['country'] = record.get("country")
        record['email'] = record.get("email")
        record['module'] = 'unknown'
        company_draft = record['company_draft']

        company_name = self.domains_index.get(utils.normalize_company_name(
            company_draft)) or company_draft

        # author_email is a key to create new user
        record['author_email'] = record["email"] or user_id
        record['company_name'] = company_name
        # _update_record_and_user function will create new user if needed
        self._update_record_and_user(record)
        record['company_name'] = company_name
        user = utils.load_user(self.runtime_storage_inst,
                               record['user_id'] or user_id)
        user['user_name'] = record['author_name']
        user['companies'] = [{
            'company_name': company_name,
            'end_date': 0,
        }]
        user['company_name'] = company_name

        utils.store_user(self.runtime_storage_inst, user)

        record['company_name'] = company_name

        yield record

    def _apply_type_based_processing(self, record):
        if record['record_type'] == 'commit':
            for r in self._process_commit(record):
                yield r
        elif record['record_type'] == 'review':
            for r in self._process_review(record):
                yield r
        elif record['record_type'] == 'email':
            for r in self._process_email(record):
                yield r
        elif record['record_type'] == 'bp':
            for r in self._process_blueprint(record):
                yield r
        elif record['record_type'] == 'member':
            for r in self._process_member(record):
                yield r

    def _renew_record_date(self, record):
        record['week'] = utils.timestamp_to_week(record['date'])
        if ('release' not in record) or (not record['release']):
            record['release'] = self._get_release(record['date'])

    def process(self, record_iterator):
        for record in record_iterator:
            for r in self._apply_type_based_processing(record):

                if r['company_name'] == '*robots':
                    continue

                self._renew_record_date(r)

                yield r

    def _update_records_with_releases(self, release_index):
        LOG.debug('Update records with releases')

        for record in self.runtime_storage_inst.get_all_records():
            if record['primary_key'] in release_index:
                release = release_index[record['primary_key']]
            else:
                release = self._get_release(record['date'])

            if record['release'] != release:
                record['release'] = release
                yield record

    def _update_records_with_user_info(self):
        LOG.debug('Update user info in records')

        for record in self.runtime_storage_inst.get_all_records():
            company_name = record['company_name']
            user_id = record['user_id']
            author_name = record['author_name']

            self._update_record_and_user(record)

            if ((record['company_name'] != company_name) or
                    (record['user_id'] != user_id) or
                    (record['author_name'] != author_name)):
                LOG.debug('User info (%(id)s, %(name)s, %(company)s) has '
                          'changed in record %(record)s',
                          {'id': user_id, 'name': author_name,
                           'company': company_name, 'record': record})
                yield record

    def _update_commits_with_merge_date(self):
        change_id_to_date = {}
        for record in self.runtime_storage_inst.get_all_records():
            if (record['record_type'] == 'review' and
                    record.get('status') == 'MERGED'):
                change_id_to_date[record['id']] = record['lastUpdated']

        for record in self.runtime_storage_inst.get_all_records():
            if record['record_type'] == 'commit':
                change_id_list = record.get('change_id')
                if change_id_list and len(change_id_list) == 1:
                    change_id = change_id_list[0]
                    if change_id in change_id_to_date:
                        old_date = record['date']
                        if old_date != change_id_to_date[change_id]:
                            record['date'] = change_id_to_date[change_id]
                            self._renew_record_date(record)
                            LOG.debug('Date %(date)s has changed in record '
                                      '%(record)s', {'date': old_date,
                                                     'record': record})
                            yield record

    def _update_blueprints_with_mention_info(self):
        LOG.debug('Process blueprints and calculate mention info')

        valid_blueprints = {}
        mentioned_blueprints = {}
        for record in self.runtime_storage_inst.get_all_records():
            for bp in record.get('blueprint_id', []):
                if bp in mentioned_blueprints:
                    mentioned_blueprints[bp]['count'] += 1
                    if record['date'] > mentioned_blueprints[bp]['date']:
                        mentioned_blueprints[bp]['date'] = record['date']
                else:
                    mentioned_blueprints[bp] = {
                        'count': 1,
                        'date': record['date']
                    }
            if record['record_type'] in ['bpd', 'bpc']:
                valid_blueprints[record['id']] = {
                    'primary_key': record['primary_key'],
                    'count': 0,
                    'date': record['date']
                }

        for bp_name, bp in six.iteritems(valid_blueprints):
            if bp_name in mentioned_blueprints:
                bp['count'] = mentioned_blueprints[bp_name]['count']
                bp['date'] = mentioned_blueprints[bp_name]['date']
            else:
                bp['count'] = 0
                bp['date'] = 0

        for record in self.runtime_storage_inst.get_all_records():
            need_update = False

            valid_bp = set([])
            for bp in record.get('blueprint_id', []):
                if bp in valid_blueprints:
                    valid_bp.add(bp)
                else:
                    LOG.debug('Update record %s: removed invalid bp: %s',
                              record['primary_key'], bp)
                    need_update = True
            record['blueprint_id'] = list(valid_bp)

            if record['record_type'] in ['bpd', 'bpc']:
                bp = valid_blueprints[record['id']]
                if ((record.get('mention_count') != bp['count']) or
                        (record.get('mention_date') != bp['date'])):
                    record['mention_count'] = bp['count']
                    record['mention_date'] = bp['date']
                    LOG.debug('Update record %s: mention stats: (%s:%s)',
                              record['primary_key'], bp['count'], bp['date'])
                    need_update = True

            if need_update:
                yield record

    def _update_reviews_with_sequence_number(self):
        LOG.debug('Set review number in review records')

        users_reviews = {}
        for record in self.runtime_storage_inst.get_all_records():
            if record['record_type'] == 'review':
                ldap_id = record['ldap_id']
                review = {'date': record['date'], 'id': record['id']}
                if ldap_id in users_reviews:
                    users_reviews[ldap_id].append(review)
                else:
                    users_reviews[ldap_id] = [review]

        reviews_index = {}
        for ldap_id, reviews in six.iteritems(users_reviews):
            reviews.sort(key=lambda x: x['date'])
            review_number = 0
            for review in reviews:
                review_number += 1
                review['review_number'] = review_number
                reviews_index[review['id']] = review

        for record in self.runtime_storage_inst.get_all_records():
            if record['record_type'] == 'review':
                review = reviews_index[record['id']]
                if record.get('review_number') != review['review_number']:
                    record['review_number'] = review['review_number']
                    yield record

    def _determine_core_contributors(self):
        LOG.debug('Determine core contributors')

        core_engineers = {}
        quarter_ago = int(time.time()) - 60 * 60 * 24 * 30 * 3  # a quarter ago

        for record in self.runtime_storage_inst.get_all_records():
            if (record['record_type'] == 'mark' and
                    record['date'] > quarter_ago and
                    record['value'] in [2, -2]):
                module_branch = (record['module'], record['branch'])
                user_id = record['user_id']
                if user_id in core_engineers:
                    core_engineers[user_id].add(module_branch)
                else:
                    core_engineers[user_id] = set([module_branch])
        for user in self.runtime_storage_inst.get_all_users():
            core_old = user.get('core')
            user['core'] = list(core_engineers.get(user['user_id'], []))
            if user['core'] != core_old:
                utils.store_user(self.runtime_storage_inst, user)

    def _close_patch(self, cores, marks):
        if len(marks) < 2:
            return

        core_mark = 0
        for mark in sorted(marks, key=lambda x: x['date'], reverse=True):

            if core_mark == 0:
                if (mark['module'], mark['branch'], mark['user_id']) in cores:
                    # mark is from core engineer
                    core_mark = mark['value']
                    continue

            disagreement = ((core_mark != 0) and
                            ((core_mark < 0 < mark['value']) or
                             (core_mark > 0 > mark['value'])))
            old_disagreement = mark.get('disagreement', False)
            mark['disagreement'] = disagreement
            if old_disagreement != disagreement:
                yield mark

    def _update_marks_with_disagreement(self):
        LOG.debug('Process marks to find disagreements')

        cores = set()
        for user in self.runtime_storage_inst.get_all_users():
            for (module, branch) in (user['core'] or []):
                cores.add((module, branch, user['user_id']))

        # map from review_id to current patch and list of marks
        marks_per_patch = collections.defaultdict(
            lambda: {'patch_number': 0, 'marks': []})

        for record in self.runtime_storage_inst.get_all_records():
            if (record['record_type'] == 'mark' and
                    record['type'] == 'Code-Review'):
                review_id = record['review_id']
                patch_number = record['patch']

                if review_id in marks_per_patch:
                    # review is already seen, check if patch is newer
                    if (marks_per_patch[review_id]['patch_number'] <
                            patch_number):
                        # the patch is new, close the current
                        for processed in self._close_patch(
                                cores, marks_per_patch[review_id]['marks']):
                            yield processed
                        del marks_per_patch[review_id]

                marks_per_patch[review_id]['patch_number'] = patch_number
                marks_per_patch[review_id]['marks'].append(record)

        # purge the rest
        for marks_patch in marks_per_patch.values():
            for processed in self._close_patch(cores, marks_patch['marks']):
                yield processed

    def update(self, release_index=None):
        self.runtime_storage_inst.set_records(
            self._update_records_with_user_info())

        if release_index:
            self.runtime_storage_inst.set_records(
                self._update_records_with_releases(release_index))

        self.runtime_storage_inst.set_records(
            self._update_reviews_with_sequence_number())

        self.runtime_storage_inst.set_records(
            self._update_blueprints_with_mention_info())

        self.runtime_storage_inst.set_records(
            self._update_commits_with_merge_date())

        self._determine_core_contributors()

        # disagreement calculation must go after determining core contributors
        self.runtime_storage_inst.set_records(
            self._update_marks_with_disagreement())