text:
package logging

import (
	"fmt"
	"os"
	"path/filepath"

	log "gopkg.in/inconshreveable/log15.v2"
	"gopkg.in/inconshreveable/log15.v2/term"

	"github.com/lxc/lxd/shared/logger"
)

// GetLogger returns a logger suitable for using as logger.Log.
func GetLogger(syslog string, logfile string, verbose bool, debug bool, customHandler log.Handler) (logger.Logger, error) {
	Log := log.New()

	var handlers []log.Handler
	var syshandler log.Handler

	// Format handler
	format := LogfmtFormat()
	if term.IsTty(os.Stderr.Fd()) {
		format = TerminalFormat()
	}

	// System specific handler
	syshandler = getSystemHandler(syslog, debug, format)
	if syshandler != nil {
		handlers = append(handlers, syshandler)
	}

	// FileHandler
	if logfile != "" {
		if !pathExists(filepath.Dir(logfile)) {
			return nil, fmt.Errorf("Log file path doesn't exist: %s", filepath.Dir(logfile))
		}

		if !debug {
			handlers = append(
				handlers,
				log.LvlFilterHandler(
					log.LvlInfo,
					log.Must.FileHandler(logfile, format),
				),
			)
		} else {
			handlers = append(handlers, log.Must.FileHandler(logfile, format))
		}
	}

	// StderrHandler
	if verbose || debug {
		if !debug {
			handlers = append(
				handlers,
				log.LvlFilterHandler(
					log.LvlInfo,
					log.StreamHandler(os.Stderr, format),
				),
			)
		} else {
			handlers = append(handlers, log.StreamHandler(os.Stderr, format))
		}
	} else {
		handlers = append(
			handlers,
			log.LvlFilterHandler(
				log.LvlWarn,
				log.StreamHandler(os.Stderr, format),
			),
		)
	}

	if customHandler != nil {
		handlers = append(handlers, customHandler)
	}

	Log.SetHandler(log.MultiHandler(handlers...))

	return Log, nil
}

// AddContext will return a copy of the logger with extra context added
func AddContext(logger logger.Logger, ctx log.Ctx) logger.Logger {
	log15logger, ok := logger.(log.Logger)
	if !ok {
		logger.Error("couldn't downcast logger to add context", log.Ctx{"logger": log15logger, "ctx": ctx})
		return logger
	}

	return log15logger.New(ctx)
}

func pathExists(name string) bool {
	_, err := os.Lstat(name)
	if err != nil && os.IsNotExist(err) {
		return false
	}
	return true
}


text:
<?xml version="1.0" ?>
<doc>
	<str name="Patent Number">
		US5239446
	</str>
	<str name="Application Number">
		US07884759
	</str>
	<str name="Kind Code">
		A
	</str>
	<str name="Title">
		Watertight casing for electronic apparatus and assembling method therefor
	</str>
	<str name="Abstract">
		A watertight casing for electronic apparatus includes a first case, a second case and a cover. Sealing members are interposed between the first case and the second case, and between the second case and the cover, respectively. The first and the second cases and the cover are fastened tightly together. The first case is provided with a recess portion into which a printed circuit board is received. The printed circuit board mounts electronic parts on one side thereof, and a battery on the other side. Another sealing member is interposed between the second case and the other side of the printed circuit board.
	</str>
	<str name="Document Types">
		US | USB | DOCDB
	</str>
	<str name="Application Date">
		1992-05-18
	</str>
	<str name="Application Year">
		1992
	</str>
	<str name="Application(Year/Month)">
		1992-05
	</str>
	<str name="Publication Date">
		1993-08-24
	</str>
	<str name="Publication Year">
		1993
	</str>
	<str name="Publication(Year/Month)">
		1993-08
	</str>
	<str name="All IPC">
		H05K5/06
	</str>
	<str name="IPC Primary">
		H05K5/06
	</str>
	<str name="IPC Section">
		H
	</str>
	<str name="IPC Class">
		H05
	</str>
	<str name="IPC Subclass">
		H05K
	</str>
	<str name="IPC Group">
		H05K5
	</str>
	<str name="All UPC">
		361/736 | 174/52.3
	</str>
	<str name="UPC Primary">
		361/736
	</str>
	<str name="UPC Class">
		361
	</str>
	<str name="Family Members">
		GB9210794D0 | GB2256321A | US5239446 | JP2829796B2 | JP1992346499A | GB2256321B
	</str>
	<str name="Family Member Count">
		6
	</str>
	<str name="Family Members Cited By Count">
		0
	</str>
	<str name="Other References Count">
		0
	</str>
	<str name="Cites">
		US3873757 | GB2013437 | JP1982044713
	</str>
	<str name="Cites Count">
		3
	</str>
	<str name="Priority Country">
		JP
	</str>
	<str name="Priority Number">
		3120484
	</str>
	<str name="Priority Date">
		1991-05-24
	</str>
	<str name="Assignee(s)">
		MATSUSHITA ELECTRIC INDUSTRIAL CO., LTD.
	</str>
	<str name="1st Assignee">
		MATSUSHITA ELECTRIC INDUSTRIAL CO., LTD.
	</str>
	<str name="Number of Assignees">
		1
	</str>
	<str name="1st Assignee Address">
		Osaka, JP
	</str>
	<str name="Assignee(s) Address">
		Osaka, JP
	</str>
	<str name="Inventor(s)">
		MATSUMURA, TETSUO | HAYASHI, TAKAHIRO
	</str>
	<str name="1st Inventor">
		MATSUMURA, TETSUO
	</str>
	<str name="Number of Inventors">
		2
	</str>
	<str name="1st Inventor Address">
		Tokyo, JP
	</str>
	<str name="Inventor(s) Address">
		Tokyo, JP | Yokohama, JP
	</str>
	<str name="Agent/Attorney">
		STEVENS, DAVIS, MILLER & MOSHER
	</str>
	<str name="Primary Examiner">
		PICARD, LEO P.
	</str>
	<str name="Assistant Examiner">
		PHILLIPS, MICHAEL W.
	</str>
	<str name="cited by within 3 years">
		0
	</str>
	<str name="cited by within 5 years">
		0
	</str>
</doc>

redpajama_set_name: RedPajamaGithub


text:
/*
	[Discuz!] (C)2001-2009 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$Id: iframe.js 20769 2009-10-19 06:23:23Z monkey $
*/

function refreshmain(e) {
	e = e ? e : window.event;
	actualCode = e.keyCode ? e.keyCode : e.charCode;
	if(actualCode == 116 && parent.main) {
		parent.main.location.reload();
		if(document.all) {
			e.keyCode = 0;
			e.returnValue = false;
		} else {
			e.cancelBubble = true;
			e.preventDefault();
		}
	}
}

_attachEvent(document.documentElement, "keydown", refreshmain);


text:
title: RSS
published_at: 2016-01-10T17:37:07Z
---

I once read RSS described as the "Internet's long-tail of content", implying
that although the "big" links at any given time are readily available from any
of aggregator or social community because their popularity is a cascading
effect, RSS enables the discovery of content that might have otherwise gone
unseen.

I've been a heavy RSS user for years now, originally with Google Reader, and
then jumping to Feedly after its demise. I'd consider myself a major proponent
of the platform, and would love to see that utopian world where the majority of
the population ingested content via a collection of distributed feeds under
their own control instead of letting Facebook's timeline spoonfeed them
whatever its algorithm dredged up for the day. That said, even though RSS shows
no sign of disappearing anytime soon, we can say with pretty good certainty
that it's never going to be widely successful either. A lot of that is probably
because it's too difficult for an average user to understand and use, but at
least some of the fault lies with the technology itself, and that's caused
attrition among even its most technically-competent users.

Here are a few major weaknesses in RSS today:

* **Overwhelming volume:** The number of articles published in an RSS feed is
  entirely at the discretion of the content creator and larger outlets tend to
  publish more volume. Very large publishers often push out as many feed items
  just by themselves as dozens of smaller sources combined, and reading the
  whole feed or even just sifting through it for the best content is untenable.
  Major periodicals produce some of the best content out there, but almost all
  of them suffer from this problem very severely. For example, the New York
  Times writes great stories, but their main feed publishes on the order of 50
  items a day.
* **Lack of curation:** A possible solution to the problem of volume described
  above is to split content into separate channels so that users can follow a
  smaller feed that still has content relevant to them, but with a less frantic
  pace (which may be keyed to a particulr topic or city). But even here,
  readers must still rely on appropriate curation by the publisher, who has
  incentive to publish all their content rather than just what's the most
  relevant or highest quality. Two examples of feeds that I had to unsubscribe
  from for this reason are _Streetsblog_ and the _AWS Official Blog_, both of
  which were ostensibly subchannels that were keyed to topics I cared about
  (San Francisco for the former and AWS announcements for the latter), but both
  of which had very low signal to noise ratios in reality [1] [2].
* **Poor quality feeds:** A commonly seen problem are feeds that force readers
  to link to the original article by truncating content available in the RSS
  body. Although sensible for some publishers in that it probably improves ad
  impressions, this "breaks" RSS as a platform by making content very onerous
  to consume. And speaking of ads, another way to significantly degrade feed
  quality is to include them in the content body; obviously an advantage for
  the publisher, but one that wholly compromises the reading experience.

The theme common to all these problems is that content providers actually have
too much control

RSS feed "ratings"?

[1] _Streetsblog_ allows you to subscribe to a city blog (say San Francisco),
but even there still cross-posts with all kinds of irrelevant content to fill
up the feed.

[2] The _AWS Official Blog_ does indeed contain important announcements related
to major new products and features, but also mixes in trivial updates and
filler. An especially heinous offender are the "AWS Week in Review" posts,
which allow you to re-read all the content that you just read.


text:
{% extends "base.html" %}
{% load i18n %}
{% load txcommontags %}

{% block breadcrumb %}{% homelink %} » {% trans "Languages" %}{% endblock %}


text:
'use strict';

var xap = require('../index'),
    dgram = require('dgram');

var FakeDgram = function () {
  var self = this;
  self.sent = [];
  self.closed = 0;

  this.setBroadcast = function (flag) {
    self.broadcastFlag = flag;
  };
  this.bind = function (port) {
    self.boundPort = port;
  };
  this.send = function (buf, offset, length, port, address, callback) {
    self.sent.push({
      buf: buf,
      offset: offset,
      length: length,
      port: port,
      address: address,
      callback: callback
    });
    callback();
  };
  this.close = function () {
    self.closed ++;
  };
}

describe('XAPBroadcaster', function () {

  describe('generateMessage', function () {
    it('should format a message appropriately', function () {
      var message = xap.generateMessage(
        'xap-header',
        {v: 12, hop: 1, uid: 'FF123400', class: 'xap-temp.notification',
         source: 'ACME.thermostat.lounge'});
      expect(message).toEqual(
        'xap-header\n{\nv=12\nhop=1\nuid=FF123400\nclass=xap-temp.notification\nsource=ACME.thermostat.lounge\n}\n')
    });
  });

  describe('instantiation', function () {
    it('should default to version 12 messages', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.version).toEqual(12);
    });
    it('should be possible to specify a version', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', version: 11, source: 'testing', uid: 'FF123400'});
      expect(transmitter.version).toEqual(11);
    });
    it('should configure the class from the options', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.class).toEqual('test');
    });
    it('should throw an error if no class is provided', function () {
      expect(function () {
        var transmitter = new xap.XAPBroadcaster(
          {source: 'test', uid: 'FF123400'});
      }).toThrow(new Error('Must provide a class.'));
    });
    it('should configure the source from the options', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.source).toEqual('testing');
    });
    it('should throw an error if no source is provided', function () {
      expect(function () {
        var transmitter = new xap.XAPBroadcaster(
          {class: 'test', uid: 'FF123400'});
      }).toThrow(new Error('Must provide a source.'));
    });
    it('should configure the uid from the options', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.uid).toEqual('FF123400');
    });
    it('should throw an error if no uid is provided', function () {
      expect(function () {
        var transmitter = new xap.XAPBroadcaster(
          {class: 'test', source: 'testing'});
      }).toThrow(new Error('Must provide a uid.'));
    });
    it('should be possible to provide a broadcast address', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400', broadcast: '192.168.1.255'});
      expect(transmitter.broadcast).toEqual('192.168.1.255');
    });
    it('should default to a broadcast address of 255.255.255.255', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.broadcast).toEqual('255.255.255.255');
    });
    it('should be possible to provide a port', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400', port: 1234});
      expect(transmitter.port).toEqual(1234);
    });
    it('should default to port 3639', function () {
      var transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400'});
      expect(transmitter.port).toEqual(3639);
    });
  });
  describe('.send', function () {
    var transmitter,
        fakeDgram,
        dgramSpy;
    beforeEach(function () {
      transmitter = new xap.XAPBroadcaster(
        {class: 'test', source: 'testing', uid: 'FF123400',
         port: 1234, broadcast: '192.168.1.255'}),
        fakeDgram = new FakeDgram(),
        dgramSpy = spyOn(dgram, 'createSocket').andReturn(fakeDgram);
    });

/*
    it('should with the correct network settings', function (done) {
      var sentMessage;

      transmitter.send('temp.current', {'temp': 25, 'units': 'C'}, done);

      expect(dgramSpy).toHaveBeenCalledWith('udp4');
      expect(fakeDgram.sent.length).toEqual(1);
      sentMessage = fakeDgram.sent[0];
      expect(sentMessage.offset).toEqual(0);
      expect(sentMessage.port).toEqual(1234);
      expect(sentMessage.address).toEqual('192.168.1.255');
    });
    it('should close the socket after transmitting', function () {
      transmitter.send('temp.current', {'temp': 25, 'units': 'C'});
      expect(fakeDgram.closed).toEqual(1);
    });
    it('should set the broadcast flag on the socket', function () {
      transmitter.send('temp.current', {'temp': 25, 'units': 'C'});
      expect(fakeDgram.broadcastFlag).toBeTruthy();
    });
    it('should bind to the the socket address', function () {
      transmitter.send('temp.current', {'temp': 25, 'units': 'C'});
      expect(fakeDgram.boundPort).toEqual(3639);
    });
    it('should send the correct header', function (done) {
      var sentMessage,
          expectedMessage;

      transmitter.send('temp.current', {'temp': 25, 'units': 'C'}, done);
      expectedMessage = xap.generateMessage(
        'xap-header',
        {v: 12, hop: 1, uid: 'FF123400', class: 'test', source: 'testing'});
      expectedMessage += xap.generateMessage(
        'temp.current', {'temp': 25, 'units': 'C'});
      sentMessage = fakeDgram.sent[0];
      expect(sentMessage.buf.toString()).toEqual(expectedMessage);
    });
*/
    it('it should handle no callback', function () {
      transmitter.send('temp.current', {'temp': 25, 'units': 'C'});
    });
  });
});


text:
import { action, computed, observable } from 'mobx';
import { debounce, get } from 'lodash';
import { sidebarConfig } from '../config/sidebarConfig';
import type { SidebarCategoryInfo } from '../config/sidebarConfig';
import type {
  SidebarWalletType,
  WalletSortConfig,
  WalletSortByOptions,
} from '../types/sidebarTypes';
import { WalletSortBy, WalletSortOrder } from '../types/sidebarTypes';
import { changeWalletSorting, sortWallets } from '../utils/walletSorting';
import Store from './lib/Store';
import { EventCategories } from '../analytics';

export default class SidebarStore extends Store {
  @observable
  CATEGORIES: Array<any> = sidebarConfig.CATEGORIES_LIST;
  @observable
  activeSidebarCategory: string = this.CATEGORIES[0].route;
  @observable
  isShowingSubMenus = true;
  @observable
  walletSortConfig: WalletSortConfig = {
    sortBy: WalletSortBy.Date,
    sortOrder: WalletSortOrder.Asc,
  };
  @observable
  searchValue = '';

  setup() {
    const { sidebar: sidebarActions } = this.actions;
    sidebarActions.showSubMenus.listen(this._showSubMenus);
    sidebarActions.toggleSubMenus.listen(this._toggleSubMenus);
    sidebarActions.activateSidebarCategory.listen(
      this._onActivateSidebarCategory
    );
    sidebarActions.walletSelected.listen(this._onWalletSelected);
    this.registerReactions([
      this._syncSidebarRouteWithRouter,
      this._syncSidebarItemsWithShelleyActivation,
    ]);

    this._configureCategories();
  }

  // We need to use computed.struct for computed objects (so they are structurally compared
  // for equality instead of idendity (which would always invalidate)
  // https://alexhisen.gitbooks.io/mobx-recipes/content/use-computedstruct-for-computed-objects.html
  @computed.struct
  get wallets(): Array<SidebarWalletType> {
    const {
      networkStatus,
      wallets,
      walletSettings,
      hardwareWallets,
    } = this.stores;
    const { hardwareWalletsConnectionData } = hardwareWallets;
    const shelleyWallets = sortWallets({
      wallets: wallets.all.filter((w) => !w.isLegacy),
      sortOrder: this.walletSortConfig.sortOrder,
      sortBy: this.walletSortConfig.sortBy,
    });
    const byronWallets = sortWallets({
      wallets: wallets.all.filter((w) => w.isLegacy),
      sortOrder: this.walletSortConfig.sortOrder,
      sortBy: this.walletSortConfig.sortBy,
    });
    const sortedWallets = [...shelleyWallets, ...byronWallets];
    return sortedWallets.map((wallet) => {
      const isHardwareWalletDisconnected = get(
        hardwareWalletsConnectionData,
        [wallet.id, 'disconnected'],
        true
      );
      const {
        hasNotification,
      } = walletSettings.getWalletsRecoveryPhraseVerificationData(wallet.id);
      return {
        id: wallet.id,
        title: wallet.name,
        amount: wallet.amount,
        isConnected: networkStatus.isConnected,
        isRestoreActive: wallet.isRestoring,
        restoreProgress: wallet.restorationProgress,
        isNotResponding: wallet.isNotResponding,
        isLegacy: wallet.isLegacy,
        isHardwareWallet: wallet.isHardwareWallet,
        isHardwareWalletDisconnected,
        hasNotification,
      };
    });
  }

  @action
  onChangeWalletSortType = (sortBy: WalletSortByOptions) => {
    this.walletSortConfig = changeWalletSorting({
      sortBy,
      sortOrder: this.walletSortConfig.sortOrder,
      currentSortBy: this.walletSortConfig.sortBy,
    });

    this.analytics.sendEvent(
      EventCategories.LAYOUT,
      'Changed wallet sorting settings'
    );
  };
  @action
  onSearchValueUpdated = (searchValue: string) => {
    this.searchValue = searchValue;
    this._sendSearchAnalyticsEvent();
  };
  @action
  _configureCategories = () => {
    const {
      // @ts-ignore ts-migrate(2339) FIXME: Property 'isFlight' does not exist on type 'typeof... Remove this comment to see the full error message
      isFlight,
      // @ts-ignore ts-migrate(2339) FIXME: Property 'environment' does not exist on type 'typ... Remove this comment to see the full error message
      environment: { isDev, isMainnet },
    } = global;
    const {
      CATEGORIES_BY_NAME: categories,
      CATEGORIES_LIST: list,
    } = sidebarConfig;
    const categoryValidation: Record<
      string,
      boolean | ((...args: Array<any>) => any)
    > = {
      [categories.WALLETS.name]: true,
      [categories.PAPER_WALLET_CREATE_CERTIFICATE.name]: false,
      [categories.STAKING_DELEGATION_COUNTDOWN.name]: false,
      [categories.STAKING.name]: true,
      [categories.SETTINGS.name]: true,
      [categories.VOTING.name]: isMainnet || isDev,
      [categories.NETWORK_INFO.name]: isFlight,
    };
    const categoriesFilteredList: Array<SidebarCategoryInfo> = list.filter(
      ({ name }: SidebarCategoryInfo): boolean => {
        let validator = categoryValidation[name];

        if (typeof validator === 'function') {
          validator = validator();
        }

        // @ts-ignore ts-migrate(2322) FIXME: Type 'boolean | ((...args: any[]) => any)' is not ... Remove this comment to see the full error message
        return validator;
      }
    );
    this.CATEGORIES = categoriesFilteredList;
  };
  @action
  _onActivateSidebarCategory = (params: {
    category: string;
    showSubMenu?: boolean;
  }) => {
    const { category, showSubMenu } = params;

    if (category !== this.activeSidebarCategory) {
      this.activeSidebarCategory = category;
      if (showSubMenu != null) this.isShowingSubMenus = showSubMenu;
      this.actions.router.goToRoute.trigger({
        route: category,
      });
    } else if (showSubMenu == null || this.isShowingSubMenus !== showSubMenu) {
      // If no explicit preferred state is given -> toggle sub menus
      this._toggleSubMenus();
    } else {
      this.isShowingSubMenus = showSubMenu;
    }
  };
  @action
  _onWalletSelected = ({ walletId }: { walletId: string }) => {
    this.stores.wallets.goToWalletRoute(walletId);
  };
  @action
  _setActivateSidebarCategory = (category: string) => {
    this.activeSidebarCategory = category;
  };
  @action
  _resetActivateSidebarCategory = () => {
    this.activeSidebarCategory = '';
  };
  @action
  _showSubMenus = () => {
    this.isShowingSubMenus = true;
    this.analytics.sendEvent(EventCategories.LAYOUT, 'Toggled submenu');
  };
  @action
  _hideSubMenus = () => {
    this.isShowingSubMenus = false;
    this.analytics.sendEvent(EventCategories.LAYOUT, 'Toggled submenu');
  };
  @action
  _toggleSubMenus = () => {
    this.isShowingSubMenus = !this.isShowingSubMenus;
    this.analytics.sendEvent(EventCategories.LAYOUT, 'Toggled submenu');
  };
  _syncSidebarRouteWithRouter = () => {
    const route = this.stores.app.currentRoute;
    this.CATEGORIES.forEach((category) => {
      // If the current route starts with the root of the category
      if (route.indexOf(category.route) === 0)
        this._setActivateSidebarCategory(category.route);
    });
  };
  _syncSidebarItemsWithShelleyActivation = () => {
    const { isShelleyActivated, isShelleyPending } = this.stores.networkStatus;

    if (isShelleyActivated || isShelleyPending) {
      this._configureCategories();
    }
  };
  _sendSearchAnalyticsEvent = debounce(() => {
    this.analytics.sendEvent(EventCategories.LAYOUT, 'Used wallet search');
  }, 5000);
}


text:
package lz4

// expose the possible block max sizes
var BlockMaxSizeItems []int

func init() {
	for s := range bsMapValue {
		BlockMaxSizeItems = append(BlockMaxSizeItems, s)
	}
}

var FrameSkipMagic = frameSkipMagic


text:
using namespace vfspp;

// *****************************************************************************
// Constants
// *****************************************************************************

// *****************************************************************************
// Public Methods
// *****************************************************************************

CFileInfo::CFileInfo()
{

}

CFileInfo::~CFileInfo()
{

}

CFileInfo::CFileInfo(const std::string& basePath, const std::string& fileName, bool isDir)
{
    Initialize(basePath, fileName, isDir);
}

CFileInfo::CFileInfo(const std::string& filePath)
{
    std::size_t found = filePath.rfind("/");
    if (found != std::string::npos)
    {
        const std::string basePath = filePath.substr(0, found + 1);
        std::string fileName;
        if (found != filePath.length())
        {
            fileName = filePath.substr(found + 1, filePath.length() - found - 1);
        }

        Initialize(basePath, fileName, false);
    }
}

void CFileInfo::Initialize(const std::string& basePath, const std::string& fileName, bool isDir)
{
    m_BasePath = basePath;
    m_Name = fileName;
    m_IsDir = isDir;

    if (!CStringUtils::EndsWith(m_BasePath, "/"))
    {
        m_BasePath += "/";
    }

    if (isDir && !CStringUtils::EndsWith(m_Name, "/"))
    {
        m_Name += "/";
    }

    if (CStringUtils::StartsWith(m_Name, "/"))
    {
        m_Name = m_Name.substr(1, m_Name.length() - 1);
    }

    m_AbsolutePath = m_BasePath + m_Name;

    size_t dotsNum = std::count(m_Name.begin(), m_Name.end(), '.');
    bool isDotOrDotDot = (dotsNum == m_Name.length() && isDir);

    if (!isDotOrDotDot)
    {
        std::size_t found = m_Name.rfind(".");
        if (found != std::string::npos)
        {
            m_BaseName = m_Name.substr(0, found);
            if (found < m_Name.length())
            {
                m_Extension = m_Name.substr(found, m_Name.length() - found);
            }
        }
    }
}

const std::string& CFileInfo::Name() const
{
    return m_Name;
}

const std::string& CFileInfo::BaseName() const
{
    return m_BaseName;
}

const std::string& CFileInfo::Extension() const
{
    return m_Extension;
}

const std::string& CFileInfo::AbsolutePath() const
{
    return m_AbsolutePath;
}

const std::string& CFileInfo::BasePath() const
{
    return m_BasePath;
}

bool CFileInfo::IsDir() const
{
    return m_IsDir;
}

bool CFileInfo::IsValid() const
{
    return !m_AbsolutePath.empty();
}

// *****************************************************************************
// Protected Methods
// *****************************************************************************

// *****************************************************************************
// Private Methods
// *****************************************************************************


text:
#ifndef __PU_ONPOSITION_OBSERVER_H__
#define __PU_ONPOSITION_OBSERVER_H__

#include "ParticleUniversePrerequisites.h"
#include "ParticleUniverseCommon.h"
#include "ParticleUniverseObserver.h"

namespace ParticleUniverse
{
	/** This class is used to observe whether a Particle reaches a certain position.
    */
	class _ParticleUniverseExport OnPositionObserver : public ParticleObserver
	{
		protected:
			Real mPositionXThreshold;
			Real mPositionYThreshold;
			Real mPositionZThreshold;
			bool mPositionXThresholdSet;
			bool mPositionYThresholdSet;
			bool mPositionZThresholdSet;
			ComparisionOperator mComparePositionX;
			ComparisionOperator mComparePositionY;
			ComparisionOperator mComparePositionZ;

		public:
			// Constants
			static const Vector3 DEFAULT_POSITION_THRESHOLD;

			OnPositionObserver(void);
	        virtual ~OnPositionObserver(void) {};

			/**
	        */
			virtual bool _observe (ParticleTechnique* particleTechnique, Particle* particle, Real timeElapsed);

			/**
			 */
			void setPositionXThreshold(Real threshold){mPositionXThreshold = threshold; mPositionXThresholdSet = true;};
			void setPositionYThreshold(Real threshold){mPositionYThreshold = threshold; mPositionYThresholdSet = true;};
			void setPositionZThreshold(Real threshold){mPositionZThreshold = threshold; mPositionZThresholdSet = true;};

			/**
			 */
			Real getPositionXThreshold(void) const {return mPositionXThreshold;};
			Real getPositionYThreshold(void) const {return mPositionYThreshold;};
			Real getPositionZThreshold(void) const {return mPositionZThreshold;};

			/**
			 */
			bool isPositionXThresholdSet(void) const {return mPositionXThresholdSet;};
			bool isPositionYThresholdSet(void) const {return mPositionYThresholdSet;};
			bool isPositionZThresholdSet(void) const {return mPositionZThresholdSet;};

			/**
			 */
			void resetPositionXThreshold(void) {mPositionXThresholdSet = false;};
			void resetPositionYThreshold(void) {mPositionYThresholdSet = false;};
			void resetPositionZThreshold(void) {mPositionZThresholdSet = false;};

			/**
			 */
			void setComparePositionX(ComparisionOperator op){mComparePositionX = op;};
			void setComparePositionY(ComparisionOperator op){mComparePositionY = op;};
			void setComparePositionZ(ComparisionOperator op){mComparePositionZ = op;};

			/**
			 */
			const ComparisionOperator getComparePositionX(void) const {return mComparePositionX;};
			const ComparisionOperator getComparePositionY(void) const {return mComparePositionY;};
			const ComparisionOperator getComparePositionZ(void) const {return mComparePositionZ;};

			/** Copy attributes to another observer.
	        */
			virtual void copyAttributesTo (ParticleObserver* observer);
	};

}
#endif


text:
@interface SearchBarController ()

@end

@implementation SearchBarController

- (void)viewDidLoad {
    self.navigationItem.title = @"搜索框选择";
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    UIButton *button1 = [[UIButton alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 50)];
    [button1 setTitle:@"固定的搜索框" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(clickedBtn1:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button1];

    UIButton *button2 = [[UIButton alloc] initWithFrame:CGRectMake(0, 150, self.view.frame.size.width, 50)];
    [button2 setTitle:@"随着滚动的搜索框" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(CilckedBtn2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button2];

    UIButton *button3 = [[UIButton alloc] initWithFrame:CGRectMake(0, 250, self.view.frame.size.width, 50)];
    [button3 setTitle:@"实时搜索" forState:UIControlStateNormal];
    [button3 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button3 addTarget:self action:@selector(CilckedBtn3:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button3];

    UIButton *button4 = [[UIButton alloc] initWithFrame:CGRectMake(0, 300, self.view.frame.size.width, 50)];
    [button4 setTitle:@"随着滚动的搜索框" forState:UIControlStateNormal];
    [button4 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [button4 addTarget:self action:@selector(CilckedBtn4:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button4];
}

- (void)clickedBtn1:(id)sender {
    AnotherSearchViewController *another = [AnotherSearchViewController new];
    [self.navigationController pushViewController:another animated:YES];
}

- (void)CilckedBtn2:(id)sender {
    SecondSearchViewController *search = [SecondSearchViewController new];
    [self.navigationController pushViewController:search animated:YES];
}

- (void)CilckedBtn3:(id)sender {
    TextSearchViewController *vc = [[TextSearchViewController alloc] init];

    vc.searchMode = SearchModeRealTime;

    [self.navigationController pushViewController:vc animated:YES];
}

- (void)CilckedBtn4:(id)sender {
    TextSearchViewController *vc = [[TextSearchViewController alloc] init];

    vc.searchMode = SearchModeAction;

    [self.navigationController pushViewController:vc animated:YES];
}

@end


text:
use super::utils::{align, is_aligned, REC_HEADER_LEN};
use super::version::Version;
use super::TickUnit;
use crate::api::ChannelError;
use crate::api::ChannelError::{IncompatibleVersion, InvalidCapacity, InvalidMaxMessageLength, InvalidSignature};
use std::cmp::max;
use std::cmp::min;

const MIN_CAPACITY: u32 = 1024 * 16;
const METADATA_LEN: usize = 128;
const SIGNATURE: u64 = 0x2A54_4942_4B45_4B2A; //"*KEKBIT*" as bytes as u64

#[inline]
const fn compute_max_msg_len(capacity: u32) -> u32 {
    //if you reduce MIN_CAPACITY this may underflow!
    (capacity >> 7) - (REC_HEADER_LEN as u32)
}

/// Defines and validates the metadata associated with a channel.
#[derive(PartialEq, Eq, Debug)]
pub struct Metadata {
    writer_id: u64,
    channel_id: u64,
    capacity: u32,
    max_msg_len: u32,
    timeout: u64,
    creation_time: u64,
    tick_unit: TickUnit,
    version: Version,
}

#[allow(clippy::len_without_is_empty)]
impl Metadata {
    /// Defines a new channel metadata.
    ///
    /// Return a struct that contains all the metadata required to be associated with a new channel.
    ///
    /// # Arguments
    ///
    /// * `writer_id` - Channel's writer identifier
    /// * `channel_id` - Channel's identifier
    /// * `capacity_hint` - Hint for the size of the channel - the maximum amount of data that can be wrote into the channel.
    ///                  Usually a successfully created channel will have a size very close to this hint, probably a little larger.
    /// * `max_msg_len_hint` - Hint for the maximum size of a message wrote into the channel. This cannot be larger than a certain fraction.
    ///        of the channel's capacity(1/128th), so the new created channel may have max message length value smaller than this hint.
    /// * `timeout` - Specifies the write inactivity time interval after each the reader will consider the channel abandoned by the writer.
    /// * `tick_unit` - Time unit used by the timeout and creation time attributes.
    ///
    /// # Example
    ///
    /// ```
    /// use kekbit::core::TickUnit::Nanos;
    /// use kekbit::core::*;
    ///
    /// let producer_id: u64 = 111;
    /// let channel_id: u64 = 101;
    /// let capacity: u32 = 10_001;
    /// let max_msg_len: u32 = 100;
    /// let timeout: u64 = 10_000;
    /// let tick_unit = Nanos;
    /// let metadata = Metadata::new(channel_id, producer_id, capacity, max_msg_len, timeout, tick_unit);
    /// println!("{:?}", &metadata);
    /// ````
    ///
    ///
    #[inline]
    pub fn new(
        writer_id: u64,
        channel_id: u64,
        capacity_hint: u32,
        max_msg_len_hint: u32,
        timeout: u64,
        tick_unit: TickUnit,
    ) -> Metadata {
        let capacity = max(MIN_CAPACITY, align(capacity_hint));
        let max_msg_len = align(min(max_msg_len_hint + REC_HEADER_LEN, compute_max_msg_len(capacity)) as u32);
        let creation_time = tick_unit.nix_time();
        Metadata {
            writer_id,
            channel_id,
            capacity,
            max_msg_len,
            timeout,
            creation_time,
            tick_unit,
            version: Version::latest(),
        }
    }
    ///Reads and `validates` the metadata from an existing memory mapped channel.
    ///
    ///Returns the metadata associated with the channel.
    ///
    /// # Arguments
    ///
    /// * `metadata` - Reference to a  byte array which should contain metadata associated with a given channel.
    ///              Usually points at the beginning of a memory mapped file used as storage for a kekbit channel.
    ///
    /// # Errors
    ///
    /// An error will occur if data is corrupted or points to an incompatible version of kekbit channel.
    ///
    /// # Example
    ///
    ///```
    /// use memmap::MmapOptions;
    /// use std::fs::OpenOptions;
    ///
    /// # use kekbit::core::TickUnit::Nanos;
    /// # use kekbit::core::Metadata;
    /// use kekbit::core::*;
    /// use kekbit::api::*;
    /// # const FOREVER: u64 = 99_999_999_999;
    /// let writer_id = 1850;
    /// let channel_id = 4242;
    /// # let metadata = Metadata::new(writer_id, channel_id, 300_000, 1000, FOREVER, Nanos);
    /// let test_tmp_dir = tempdir::TempDir::new("kektest").unwrap();
    /// let dir_path = test_tmp_dir.path();
    ///  # let writer = shm_writer(&test_tmp_dir.path(), &metadata, EncoderHandler::default()).unwrap();
    ///
    /// let kek_file_name = storage_path(dir_path, channel_id);
    /// let kek_file = OpenOptions::new()
    ///  .write(true)
    ///  .read(true)
    ///  .open(&kek_file_name).unwrap();
    ///  let mut mmap = unsafe { MmapOptions::new().map_mut(&kek_file) }.unwrap();
    ///  let buf = &mut mmap[..];
    ///  let metadata = Metadata::read(buf).unwrap();
    ///  println!("{:?}", &metadata);
    ///  ```
    ///
    pub fn read(metadata: &[u8]) -> Result<Metadata, ChannelError> {
        assert!(metadata.len() >= METADATA_LEN);
        let mut offset = 0;
        let signature = Metadata::read_u64(metadata, offset);
        if signature != SIGNATURE {
            return Err(InvalidSignature {
                expected: SIGNATURE,
                actual: signature,
            });
        }
        offset += 8;
        let version: Version = Metadata::read_u64(metadata, 8).into();
        let latest = Version::latest();
        if !latest.is_compatible(version) {
            return Err(IncompatibleVersion {
                expected: latest.into(),
                actual: version.into(),
            });
        }
        offset += 8;
        let writer_id = Metadata::read_u64(metadata, offset);
        offset += 8;
        let channel_id = Metadata::read_u64(metadata, offset);
        offset += 8;
        let capacity = Metadata::read_u32(metadata, offset);
        if capacity < MIN_CAPACITY {
            return Err(InvalidCapacity {
                capacity,
                msg: "Capacity below minimum allowed of 10KB",
            });
        }
        if !is_aligned(MIN_CAPACITY) {
            return Err(InvalidCapacity {
                capacity,
                msg: "Capacity is not 8 bytes aligned",
            });
        }
        offset += 4;
        let max_msg_len = Metadata::read_u32(metadata, offset);
        if max_msg_len > align(compute_max_msg_len(capacity)) {
            return Err(InvalidMaxMessageLength {
                msg_len: max_msg_len,
                msg: "Max message lenght is too large",
            });
        }
        if !is_aligned(max_msg_len) {
            return Err(InvalidMaxMessageLength {
                msg_len: max_msg_len,
                msg: "Max message length is not 8 bytes aligned",
            });
        }
        offset += 4;
        let timeout = Metadata::read_u64(metadata, offset);
        offset += 8;
        let creation_time = Metadata::read_u64(metadata, offset);
        offset += 8;
        let tick_unit = TickUnit::from_id(metadata[offset]);
        //offset += 1;
        Ok(Metadata {
            writer_id,
            channel_id,
            capacity,
            max_msg_len,
            timeout,
            creation_time,
            tick_unit,
            version,
        })
    }
    ///Writes kekbit metadata to a memory mapepd file.
    ///
    /// Returns  the lenght of the metadata
    ///
    /// # Arguments
    ///
    /// * `metadata` - Reference to a byte slice where metadata must be written.
    ///              Usually points at the beginning of a memory mapped file used as storage for a kekbit channel.
    ///
    /// # Example
    ///
    ///```
    /// use memmap::MmapOptions;
    /// use std::fs::OpenOptions;
    ///
    /// use kekbit::core::TickUnit::Nanos;
    /// use kekbit::core::Metadata;
    /// use kekbit::core::*;
    /// use std::fs::DirBuilder;
    ///
    /// const FOREVER: u64 = 99_999_999_999;
    /// let writer_id = 1850;
    /// let channel_id = 42;
    /// let test_tmp_dir = tempdir::TempDir::new("keksample").unwrap();
    /// let dir_path = test_tmp_dir.path().join(writer_id.to_string());
    /// let mut builder = DirBuilder::new();
    /// builder.recursive(true);
    /// builder.create(&dir_path).or_else(|err| Err(err.to_string())).unwrap();
    ///
    /// let kek_file_name = dir_path.join(format!("{}.kekbit", channel_id));
    /// let kek_file = OpenOptions::new()
    /// .write(true)
    /// .read(true)
    /// .create(true)
    /// .open(&kek_file_name)
    /// .or_else(|err| Err(err.to_string())).unwrap();
    ///
    /// let metadata = Metadata::new(writer_id, channel_id, 300_000, 1000, FOREVER, Nanos);
    /// let total_len = (metadata.capacity() + metadata.len() as u32) as u64;
    /// kek_file.set_len(total_len).or_else(|err| Err(err.to_string())).unwrap();
    /// let mut mmap = unsafe { MmapOptions::new().map_mut(&kek_file) }.unwrap();
    /// let buf = &mut mmap[..];
    /// metadata.write_to(buf);
    /// mmap.flush().unwrap();
    /// ```
    #[inline]
    pub fn write_to(&self, metadata: &mut [u8]) -> usize {
        assert!(self.len() <= metadata.len());
        metadata[0..8].clone_from_slice(&SIGNATURE.to_le_bytes());
        let latest_v: u64 = Version::latest().into();
        metadata[8..16].clone_from_slice(&latest_v.to_le_bytes());
        metadata[16..24].clone_from_slice(&self.writer_id.to_le_bytes());
        metadata[24..32].clone_from_slice(&self.channel_id.to_le_bytes());
        metadata[32..36].clone_from_slice(&self.capacity.to_le_bytes());
        metadata[36..40].clone_from_slice(&self.max_msg_len.to_le_bytes());
        metadata[40..48].clone_from_slice(&self.timeout.to_le_bytes());
        metadata[48..56].clone_from_slice(&self.creation_time.to_le_bytes());
        metadata[56] = self.tick_unit.id();
        let last = 57;
        for item in metadata.iter_mut().take(METADATA_LEN).skip(last) {
            *item = 0u8;
        }
        self.len()
    }

    #[inline]
    fn read_u64(metadata: &[u8], offset: usize) -> u64 {
        assert!(offset + 8 < METADATA_LEN);
        u64::from_le_bytes([
            metadata[offset],
            metadata[offset + 1],
            metadata[offset + 2],
            metadata[offset + 3],
            metadata[offset + 4],
            metadata[offset + 5],
            metadata[offset + 6],
            metadata[offset + 7],
        ])
    }

    #[inline]
    fn read_u32(metadata: &[u8], offset: usize) -> u32 {
        assert!(offset + 4 < METADATA_LEN);
        u32::from_le_bytes([
            metadata[offset],
            metadata[offset + 1],
            metadata[offset + 2],
            metadata[offset + 3],
        ])
    }

    ///Returns the metadata version
    #[inline]
    pub fn version(&self) -> String {
        self.version.to_string()
    }

    ///Returns the channel identifier
    #[inline]
    pub fn channel_id(&self) -> u64 {
        self.channel_id
    }

    ///Returns the channel writer identifier
    #[inline]
    pub fn writer_id(&self) -> u64 {
        self.writer_id
    }

    ///Returns the capacity of the channel
    #[inline]
    pub fn capacity(&self) -> u32 {
        self.capacity
    }

    ///Returns the maximum message size allowed
    #[inline]
    pub fn max_msg_len(&self) -> u32 {
        self.max_msg_len
    }
    ///Returns the inactivity time interval after each the reader will consider the channel abandoned by the writer.
    #[inline]
    pub fn timeout(&self) -> u64 {
        self.timeout
    }

    ///Returns the channel creation time
    #[inline]
    pub fn creation_time(&self) -> u64 {
        self.creation_time
    }
    ///Returns the time unit used by the channel creation time and the timeout attributes.
    #[inline]
    pub fn tick_unit(&self) -> TickUnit {
        self.tick_unit
    }
    #[inline]
    ///Returns  the length of the metadata. For any given version the length is the same.
    ///In the current version it is 128 bytes.
    pub const fn len(&self) -> usize {
        METADATA_LEN
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn check_read_write_metadata() {
        let producer_id: u64 = 111;
        let channel_id: u64 = 101;
        let capacity: u32 = 10_001;
        let max_msg_len: u32 = 100;
        let timeout: u64 = 10_000;
        let tick_unit = TickUnit::Nanos;
        let head = Metadata::new(producer_id, channel_id, capacity, max_msg_len, timeout, tick_unit);
        let mut data = vec![0u8; METADATA_LEN];
        assert!(head.write_to(&mut data) == METADATA_LEN);
        assert!(Metadata::read(&data).unwrap() == head);
        assert_eq!(head.tick_unit(), TickUnit::Nanos);
        assert_eq!(head.timeout(), timeout);
        assert_eq!(head.version(), Version::latest().to_string());
        assert!(head.creation_time() < tick_unit.nix_time());
        assert_eq!(head.len(), 128);
        assert_eq!(head.writer_id(), producer_id);
    }
}


text:
Take Photo

Take a photo using your web cam, right now!

    <button class="btn btn-default" id="freeze">
         Preview
    </button>
    <button class="btn btn-danger" id="retake">
         Retake
    </button>
    <button class="btn btn-success disabled" id="save">
         Save
    </button>

Say Cheese!

                <video autoplay id="videoElement"></video>

Preview

If you're having troble, try the tried-and-true file upload option.

    <input id="fileselect" type="file" accept="image/png" capture="camera">


text:
package com.vmware.vim25;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;

/**
 *
Java class for InheritablePolicy complex type.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *
 *

 * <complexType name="InheritablePolicy">
 *   <complexContent>
 *     <extension base="{urn:vim25}DynamicData">
 *       <sequence>
 *         <element name="inherited" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
 *       </sequence>
 *     </extension>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "InheritablePolicy", propOrder = {
    "inherited"
})
@XmlSeeAlso({
    DVSVendorSpecificConfig.class,
    DVSTrafficShapingPolicy.class,
    IntPolicy.class,
    VmwareUplinkPortTeamingPolicy.class,
    DVSSecurityPolicy.class,
    VMwareUplinkPortOrderPolicy.class,
    LongPolicy.class,
    VMwareUplinkLacpPolicy.class,
    StringPolicy.class,
    DvsFilterPolicy.class,
    DVSFailureCriteria.class,
    VmwareDistributedVirtualSwitchVlanSpec.class,
    DvsFilterConfig.class,
    BoolPolicy.class
})
public class InheritablePolicy
    extends DynamicData
{

    protected boolean inherited;

    /**
     * Gets the value of the inherited property.
     *
     */
    public boolean isInherited() {
        return inherited;
    }

    /**
     * Sets the value of the inherited property.
     *
     */
    public void setInherited(boolean value) {
        this.inherited = value;
    }

}


text:
<!DOCTYPE html>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

        <link href="{{site.baseurl}}/assets/css/plugins/plugins.css" rel="stylesheet">

        <link href="{{site.baseurl}}/assets/css/style.css" rel="stylesheet">

        <link rel="shortcut icon" href="{{site.baseurl}}/assets/img/computer.png">

Need Help? Contact the USD ServiceDesk

 servicedesk@usd.edu

 1+ (605) 658 6000

 1+ (877) 225 0027

                     <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">

                </button>

 Home

 About

 Services

 Resources

 Education

 Contact Us

    {{content}}

Contact Info

 University of South Dakota

    1+ (877) 225 0027

      servicedesk@usd.edu

    @usdrcg

Welcome Wagon

                            Workshops

We offer hands-on training sessions.

                            Training Documents

Here you can find how-to instructions.

External Training

                            Software Carpentry

This site has tutorials for beginners.

                            Explain Shell

This tool explains shell commands.

                        ©2017-present. All right reserved. Maintained by wendikristine.


text:
package org.apache.spark.util

import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer

import org.apache.spark.SparkConf
import org.apache.spark.sql.{CarbonEnv, SparkSession}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.hive.{CarbonRelation, CarbonSessionState}
import org.apache.spark.sql.hive.HiveExternalCatalog._

import org.apache.carbondata.common.logging.LogServiceFactory
import org.apache.carbondata.core.constants.CarbonCommonConstants
import org.apache.carbondata.core.datastore.impl.FileFactory
import org.apache.carbondata.core.locks.{CarbonLockUtil, ICarbonLock}
import org.apache.carbondata.core.metadata.CarbonTableIdentifier
import org.apache.carbondata.core.metadata.schema.table.CarbonTable
import org.apache.carbondata.core.util.path.CarbonStorePath
import org.apache.carbondata.format.{SchemaEvolutionEntry, TableInfo}

object AlterTableUtil {

  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)

  /**
   * Validates that the table exists and acquires meta lock on it.
   *
   * @param dbName
   * @param tableName
   * @param sparkSession
   * @return
   */
  def validateTableAndAcquireLock(dbName: String,
      tableName: String,
      locksToBeAcquired: List[String])
    (sparkSession: SparkSession): List[ICarbonLock] = {
    val relation =
      CarbonEnv.getInstance(sparkSession).carbonMetastore
        .lookupRelation(Option(dbName), tableName)(sparkSession)
        .asInstanceOf[CarbonRelation]
    if (relation == null) {
      LOGGER.audit(s"Alter table request has failed. " +
                   s"Table $dbName.$tableName does not exist")
      sys.error(s"Table $dbName.$tableName does not exist")
    }
    // acquire the lock first
    val table = relation.tableMeta.carbonTable
    val acquiredLocks = ListBuffer[ICarbonLock]()
    try {
      locksToBeAcquired.foreach { lock =>
        acquiredLocks += CarbonLockUtil.getLockObject(table.getCarbonTableIdentifier, lock)
      }
      acquiredLocks.toList
    } catch {
      case e: Exception =>
        releaseLocks(acquiredLocks.toList)
        throw e
    }
  }

  /**
   * This method will release the locks acquired for an operation
   *
   * @param locks
   */
  def releaseLocks(locks: List[ICarbonLock]): Unit = {
    locks.foreach { carbonLock =>
      if (carbonLock.unlock()) {
        LOGGER.info("Alter table lock released successfully")
      } else {
        LOGGER.error("Unable to release lock during alter table operation")
      }
    }
  }

  /**
   * This method will release the locks by manually forming a lock path. Specific usage for
   * rename table
   *
   * @param locks
   * @param locksAcquired
   * @param dbName
   * @param tableName
   * @param storeLocation
   */
  def releaseLocksManually(locks: List[ICarbonLock],
      locksAcquired: List[String],
      dbName: String,
      tableName: String,
      storeLocation: String): Unit = {
    val lockLocation = storeLocation + CarbonCommonConstants.FILE_SEPARATOR +
                       dbName + CarbonCommonConstants.FILE_SEPARATOR + tableName
    locks.zip(locksAcquired).foreach { case (carbonLock, lockType) =>
      val lockFilePath = lockLocation + CarbonCommonConstants.FILE_SEPARATOR +
                         lockType
      if (carbonLock.releaseLockManually(lockFilePath)) {
        LOGGER.info(s"Alter table lock released successfully: ${ lockType }")
      } else {
        LOGGER.error("Unable to release lock during alter table operation")
      }
    }
  }

  /**
   * @param carbonTable
   * @param schemaEvolutionEntry
   * @param thriftTable
   * @param sparkSession
   * @param sessionState
   */
  def updateSchemaInfo(carbonTable: CarbonTable,
      schemaEvolutionEntry: SchemaEvolutionEntry,
      thriftTable: TableInfo)(sparkSession: SparkSession,
      sessionState: CarbonSessionState): Unit = {
    val dbName = carbonTable.getDatabaseName
    val tableName = carbonTable.getFactTableName
    CarbonEnv.getInstance(sparkSession).carbonMetastore
      .updateTableSchema(carbonTable.getCarbonTableIdentifier,
        carbonTable.getCarbonTableIdentifier,
        thriftTable,
        schemaEvolutionEntry,
        carbonTable.getAbsoluteTableIdentifier.getTablePath)(sparkSession)
    val tableIdentifier = TableIdentifier(tableName, Some(dbName))
    sparkSession.catalog.refreshTable(tableIdentifier.quotedString)
    val schema = CarbonEnv.getInstance(sparkSession).carbonMetastore
      .lookupRelation(tableIdentifier)(sparkSession).schema.json
    val schemaParts = prepareSchemaJsonForAlterTable(sparkSession.sparkContext.getConf, schema)
    sessionState.metadataHive.runSqlHive(
      s"ALTER TABLE $dbName.$tableName SET TBLPROPERTIES($schemaParts)")
    sparkSession.catalog.refreshTable(tableIdentifier.quotedString)
  }

  /**
   * This method will split schema string into multiple parts of configured size and
   * registers the parts as keys in tableProperties which will be read by spark to prepare
   * Carbon Table fields
   *
   * @param sparkConf
   * @param schemaJsonString
   * @return
   */
  private def prepareSchemaJsonForAlterTable(sparkConf: SparkConf,
      schemaJsonString: String): String = {
    val threshold = sparkConf
      .getInt(CarbonCommonConstants.SPARK_SCHEMA_STRING_LENGTH_THRESHOLD,
        CarbonCommonConstants.SPARK_SCHEMA_STRING_LENGTH_THRESHOLD_DEFAULT)
    // Split the JSON string.
    val parts = schemaJsonString.grouped(threshold).toSeq
    var schemaParts: Seq[String] = Seq.empty
    schemaParts = schemaParts :+ s"'$DATASOURCE_SCHEMA_NUMPARTS'='${ parts.size }'"
    parts.zipWithIndex.foreach { case (part, index) =>
      schemaParts = schemaParts :+ s"'$DATASOURCE_SCHEMA_PART_PREFIX$index'='$part'"
    }
    schemaParts.mkString(",")
  }

  /**
   * This method reverts the changes to the schema if the rename table command fails.
   *
   * @param oldTableIdentifier
   * @param newTableName
   * @param timeStamp
   * @param sparkSession
   */
  def revertRenameTableChanges(oldTableIdentifier: TableIdentifier,
      newTableName: String,
      storePath: String,
      tableId: String,
      timeStamp: Long)
    (sparkSession: SparkSession): Unit = {
    val database = oldTableIdentifier.database.getOrElse(sparkSession.catalog.currentDatabase)
    val newCarbonTableIdentifier = new CarbonTableIdentifier(database, newTableName, tableId)
    val carbonTablePath = CarbonStorePath.getCarbonTablePath(storePath, newCarbonTableIdentifier)
    val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
    val tableMetadataFile = carbonTablePath.getPath
    val fileType = FileFactory.getFileType(tableMetadataFile)
    if (FileFactory.isFileExist(tableMetadataFile, fileType)) {
      val tableInfo = if (metastore.isReadFromHiveMetaStore) {
        // In case of hive metastore we first update the carbonschema inside old table only.
        metastore.getThriftTableInfo(CarbonStorePath.getCarbonTablePath(storePath,
          new CarbonTableIdentifier(database, oldTableIdentifier.table, tableId)))(sparkSession)
      } else {
        metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
      }
      val evolutionEntryList = tableInfo.fact_table.schema_evolution.schema_evolution_history
      val updatedTime = evolutionEntryList.get(evolutionEntryList.size() - 1).time_stamp
      if (updatedTime == timeStamp) {
        LOGGER.error(s"Reverting changes for $database.${ oldTableIdentifier.table }")
        FileFactory.getCarbonFile(carbonTablePath.getPath, fileType)
          .renameForce(carbonTablePath.getParent.toString + CarbonCommonConstants.FILE_SEPARATOR +
                       oldTableIdentifier.table)
        val tableIdentifier = new CarbonTableIdentifier(database, oldTableIdentifier.table, tableId)
        metastore.revertTableSchema(tableIdentifier,
          tableInfo, carbonTablePath.getPath)(sparkSession)
        metastore.removeTableFromMetadata(database, newTableName)
      }
    }
  }

  /**
   * This method reverts the changes to the schema if add column command fails.
   *
   * @param dbName
   * @param tableName
   * @param timeStamp
   * @param sparkSession
   */
  def revertAddColumnChanges(dbName: String, tableName: String, timeStamp: Long)
    (sparkSession: SparkSession): Unit = {
    val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
    val carbonTable = metastore
      .lookupRelation(Some(dbName), tableName)(sparkSession).asInstanceOf[CarbonRelation].tableMeta
      .carbonTable

    val carbonTablePath = CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
      carbonTable.getCarbonTableIdentifier)
    val thriftTable: TableInfo = metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
    val evolutionEntryList = thriftTable.fact_table.schema_evolution.schema_evolution_history
    val updatedTime = evolutionEntryList.get(evolutionEntryList.size() - 1).time_stamp
    if (updatedTime == timeStamp) {
      LOGGER.info(s"Reverting changes for $dbName.$tableName")
      val addedSchemas = evolutionEntryList.get(evolutionEntryList.size() - 1).added
      thriftTable.fact_table.table_columns.removeAll(addedSchemas)
      metastore
        .revertTableSchema(carbonTable.getCarbonTableIdentifier,
          thriftTable, carbonTable.getAbsoluteTableIdentifier.getTablePath)(sparkSession)
    }
  }

  /**
   * This method reverts the schema changes if drop table command fails.
   *
   * @param dbName
   * @param tableName
   * @param timeStamp
   * @param sparkSession
   */
  def revertDropColumnChanges(dbName: String, tableName: String, timeStamp: Long)
    (sparkSession: SparkSession): Unit = {
    val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
    val carbonTable = metastore
      .lookupRelation(Some(dbName), tableName)(sparkSession).asInstanceOf[CarbonRelation].tableMeta
      .carbonTable
    val carbonTablePath = CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
      carbonTable.getCarbonTableIdentifier)
    val thriftTable: TableInfo = metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
    val evolutionEntryList = thriftTable.fact_table.schema_evolution.schema_evolution_history
    val updatedTime = evolutionEntryList.get(evolutionEntryList.size() - 1).time_stamp
    if (updatedTime == timeStamp) {
      LOGGER.error(s"Reverting changes for $dbName.$tableName")
      val removedSchemas = evolutionEntryList.get(evolutionEntryList.size() - 1).removed
      thriftTable.fact_table.table_columns.asScala.foreach { columnSchema =>
        removedSchemas.asScala.foreach { removedSchemas =>
          if (columnSchema.invisible && removedSchemas.column_id == columnSchema.column_id) {
            columnSchema.setInvisible(false)
          }
        }
      }
      metastore
        .revertTableSchema(carbonTable.getCarbonTableIdentifier,
          thriftTable, carbonTable.getAbsoluteTableIdentifier.getTablePath)(sparkSession)
    }
  }

  /**
   * This method reverts the changes to schema if the data type change command fails.
   *
   * @param dbName
   * @param tableName
   * @param timeStamp
   * @param sparkSession
   */
  def revertDataTypeChanges(dbName: String, tableName: String, timeStamp: Long)
    (sparkSession: SparkSession): Unit = {
    val metastore = CarbonEnv.getInstance(sparkSession).carbonMetastore
    val carbonTable = metastore
      .lookupRelation(Some(dbName), tableName)(sparkSession).asInstanceOf[CarbonRelation].tableMeta
      .carbonTable
    val carbonTablePath = CarbonStorePath.getCarbonTablePath(carbonTable.getStorePath,
      carbonTable.getCarbonTableIdentifier)
    val thriftTable: TableInfo = metastore.getThriftTableInfo(carbonTablePath)(sparkSession)
    val evolutionEntryList = thriftTable.fact_table.schema_evolution.schema_evolution_history
    val updatedTime = evolutionEntryList.get(evolutionEntryList.size() - 1).time_stamp
    if (updatedTime == timeStamp) {
      LOGGER.error(s"Reverting changes for $dbName.$tableName")
      val removedColumns = evolutionEntryList.get(evolutionEntryList.size() - 1).removed
      thriftTable.fact_table.table_columns.asScala.foreach { columnSchema =>
        removedColumns.asScala.foreach { removedColumn =>
          if (columnSchema.column_id.equalsIgnoreCase(removedColumn.column_id) &&
              !columnSchema.isInvisible) {
            columnSchema.setData_type(removedColumn.data_type)
            columnSchema.setPrecision(removedColumn.precision)
            columnSchema.setScale(removedColumn.scale)
          }
        }
      }
      metastore
        .revertTableSchema(carbonTable.getCarbonTableIdentifier,
          thriftTable, carbonTable.getAbsoluteTableIdentifier.getTablePath)(sparkSession)
    }
  }

}


text:
package org.apache.geode.management.internal.configuration.utils;

import javax.xml.XMLConstants;

/**
 *
 * @since GemFire 8.1
 */
public class XmlConstants {

  /**
   * Standard prefix for {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI}
   * (http://www.w3.org/2001/XMLSchema-instance) namespace.
   *
   * @since GemFire 8.1
   */
  public static final String W3C_XML_SCHEMA_INSTANCE_PREFIX = "xsi";

  /**
   * Schema location attribute local name, "schemaLocation", in
   * {@link XMLConstants#W3C_XML_SCHEMA_INSTANCE_NS_URI} (http://www.w3.org/2001/XMLSchema-instance)
   * namespace.
   *
   * @since GemFire 8.1
   */
  public static final String W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION = "schemaLocation";

  /**
   * Default prefix. Effectively no prefix.
   *
   * @since GemFire 8.1
   */
  public static final String DEFAULT_PREFIX = "";

  private XmlConstants() {
    // statics only
  }
}


text:
#Region "Microsoft.VisualBasic::582e624bf902fe455109a672ac04d71b, src\metadb\Massbank\Public\lipidMAPS\MapsHelper.vb"

    ' Author:
    '
    '       xieguigang (gg.xie@bionovogene.com, BioNovoGene Co., LTD.)
    '
    ' Copyright (c) 2018 gg.xie@bionovogene.com, BioNovoGene Co., LTD.
    '
    '
    ' MIT License
    '
    '
    ' Permission is hereby granted, free of charge, to any person obtaining a copy
    ' of this software and associated documentation files (the "Software"), to deal
    ' in the Software without restriction, including without limitation the rights
    ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    ' copies of the Software, and to permit persons to whom the Software is
    ' furnished to do so, subject to the following conditions:
    '
    ' The above copyright notice and this permission notice shall be included in all
    ' copies or substantial portions of the Software.
    '
    ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    ' SOFTWARE.

    ' /********************************************************************************/

    ' Summaries:

    '     Module MapsHelper
    '
    '         Function: AssertMap, CreateMaps, Tuple
    '
    '
    ' /********************************************************************************/

#End Region

Imports System.Reflection
Imports System.Runtime.CompilerServices
Imports BioNovoGene.BioDeep.Chemoinformatics.SDF
Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel
Imports Microsoft.VisualBasic.Emit.Delegates
Imports Microsoft.VisualBasic.Language

Namespace LipidMaps

    Public Module MapsHelper

        Public Const chebi$ = NameOf(chebi)
        Public Const hmdb$ = NameOf(hmdb)
        Public Const inchi$ = NameOf(inchi)
        Public Const inchi_key$ = NameOf(inchi_key)
        Public Const kegg$ = NameOf(kegg)
        Public Const lipidbank$ = NameOf(lipidbank)
        Public Const lipidmap$ = NameOf(lipidmap)
        Public Const pubchem$ = NameOf(pubchem)

        <Extension>
        Public Function AssertMap(maps As NamedValue(Of Dictionary(Of String, MetaData()))(), xref As Dictionary(Of String, String)) As String
            For Each map In maps
                With map
                    If xref.ContainsKey(.Name) Then
                        Dim id$ = xref(.Name)
                        If .Value.ContainsKey(id) Then
                            Return .Value(id) _
                                .Select(Function(x) x.LM_ID) _
                                .Distinct _
                                .JoinBy(", ")
                        End If
                    End If
                End With
            Next

            Return Nothing
        End Function

        <Extension> Public Function CreateMaps(lipidMaps As IEnumerable(Of SDF)) As NamedValue(Of Dictionary(Of String, MetaData()))()
            Dim out As New List(Of NamedValue(Of Dictionary(Of String, MetaData())))
            Dim schema = DataFramework.Schema(Of MetaData)(PropertyAccess.Readable, True)
            Dim tuple As Dictionary(Of String, MetaData())

            With lipidMaps _
                .Where(Function(sdf) Not sdf.MetaData Is Nothing) _
                .Select(Function(sdf) MetaData.Data(sdf)) _
                .ToArray

                Dim map = Sub(field$, mapName$)
                              tuple = .Tuple(schema(field))
                              out += New NamedValue(Of Dictionary(Of String, MetaData())) With {
                                  .Name = mapName,
                                  .Value = tuple
                              }
                          End Sub

                Call map(NameOf(MetaData.CHEBI_ID), chebi)
                Call map(NameOf(MetaData.HMDBID), hmdb)
                Call map(NameOf(MetaData.INCHI), inchi)
                Call map(NameOf(MetaData.INCHI_KEY), inchi_key)
                Call map(NameOf(MetaData.KEGG_ID), kegg)
                Call map(NameOf(MetaData.LIPIDBANK_ID), lipidbank)
                Call map(NameOf(MetaData.LM_ID), lipidmap)
                Call map(NameOf(MetaData.PUBCHEM_CID), pubchem)
            End With

            Return out
        End Function

        <Extension>
        Private Function Tuple(lipidmaps As MetaData(), field As PropertyInfo) As Dictionary(Of String, MetaData())
            Dim read = field.PropertyGet(Of MetaData, String)
            Dim group = lipidmaps _
                .Select(Function(m) (key:=read(m), m)) _
                .Where(Function(m) Not m.key.StringEmpty) _
                .GroupBy(Function(t) t.key)
            Dim table = group.ToDictionary(
                Function(g) g.Key,
                Function(list)
                    Return list _
                        .Select(Function(t) t.Item2) _
                        .ToArray
                End Function)
            Return table
        End Function
    End Module
End Namespace


text:
package cache_test

import (
	"testing"

	"github.com/google/webpackager/resource/cache"
)

func TestBoundedCache_LRU(t *testing.T) {
	foo := makeResource("https://example.com/foo.html")
	bar := makeResource("https://example.com/bar.html")
	bc := cache.NewBoundedInMemoryCache(1)

	reqFoo := makeRequest("https://example.com/foo.html")
	reqBar := makeRequest("https://example.com/bar.html")

	// foo is not present in the initial state.
	{
		got, err := bc.Lookup(reqFoo)
		if err != nil {
			t.Errorf("bc.Lookup(reqFoo) = error(%q), want success", err)
		}
		if got != nil {
			t.Errorf("bc.Lookup(reqFoo) = %v, want %v", got, nil)
		}
	}

	if err := bc.Store(foo); err != nil {
		t.Errorf("bc.Store(foo) = error(%q), want success", err)
	}

	// foo is now present.
	{
		got, err := bc.Lookup(reqFoo)
		if err != nil {
			t.Errorf("bc.Lookup(reqFoo) = error(%q), want success", err)
		}
		if got != foo {
			t.Errorf("bc.Lookup(reqFoo) = %v, want %v", got, foo)
		}
	}
	// bar is still not present.
	{
		got, err := bc.Lookup(reqBar)
		if err != nil {
			t.Errorf("bc.Lookup(reqBar) = error(%q), want success", err)
		}
		if got != nil {
			t.Errorf("bc.Lookup(reqBar) = %v, want %v", got, nil)
		}
	}

	if err := bc.Store(bar); err != nil {
		t.Errorf("bc.Store(bar) = error(%q), want success", err)
	}

	// bar is now present.
	{
		got, err := bc.Lookup(reqBar)
		if err != nil {
			t.Errorf("bc.Lookup(reqBar) = error(%q), want success", err)
		}
		if got != bar {
			t.Errorf("bc.Lookup(reqBar) = %v, want %v", got, bar)
		}
	}
	// foo is no longer present.
	{
		got, err := bc.Lookup(reqFoo)
		if err != nil {
			t.Errorf("bc.Lookup(reqFoo) = error(%q), want success", err)
		}
		if got != nil {
			t.Errorf("bc.Lookup(reqFoo) = %v, want %v", got, nil)
		}
	}
}

func TestBoundedCache_2Q(t *testing.T) {
	foo := makeResource("https://example.com/foo.html")
	bar := makeResource("https://example.com/bar.html")
	baz := makeResource("https://example.com/baz.html")
	bc := cache.NewBoundedInMemoryCache(2)

	reqFoo := makeRequest("https://example.com/foo.html")
	reqBar := makeRequest("https://example.com/bar.html")
	reqBaz := makeRequest("https://example.com/baz.html")

	if err := bc.Store(foo); err != nil {
		t.Errorf("bc.Store(foo) = error(%q), want success", err)
	}
	if err := bc.Store(bar); err != nil {
		t.Errorf("bc.Store(bar) = error(%q), want success", err)
	}
	if err := bc.Store(baz); err != nil {
		t.Errorf("bc.Store(baz) = error(%q), want success", err)
	}

	// foo is not present.
	{
		got, err := bc.Lookup(reqFoo)
		if err != nil {
			t.Errorf("bc.Lookup(reqFoo) = error(%q), want success", err)
		}
		if got != nil {
			t.Errorf("bc.Lookup(reqFoo) = %v, want %v", got, nil)
		}
	}
	// bar is present.
	{
		got, err := bc.Lookup(reqBar)
		if err != nil {
			t.Errorf("bc.Lookup(reqBar) = error(%q), want success", err)
		}
		if got != bar {
			t.Errorf("bc.Lookup(reqBar) = %v, want %v", got, bar)
		}
	}
	// baz is present.
	{
		got, err := bc.Lookup(reqBaz)
		if err != nil {
			t.Errorf("bc.Lookup(reqBaz) = error(%q), want success", err)
		}
		if got != baz {
			t.Errorf("bc.Lookup(reqBaz) = %v, want %v", got, baz)
		}
	}
}


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>SVISlide.SlideDeformDirection</title>
<meta name="date" content="2015-03-27">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

com.github.sviengine.slide

Interface SVISlide.SlideDeformDirection

Enclosing class:

SVISlide

public static interface SVISlide.SlideDeformDirection

slide deformation direction type

Field Summary

Fields

Modifier and Type
Field and Description

static int
DEFORM_HORIZONTAL

static int
DEFORM_HORIZONTAL_REVERSE

static int
DEFORM_VERTICAL

static int
DEFORM_VERTICAL_REVERSE

Field Detail

DEFORM_HORIZONTAL

static final int DEFORM_HORIZONTAL

See Also:

Constant Field Values

DEFORM_VERTICAL

static final int DEFORM_VERTICAL

See Also:

Constant Field Values

DEFORM_HORIZONTAL_REVERSE

static final int DEFORM_HORIZONTAL_REVERSE

See Also:

Constant Field Values

DEFORM_VERTICAL_REVERSE

static final int DEFORM_VERTICAL_REVERSE

See Also:

Constant Field Values

Skip navigation links

Overview

Package

Class

Use

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method


text:
====================================================
dateparser -- python parser for human readable dates
====================================================

.. image:: https://img.shields.io/pypi/dm/dateparser
   :target: https://pypi.python.org/pypi/dateparser
   :alt: pypi downloads

.. image:: https://img.shields.io/pypi/v/dateparser.svg
   :target: https://pypi.python.org/pypi/dateparser
   :alt: pypi version

.. image:: https://codecov.io/gh/scrapinghub/dateparser/branch/master/graph/badge.svg
   :target: https://codecov.io/gh/scrapinghub/dateparser
   :alt: Code Coverage

.. image:: https://github.com/scrapinghub/dateparser/workflows/Build/badge.svg
   :target: https://github.com/scrapinghub/dateparser/actions
   :alt: Github Build

.. image:: https://readthedocs.org/projects/dateparser/badge/?version=latest
   :target: http://dateparser.readthedocs.org/en/latest/?badge=latest
   :alt: Documentation Status

`dateparser` provides modules to easily parse localized dates in almost
any string formats commonly found on web pages.

Documentation
=============

This documentation is built automatically and can be found on
`Read the Docs <https://dateparser.readthedocs.org/en/latest/>`_.

.. include:: introduction.rst

Indices and tables
==================

Contents:

.. toctree::
   :maxdepth: 2

   introduction
   installation
   usage
   settings
   custom_language_detection
   supported_locales
   contributing
   modules
   authors
   history

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`


text:
package org.apache.hadoop.hdfs.protocolPB;

import com.google.common.collect.Lists;
import com.google.protobuf.ByteString;
import com.google.protobuf.CodedInputStream;
import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.protocol.DatanodeID;
import org.apache.hadoop.hdfs.protocol.DatanodeInfo;
import org.apache.hadoop.hdfs.protocol.DatanodeLocalInfo;
import org.apache.hadoop.hdfs.protocol.ExtendedBlock;
import org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.ShortCircuitShmIdProto;
import org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.ShortCircuitShmSlotProto;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeIDProto;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeInfoProto;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.DatanodeLocalInfoProto;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.ExtendedBlockProto;
import org.apache.hadoop.hdfs.protocol.proto.HdfsProtos.StorageTypeProto;
import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.ShmId;
import org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId;
import org.apache.hadoop.hdfs.util.ExactSizeInputStream;
import org.apache.hadoop.security.proto.SecurityProtos.TokenProto;
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.util.DataChecksum;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Utilities for converting protobuf classes to and from implementation classes
 * and other helper utilities to help in dealing with protobuf.
 *
 * Note that when converting from an internal type to protobuf type, the
 * converter never return null for protobuf type. The check for internal type
 * being null must be done before calling the convert() method.
 */
public class PBHelperClient {
  private PBHelperClient() {
    /** Hidden constructor */
  }

  public static ByteString getByteString(byte[] bytes) {
    return ByteString.copyFrom(bytes);
  }

  public static ShmId convert(ShortCircuitShmIdProto shmId) {
    return new ShmId(shmId.getHi(), shmId.getLo());
  }

  public static DataChecksum.Type convert(HdfsProtos.ChecksumTypeProto type) {
    return DataChecksum.Type.valueOf(type.getNumber());
  }

  public static HdfsProtos.ChecksumTypeProto convert(DataChecksum.Type type) {
    return HdfsProtos.ChecksumTypeProto.valueOf(type.id);
  }

  public static ExtendedBlockProto convert(final ExtendedBlock b) {
    if (b == null) return null;
    return ExtendedBlockProto.newBuilder().
      setPoolId(b.getBlockPoolId()).
      setBlockId(b.getBlockId()).
      setNumBytes(b.getNumBytes()).
      setGenerationStamp(b.getGenerationStamp()).
      build();
  }

  public static TokenProto convert(Token<?> tok) {
    return TokenProto.newBuilder().
      setIdentifier(ByteString.copyFrom(tok.getIdentifier())).
      setPassword(ByteString.copyFrom(tok.getPassword())).
      setKind(tok.getKind().toString()).
      setService(tok.getService().toString()).build();
  }

  public static ShortCircuitShmIdProto convert(ShmId shmId) {
    return ShortCircuitShmIdProto.newBuilder().
      setHi(shmId.getHi()).
      setLo(shmId.getLo()).
      build();

  }

  public static ShortCircuitShmSlotProto convert(SlotId slotId) {
    return ShortCircuitShmSlotProto.newBuilder().
      setShmId(convert(slotId.getShmId())).
      setSlotIdx(slotId.getSlotIdx()).
      build();
  }

  public static DatanodeIDProto convert(DatanodeID dn) {
    // For wire compatibility with older versions we transmit the StorageID
    // which is the same as the DatanodeUuid. Since StorageID is a required
    // field we pass the empty string if the DatanodeUuid is not yet known.
    return DatanodeIDProto.newBuilder()
      .setIpAddr(dn.getIpAddr())
      .setHostName(dn.getHostName())
      .setXferPort(dn.getXferPort())
      .setDatanodeUuid(dn.getDatanodeUuid() != null ? dn.getDatanodeUuid() : "")
      .setInfoPort(dn.getInfoPort())
      .setInfoSecurePort(dn.getInfoSecurePort())
      .setIpcPort(dn.getIpcPort()).build();
  }

  public static DatanodeInfoProto.AdminState convert(
    final DatanodeInfo.AdminStates inAs) {
    switch (inAs) {
      case NORMAL: return  DatanodeInfoProto.AdminState.NORMAL;
      case DECOMMISSION_INPROGRESS:
        return DatanodeInfoProto.AdminState.DECOMMISSION_INPROGRESS;
      case DECOMMISSIONED: return DatanodeInfoProto.AdminState.DECOMMISSIONED;
      default: return DatanodeInfoProto.AdminState.NORMAL;
    }
  }

  public static DatanodeInfoProto convert(DatanodeInfo info) {
    DatanodeInfoProto.Builder builder = DatanodeInfoProto.newBuilder();
    if (info.getNetworkLocation() != null) {
      builder.setLocation(info.getNetworkLocation());
    }
    builder
      .setId(convert((DatanodeID) info))
      .setCapacity(info.getCapacity())
      .setDfsUsed(info.getDfsUsed())
      .setRemaining(info.getRemaining())
      .setBlockPoolUsed(info.getBlockPoolUsed())
      .setCacheCapacity(info.getCacheCapacity())
      .setCacheUsed(info.getCacheUsed())
      .setLastUpdate(info.getLastUpdate())
      .setLastUpdateMonotonic(info.getLastUpdateMonotonic())
      .setXceiverCount(info.getXceiverCount())
      .setAdminState(convert(info.getAdminState()))
      .build();
    return builder.build();
  }

  public static List<? extends HdfsProtos.DatanodeInfoProto> convert(
    DatanodeInfo[] dnInfos) {
    return convert(dnInfos, 0);
  }

  /**
   * Copy from {@code dnInfos} to a target of list of same size starting at
   * {@code startIdx}.
   */
  public static List<? extends HdfsProtos.DatanodeInfoProto> convert(
    DatanodeInfo[] dnInfos, int startIdx) {
    if (dnInfos == null)
      return null;
    ArrayList<HdfsProtos.DatanodeInfoProto> protos = Lists
      .newArrayListWithCapacity(dnInfos.length);
    for (int i = startIdx; i < dnInfos.length; i++) {
      protos.add(convert(dnInfos[i]));
    }
    return protos;
  }

  public static List<Boolean> convert(boolean[] targetPinnings, int idx) {
    List<Boolean> pinnings = new ArrayList<>();
    if (targetPinnings == null) {
      pinnings.add(Boolean.FALSE);
    } else {
      for (; idx < targetPinnings.length; ++idx) {
        pinnings.add(targetPinnings[idx]);
      }
    }
    return pinnings;
  }

  public static ExtendedBlock convert(ExtendedBlockProto eb) {
    if (eb == null) return null;
    return new ExtendedBlock( eb.getPoolId(), eb.getBlockId(), eb.getNumBytes(),
        eb.getGenerationStamp());
  }

  public static DatanodeLocalInfo convert(DatanodeLocalInfoProto proto) {
    return new DatanodeLocalInfo(proto.getSoftwareVersion(),
        proto.getConfigVersion(), proto.getUptime());
  }

  static public DatanodeInfoProto convertDatanodeInfo(DatanodeInfo di) {
    if (di == null) return null;
    return convert(di);
  }

  public static StorageTypeProto convertStorageType(StorageType type) {
    switch(type) {
      case DISK:
        return StorageTypeProto.DISK;
      case SSD:
        return StorageTypeProto.SSD;
      case ARCHIVE:
        return StorageTypeProto.ARCHIVE;
      case RAM_DISK:
        return StorageTypeProto.RAM_DISK;
      default:
        throw new IllegalStateException(
          "BUG: StorageType not found, type=" + type);
    }
  }

  public static StorageType convertStorageType(StorageTypeProto type) {
    switch(type) {
      case DISK:
        return StorageType.DISK;
      case SSD:
        return StorageType.SSD;
      case ARCHIVE:
        return StorageType.ARCHIVE;
      case RAM_DISK:
        return StorageType.RAM_DISK;
      default:
        throw new IllegalStateException(
          "BUG: StorageTypeProto not found, type=" + type);
    }
  }

  public static List<StorageTypeProto> convertStorageTypes(
    StorageType[] types) {
    return convertStorageTypes(types, 0);
  }

  public static List<StorageTypeProto> convertStorageTypes(
    StorageType[] types, int startIdx) {
    if (types == null) {
      return null;
    }
    final List<StorageTypeProto> protos = new ArrayList<>(
      types.length);
    for (int i = startIdx; i < types.length; ++i) {
      protos.add(PBHelperClient.convertStorageType(types[i]));
    }
    return protos;
  }

  public static InputStream vintPrefixed(final InputStream input)
    throws IOException {
    final int firstByte = input.read();
    if (firstByte == -1) {
      throw new EOFException("Premature EOF: no length prefix available");
    }

    int size = CodedInputStream.readRawVarint32(firstByte, input);
    assert size >= 0;
    return new ExactSizeInputStream(input, size);
  }
}


text:
package org.osgi.test.cases.log.stream.junit;

import static org.assertj.core.api.Assertions.assertThat;
import static org.osgi.test.assertj.promise.PromiseAssert.assertThat;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.LongUnaryOperator;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogService;
import org.osgi.service.log.stream.LogStreamProvider;
import org.osgi.test.common.annotation.InjectBundleContext;
import org.osgi.test.common.annotation.InjectService;
import org.osgi.test.junit5.context.BundleContextExtension;
import org.osgi.test.junit5.service.ServiceExtension;
import org.osgi.test.support.tracker.Tracker;
import org.osgi.util.promise.Promise;
import org.osgi.util.pushstream.PushStream;
import org.osgi.util.tracker.ServiceTracker;

@ExtendWith(BundleContextExtension.class)
@ExtendWith(ServiceExtension.class)
public class LogStreamTest {
	private static int									SLEEP	= 1000;

	@InjectBundleContext
	BundleContext										context;
	@InjectService
	LogService											logService;
	ServiceTracker<LogStreamProvider,LogStreamProvider>	logStreamProviderTracker;
	LogStreamProvider									logStreamProvider;

	String												testMethodName;
	@BeforeEach
	public void setUp(TestInfo info) throws Exception {
		testMethodName = info.getTestMethod().map(Method::getName).get();
		logStreamProviderTracker = new ServiceTracker<LogStreamProvider,LogStreamProvider>(
				context, LogStreamProvider.class, null);
		logStreamProviderTracker.open();

		// logService = Tracker.waitForService(logServiceTracker, SLEEP);
		logStreamProvider = Tracker.waitForService(logStreamProviderTracker,
				SLEEP);
	}

	@AfterEach
	public void tearDown() throws Exception {
		logStreamProviderTracker.close();
	}

	@Test
	public void testLogStreamIsBuffered() throws Exception {
		LongUnaryOperator backPressure = i -> 100L;
		for (int i = 0; i < 5; i++) {
			logService.getLogger(testMethodName)
					.audit(String.valueOf(i + 1));
		}

		CountDownLatch latch = new CountDownLatch(30);

		AtomicLong lastEventTime = new AtomicLong();
		try (PushStream<LogEntry> stream = logStreamProvider
				.createStream(LogStreamProvider.Options.HISTORY)) {

			for (int i = 5; i < 10; i++) {
				logService.getLogger(testMethodName)
						.audit(String.valueOf(i + 1));
			}

			long startTime = System.nanoTime();
			stream.adjustBackPressure(backPressure)
					.filter(l -> testMethodName
							.equals(l.getLoggerName()))
					.forEach(l -> {
						System.out.printf("%s[%s]: %s%n", l.getLoggerName(),
								l.getSequence(), l.getMessage());
						latch.countDown();
						lastEventTime.set(System.nanoTime());
					});

			for (int i = 10; i < 30; i++) {
				logService.getLogger(testMethodName)
						.audit(String.valueOf(i + 1));
			}

			assertThat(latch.getCount())
					.as("Latch is not zero indicating we blocked.")
					.isPositive();

			latch.await(4, TimeUnit.SECONDS);
			assertThat(latch.getCount()).as("Did not get full history")
					.isZero();

			long timeForConsumer = TimeUnit.NANOSECONDS
					.toMillis(lastEventTime.get() - startTime);
			// making sure the timeForConsumer is greater than 2900
			// We fire 30 events but there can be jitter on the delay
			// so we allow a small margin
			assertThat(timeForConsumer)
					.as("Did not take long enough: %s", timeForConsumer)
					.isGreaterThan(2900);
		}
	}

	@Test
	public void testLogWithHistory() throws Exception {
		for (int i = 0; i < 50; i++) {
			logService.getLogger(testMethodName)
					.audit(String.valueOf(i + 1));
		}

		CountDownLatch latch = new CountDownLatch(150);
		try (PushStream<LogEntry> stream = logStreamProvider
				.createStream(LogStreamProvider.Options.HISTORY)) {

			for (int i = 50; i < 100; i++) {
				logService.getLogger(testMethodName)
						.audit(String.valueOf(i + 1));
			}

			stream.filter(
					l -> testMethodName.equals(l.getLoggerName()))
					.forEach(l -> {
						System.out.printf("%s[%s]: %s%n", l.getLoggerName(),
								l.getSequence(), l.getMessage());
						latch.countDown();
					});

			for (int i = 100; i < 150; i++) {
				logService.getLogger(testMethodName)
						.audit(String.valueOf(i + 1));
			}

			latch.await(SLEEP, TimeUnit.MILLISECONDS);
			assertThat(latch.getCount()).as("Did not get full history")
					.isZero();
		}
	}

	@Test
	public void testStreamSize() throws Exception {
		Set<String> messageSet = new HashSet<String>();
		messageSet.add("test1");
		messageSet.add("test2");
		messageSet.add("test3");

		CountDownLatch latch = new CountDownLatch(messageSet.size());
		try (PushStream<LogEntry> ps = logStreamProvider.createStream()) {
			ps.filter(l -> testMethodName.equals(l.getLoggerName()))
					.forEach(l -> {
						System.out.printf("%s[%s]: %s%n", l.getLoggerName(),
								l.getSequence(), l.getMessage());
						messageSet.remove(l.getMessage());
						latch.countDown();
					});

			logService.getLogger(testMethodName).audit("test1");
			logService.getLogger(testMethodName).audit("test2");
			logService.getLogger(testMethodName).audit("test3");

			latch.await(SLEEP, TimeUnit.MILLISECONDS);
		}
		assertThat(messageSet).as("Some number of messages, >0 not in stream")
				.isEmpty();
	}

	@Test
	public void testCloseOnUnget() throws Exception {
		Promise<Long> p = null;
		CountDownLatch latch = new CountDownLatch(1);
		PushStream<LogEntry> stream = logStreamProvider.createStream();
		try {
			p = stream.filter(
					l -> testMethodName.equals(l.getLoggerName()))
					.filter(l -> l.getMessage().startsWith("count"))
					.count();

			logService.getLogger(testMethodName).audit("count1");
			logService.getLogger(testMethodName).audit("count2");
			logService.getLogger(testMethodName).audit("nocount1");
			logService.getLogger(testMethodName).audit("count3");
			logService.getLogger(testMethodName).audit("nocount2");

			latch.await(SLEEP, TimeUnit.MILLISECONDS);
		} finally {
			// ungetService closes the stream
			logStreamProviderTracker.close();
		}
		assertThat(p).as("Incorrect count")
				.resolvesWithin(5L, TimeUnit.SECONDS)
				.hasValue(3L);
	}

}