text:
// Copyright (c) 2012 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.
//
// Notes about usage of this object by VideoCaptureImplManager.
//
// VideoCaptureImplManager access this object by using a Unretained()
// binding and tasks on the IO thread. It is then important that
// VideoCaptureImpl never post task to itself. All operations must be
// synchronous.

#include "content/renderer/media/video_capture_impl.h"

#include <stddef.h>
#include <utility>

#include "base/bind.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
#include "content/child/child_process.h"
#include "content/public/child/child_thread.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/limits.h"
#include "media/base/video_frame.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/service_manager/public/cpp/interface_provider.h"

namespace content {

// A holder of a memory-backed buffer and accessors to it.
class VideoCaptureImpl::ClientBuffer
    : public base::RefCountedThreadSafe<ClientBuffer> {
 public:
  ClientBuffer(std::unique_ptr<base::SharedMemory> buffer, size_t buffer_size)
      : buffer_(std::move(buffer)), buffer_size_(buffer_size) {}

  base::SharedMemory* buffer() const { return buffer_.get(); }
  size_t buffer_size() const { return buffer_size_; }

 private:
  friend class base::RefCountedThreadSafe<ClientBuffer>;

  virtual ~ClientBuffer() {}

  const std::unique_ptr<base::SharedMemory> buffer_;
  const size_t buffer_size_;

  DISALLOW_COPY_AND_ASSIGN(ClientBuffer);
};

// Information about a video capture client of ours.
struct VideoCaptureImpl::ClientInfo {
  ClientInfo() = default;

  ClientInfo(const ClientInfo& other) = default;

  ~ClientInfo() = default;

  media::VideoCaptureParams params;

  VideoCaptureStateUpdateCB state_update_cb;

  VideoCaptureDeliverFrameCB deliver_frame_cb;
};

VideoCaptureImpl::VideoCaptureImpl(media::VideoCaptureSessionId session_id)
    : device_id_(session_id),
      session_id_(session_id),
      video_capture_host_for_testing_(nullptr),
      observer_binding_(this),
      state_(VIDEO_CAPTURE_STATE_STOPPED),
      weak_factory_(this) {
  io_thread_checker_.DetachFromThread();

  if (ChildThread::Get()) {  // This will be null in unit tests.
    mojom::VideoCaptureHostPtr temp_video_capture_host;
    ChildThread::Get()->GetRemoteInterfaces()->GetInterface(
        mojo::MakeRequest(&temp_video_capture_host));
    video_capture_host_info_ = temp_video_capture_host.PassInterface();
  }
}

VideoCaptureImpl::~VideoCaptureImpl() {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  if (state_ == VIDEO_CAPTURE_STATE_STARTED && GetVideoCaptureHost())
    GetVideoCaptureHost()->Stop(device_id_);
}

void VideoCaptureImpl::SuspendCapture(bool suspend) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  if (suspend)
    GetVideoCaptureHost()->Pause(device_id_);
  else
    GetVideoCaptureHost()->Resume(device_id_, session_id_, params_);
}

void VideoCaptureImpl::StartCapture(
    int client_id,
    const media::VideoCaptureParams& params,
    const VideoCaptureStateUpdateCB& state_update_cb,
    const VideoCaptureDeliverFrameCB& deliver_frame_cb) {
  DVLOG(1) << __func__ << " |device_id_| = " << device_id_;
  DCHECK(io_thread_checker_.CalledOnValidThread());
  ClientInfo client_info;
  client_info.params = params;
  client_info.state_update_cb = state_update_cb;
  client_info.deliver_frame_cb = deliver_frame_cb;

  if (state_ == VIDEO_CAPTURE_STATE_ERROR) {
    state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR);
  } else if (clients_pending_on_restart_.count(client_id) ||
             clients_.count(client_id)) {
    DLOG(FATAL) << __func__ << " This client has already started.";
  } else {
    // Note: |state_| might not be started at this point. But we tell
    // client that we have started.
    state_update_cb.Run(VIDEO_CAPTURE_STATE_STARTED);
    if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
      clients_[client_id] = client_info;
      // TODO(sheu): Allowing resolution change will require that all
      // outstanding clients of a capture session support resolution change.
      DCHECK_EQ(params_.resolution_change_policy,
                params.resolution_change_policy);
    } else if (state_ == VIDEO_CAPTURE_STATE_STOPPING) {
      clients_pending_on_restart_[client_id] = client_info;
      DVLOG(1) << __func__ << " Got new resolution while stopping: "
               << params.requested_format.frame_size.ToString();
    } else {
      clients_[client_id] = client_info;
      if (state_ == VIDEO_CAPTURE_STATE_STARTED)
        return;
      params_ = params;
      params_.requested_format.frame_rate =
          std::min(params_.requested_format.frame_rate,
                   static_cast<float>(media::limits::kMaxFramesPerSecond));

      DVLOG(1) << "StartCapture: starting with first resolution "
               << params_.requested_format.frame_size.ToString();
      StartCaptureInternal();
    }
  }
}

void VideoCaptureImpl::StopCapture(int client_id) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  // A client ID can be in only one client list.
  // If this ID is in any client list, we can just remove it from
  // that client list and don't have to run the other following RemoveClient().
  if (!RemoveClient(client_id, &clients_pending_on_restart_)) {
    RemoveClient(client_id, &clients_);
  }

  if (!clients_.empty())
    return;
  DVLOG(1) << "StopCapture: No more client, stopping ...";
  StopDevice();
  client_buffers_.clear();
  weak_factory_.InvalidateWeakPtrs();
}

void VideoCaptureImpl::RequestRefreshFrame() {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  GetVideoCaptureHost()->RequestRefreshFrame(device_id_);
}

void VideoCaptureImpl::GetDeviceSupportedFormats(
    const VideoCaptureDeviceFormatsCB& callback) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  GetVideoCaptureHost()->GetDeviceSupportedFormats(
      device_id_, session_id_,
      base::Bind(&VideoCaptureImpl::OnDeviceSupportedFormats,
                 weak_factory_.GetWeakPtr(), callback));
}

void VideoCaptureImpl::GetDeviceFormatsInUse(
    const VideoCaptureDeviceFormatsCB& callback) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  GetVideoCaptureHost()->GetDeviceFormatsInUse(
      device_id_, session_id_,
      base::Bind(&VideoCaptureImpl::OnDeviceFormatsInUse,
                 weak_factory_.GetWeakPtr(), callback));
}

void VideoCaptureImpl::OnStateChanged(mojom::VideoCaptureState state) {
  DVLOG(1) << __func__ << " state: " << state;
  DCHECK(io_thread_checker_.CalledOnValidThread());

  switch (state) {
    case mojom::VideoCaptureState::STARTED:
      // Capture has started in the browser process. Since we have already
      // told all clients that we have started there's nothing to do.
      break;
    case mojom::VideoCaptureState::STOPPED:
      state_ = VIDEO_CAPTURE_STATE_STOPPED;
      client_buffers_.clear();
      weak_factory_.InvalidateWeakPtrs();
      if (!clients_.empty() || !clients_pending_on_restart_.empty())
        RestartCapture();
      break;
    case mojom::VideoCaptureState::PAUSED:
      for (const auto& client : clients_)
        client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_PAUSED);
      break;
    case mojom::VideoCaptureState::RESUMED:
      for (const auto& client : clients_)
        client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_RESUMED);
      break;
    case mojom::VideoCaptureState::FAILED:
      for (const auto& client : clients_)
        client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_ERROR);
      clients_.clear();
      state_ = VIDEO_CAPTURE_STATE_ERROR;
      break;
    case mojom::VideoCaptureState::ENDED:
      // We'll only notify the client that the stream has stopped.
      for (const auto& client : clients_)
        client.second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
      clients_.clear();
      state_ = VIDEO_CAPTURE_STATE_ENDED;
      break;
  }
}

void VideoCaptureImpl::OnBufferCreated(int32_t buffer_id,
                                       mojo::ScopedSharedBufferHandle handle) {
  DVLOG(1) << __func__ << " buffer_id: " << buffer_id;
  DCHECK(io_thread_checker_.CalledOnValidThread());
  DCHECK(handle.is_valid());

  if (state_ != VIDEO_CAPTURE_STATE_STARTED)
    return;

  base::SharedMemoryHandle memory_handle;
  size_t memory_size = 0;
  bool read_only_flag = false;

  const MojoResult result = mojo::UnwrapSharedMemoryHandle(
      std::move(handle), &memory_handle, &memory_size, &read_only_flag);
  DCHECK_EQ(MOJO_RESULT_OK, result);
  DCHECK_GT(memory_size, 0u);

  std::unique_ptr<base::SharedMemory> shm(
      new base::SharedMemory(memory_handle, true /* read_only */));
  if (!shm->Map(memory_size)) {
    DLOG(ERROR) << "OnBufferCreated: Map failed.";
    return;
  }
  const bool inserted =
      client_buffers_
          .insert(std::make_pair(buffer_id,
                                 new ClientBuffer(std::move(shm), memory_size)))
          .second;
  DCHECK(inserted);
}

void VideoCaptureImpl::OnBufferReady(int32_t buffer_id,
                                     media::mojom::VideoFrameInfoPtr info) {
  DVLOG(1) << __func__ << " buffer_id: " << buffer_id;
  DCHECK(io_thread_checker_.CalledOnValidThread());

  bool consume_buffer = state_ == VIDEO_CAPTURE_STATE_STARTED;
  if ((info->pixel_format != media::PIXEL_FORMAT_I420 &&
       info->pixel_format != media::PIXEL_FORMAT_Y16) ||
      info->storage_type != media::PIXEL_STORAGE_CPU) {
    consume_buffer = false;
    LOG(DFATAL) << "Wrong pixel format or storage, got pixel format:"
                << VideoPixelFormatToString(info->pixel_format)
                << ", storage:" << info->storage_type;
  }
  if (!consume_buffer) {
    GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0);
    return;
  }

  base::TimeTicks reference_time;
  media::VideoFrameMetadata frame_metadata;
  frame_metadata.MergeInternalValuesFrom(*info->metadata);
  const bool success = frame_metadata.GetTimeTicks(
      media::VideoFrameMetadata::REFERENCE_TIME, &reference_time);
  DCHECK(success);

  if (first_frame_ref_time_.is_null())
    first_frame_ref_time_ = reference_time;

  // If the timestamp is not prepared, we use reference time to make a rough
  // estimate. e.g. ThreadSafeCaptureOracle::DidCaptureFrame().
  // TODO(miu): Fix upstream capturers to always set timestamp and reference
  // time. See http://crbug/618407/ for tracking.
  if (info->timestamp.is_zero())
    info->timestamp = reference_time - first_frame_ref_time_;

  // TODO(qiangchen): Change the metric name to "reference_time" and
  // "timestamp", so that we have consistent naming everywhere.
  // Used by chrome/browser/extension/api/cast_streaming/performance_test.cc
  TRACE_EVENT_INSTANT2("cast_perf_test", "OnBufferReceived",
                       TRACE_EVENT_SCOPE_THREAD, "timestamp",
                       (reference_time - base::TimeTicks()).InMicroseconds(),
                       "time_delta", info->timestamp.InMicroseconds());

  const auto& iter = client_buffers_.find(buffer_id);
  DCHECK(iter != client_buffers_.end());
  const scoped_refptr<ClientBuffer> buffer = iter->second;
  scoped_refptr<media::VideoFrame> frame =
      media::VideoFrame::WrapExternalSharedMemory(
          static_cast<media::VideoPixelFormat>(info->pixel_format),
          info->coded_size, info->visible_rect, info->visible_rect.size(),
          reinterpret_cast<uint8_t*>(buffer->buffer()->memory()),
          buffer->buffer_size(), buffer->buffer()->handle(),
          0 /* shared_memory_offset */, info->timestamp);
  if (!frame) {
    GetVideoCaptureHost()->ReleaseBuffer(device_id_, buffer_id, -1.0);
    return;
  }

  BufferFinishedCallback buffer_finished_callback = media::BindToCurrentLoop(
      base::Bind(&VideoCaptureImpl::OnClientBufferFinished,
                 weak_factory_.GetWeakPtr(), buffer_id, buffer));
  frame->AddDestructionObserver(
      base::Bind(&VideoCaptureImpl::DidFinishConsumingFrame, frame->metadata(),
                 buffer_finished_callback));

  frame->metadata()->MergeInternalValuesFrom(*info->metadata);

  // TODO(qiangchen): Dive into the full code path to let frame metadata hold
  // reference time rather than using an extra parameter.
  for (const auto& client : clients_)
    client.second.deliver_frame_cb.Run(frame, reference_time);
}

void VideoCaptureImpl::OnBufferDestroyed(int32_t buffer_id) {
  DCHECK(io_thread_checker_.CalledOnValidThread());

  const auto& cb_iter = client_buffers_.find(buffer_id);
  if (cb_iter != client_buffers_.end()) {
    DCHECK(!cb_iter->second.get() || cb_iter->second->HasOneRef())
        << "Instructed to delete buffer we are still using.";
    client_buffers_.erase(cb_iter);
  }
}

void VideoCaptureImpl::OnClientBufferFinished(
    int buffer_id,
    const scoped_refptr<ClientBuffer>& /* ignored_buffer */,
    double consumer_resource_utilization) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  GetVideoCaptureHost()->ReleaseBuffer(
      device_id_, buffer_id, consumer_resource_utilization);
}

void VideoCaptureImpl::StopDevice() {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  if (state_ != VIDEO_CAPTURE_STATE_STARTED)
    return;
  state_ = VIDEO_CAPTURE_STATE_STOPPING;
  GetVideoCaptureHost()->Stop(device_id_);
  params_.requested_format.frame_size.SetSize(0, 0);
}

void VideoCaptureImpl::RestartCapture() {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  DCHECK_EQ(state_, VIDEO_CAPTURE_STATE_STOPPED);

  int width = 0;
  int height = 0;
  clients_.insert(clients_pending_on_restart_.begin(),
                  clients_pending_on_restart_.end());
  clients_pending_on_restart_.clear();
  for (const auto& client : clients_) {
    width = std::max(width,
                     client.second.params.requested_format.frame_size.width());
    height = std::max(
        height, client.second.params.requested_format.frame_size.height());
  }
  params_.requested_format.frame_size.SetSize(width, height);
  DVLOG(1) << __func__ << " " << params_.requested_format.frame_size.ToString();
  StartCaptureInternal();
}

void VideoCaptureImpl::StartCaptureInternal() {
  DCHECK(io_thread_checker_.CalledOnValidThread());

  GetVideoCaptureHost()->Start(device_id_, session_id_, params_,
                               observer_binding_.CreateInterfacePtrAndBind());
  state_ = VIDEO_CAPTURE_STATE_STARTED;
}

void VideoCaptureImpl::OnDeviceSupportedFormats(
    const VideoCaptureDeviceFormatsCB& callback,
    const media::VideoCaptureFormats& supported_formats) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  callback.Run(supported_formats);
}

void VideoCaptureImpl::OnDeviceFormatsInUse(
    const VideoCaptureDeviceFormatsCB& callback,
    const media::VideoCaptureFormats& formats_in_use) {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  callback.Run(formats_in_use);
}

bool VideoCaptureImpl::RemoveClient(int client_id, ClientInfoMap* clients) {
  DCHECK(io_thread_checker_.CalledOnValidThread());

  const ClientInfoMap::iterator it = clients->find(client_id);
  if (it == clients->end())
    return false;

  it->second.state_update_cb.Run(VIDEO_CAPTURE_STATE_STOPPED);
  clients->erase(it);
  return true;
}

mojom::VideoCaptureHost* VideoCaptureImpl::GetVideoCaptureHost() {
  DCHECK(io_thread_checker_.CalledOnValidThread());
  if (video_capture_host_for_testing_)
    return video_capture_host_for_testing_;

  if (!video_capture_host_.get())
    video_capture_host_.Bind(std::move(video_capture_host_info_));
  return video_capture_host_.get();
};

// static
void VideoCaptureImpl::DidFinishConsumingFrame(
    const media::VideoFrameMetadata* metadata,
    const BufferFinishedCallback& callback_to_io_thread) {
  // Note: This function may be called on any thread by the VideoFrame
  // destructor.  |metadata| is still valid for read-access at this point.
  double consumer_resource_utilization = -1.0;
  if (!metadata->GetDouble(media::VideoFrameMetadata::RESOURCE_UTILIZATION,
                           &consumer_resource_utilization)) {
    consumer_resource_utilization = -1.0;
  }
  callback_to_io_thread.Run(consumer_resource_utilization);
}

}  // namespace content


text:
class CVcIntersection : public COleDispatchDriver
{
public:
	CVcIntersection() {}		// Calls COleDispatchDriver default constructor
	CVcIntersection(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
	CVcIntersection(const CVcIntersection& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

// Attributes
public:

// Operations
public:

	BOOL get_Auto()
	{
		BOOL result;
		InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
		return result;
	}
	void put_Auto(BOOL newValue)
	{
		static BYTE parms[] = VTS_BOOL ;
		InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}
	double get_Point()
	{
		double result;
		InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_R8, (void*)&result, NULL);
		return result;
	}
	void put_Point(double newValue)
	{
		static BYTE parms[] = VTS_R8 ;
		InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}
	long get_axisID()
	{
		long result;
		InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
		return result;
	}
	short get_Index()
	{
		short result;
		InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
		return result;
	}
	BOOL get_LabelsInsidePlot()
	{
		BOOL result;
		InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
		return result;
	}
	void put_LabelsInsidePlot(BOOL newValue)
	{
		static BYTE parms[] = VTS_BOOL ;
		InvokeHelper(0x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
	}

};

redpajama_set_name: RedPajamaGithub


text:
require File.dirname(__FILE__) + '/test_helper'

module FriendlyId
  module Test
    module ActiveRecord2
      module Simple

        module SimpleTest
          def klass
            @klass ||= User
          end

          def instance
            @instance ||= User.create! :name => "hello world"
          end

          def other_class
            Author
          end
        end

        class StatusTest < ::Test::Unit::TestCase

          include SimpleTest

          test "should default to not friendly" do
            assert !status.friendly?
          end

          test "should default to numeric" do
            assert status.numeric?
          end

          test "should be friendly if name is set" do
            status.name = "name"
            assert status.friendly?
          end

          test "should be best if it is numeric, but record has no friendly_id" do
            instance.send("#{klass.friendly_id_config.column}=", nil)
            assert status.best?
          end

          def status
            @status ||= instance.friendly_id_status
          end

        end

        class BasicTest < ::Test::Unit::TestCase
          include Core
          include SimpleTest
        end

      end
    end
  end
end


text:
import sys
import os
reload(sys)
sys.setdefaultencoding("utf-8")
from sqlalchemy import Table

from yaml import load
try:
	from yaml import CSafeLoader as SafeLoader
	print "Using CSafeLoader"
except ImportError:
	from yaml import SafeLoader
	print "Using Python SafeLoader"

def importyaml(connection,metadata,sourcePath,language='en'):
    print "Importing character bloodlines"
    chrBloodlines = Table('chrBloodlines',metadata)

    print "opening Yaml"

    trans = connection.begin()
    with open(os.path.join(sourcePath,'fsd','bloodlines.yaml'),'r') as yamlstream:
        print "importing"
        bloodlines=load(yamlstream,Loader=SafeLoader)
        print "Yaml Processed into memory"
        for bloodlineid in bloodlines:
            connection.execute(chrBloodlines.insert(),
                            bloodlineID=bloodlineid,
                            bloodlineName=bloodlines[bloodlineid].get('nameID',{}).get(language,'').decode('utf-8'),
                            description=bloodlines[bloodlineid].get('descriptionID',{}).get(language,'').decode('utf-8'),
                            iconID=bloodlines[bloodlineid].get('iconID'),
                            corporationID=bloodlines[bloodlineid].get('corporationID'),
                            charisma=bloodlines[bloodlineid].get('charisma'),
                            intelligence=bloodlines[bloodlineid].get('intelligence'),
                            memory=bloodlines[bloodlineid].get('memory'),
                            perception=bloodlines[bloodlineid].get('perception'),
                            raceID=bloodlines[bloodlineid].get('raceID'),
                            shipTypeID=bloodlines[bloodlineid].get('shipTypeID'),
                              )
    trans.commit()


text:
using System.Collections.Generic;
using System.Linq;
using Peoneer.Library.Remote;

namespace Peoneer.Library.Core
{
    public interface IBuildAgentRepository
    {
        void AddAgent(string endpoint);
        IEnumerable<BuildAgentClientBase> GetAgents();
        BuildAgentClientBase GetAgent(string name);
    }

    public class InMemoryBuildAgentRepository : IBuildAgentRepository
    {
        private List<BuildAgentClientBase> _buildAgents = new List<BuildAgentClientBase>();
        public void AddAgent(string endpoint)
        {
            _buildAgents.Add(new WcfClient(new WcfChannel<IMessageProcessor>(endpoint)));
        }

        public IEnumerable<BuildAgentClientBase> GetAgents()
        {
            return _buildAgents;
        }

        public BuildAgentClientBase GetAgent(string name)
        {
            return _buildAgents.FirstOrDefault(a => a.Name == name);
        }
    }
}


text: "use strict";var l={};(this?this:window)['DvtBaseMapManager']['_UNPROCESSED_MAPS'][2].push(["northAmerica","countries",l]);


text:
/**
 * Module dependencies
 */

var fs = require('fs');
var path = require('path');

/**
 * Check if the specified appPath contains something that looks like a Sails app.
 *
 * @param {String} appPath
 */

module.exports = function isSailsAppSync(appPath) {

  // Has no package.json file
  if (!fs.existsSync(path.join(appPath, 'package.json'))) {
    return false;
  }

  // Package.json exists, but doesn't list Sails as a dependency
  var appPackageJSON;
  try {
    appPackageJSON = JSON.parse(fs.readFileSync(path.resolve(appPath, 'package.json'), 'utf8'));
  } catch (e) {
    return false;
  }
  var appDependencies = appPackageJSON.dependencies;
  if (!(appDependencies && appDependencies.sails)) {
    return false;
  }

  return true;
};


text:
using namespace v8;

Persistent<Function> MCrypt::constructor;

MCrypt::MCrypt(const Arguments& args):
    checkKeySize(true),
    checkIvSize(true),
    algo(args[0]),
    mode(args[1]),
    algoDir(args[2]),
    modeDir(args[3]) {

    mcrypt_ = mcrypt_module_open(*algo, *algoDir, *mode, *modeDir);
};

MCrypt::~MCrypt() {
    mcrypt_module_close(mcrypt_);
};

template <int (*modify)(MCRYPT mcrypt, void* target, int length)>
node::Buffer* MCrypt::transform(const char* plainText, const size_t length, int* result) {
    size_t targetLength = length;

    // determine allocation size if the cipher algorithm is block mode
    // block mode algorithm needs to fit in modulus of block size
    // and it needs to padding space if not fit into block size
    if (mcrypt_enc_is_block_algorithm(mcrypt_) == 1) {
        size_t blockSize = mcrypt_enc_get_block_size(mcrypt_);
        targetLength = (((length - 1) / blockSize) + 1) * blockSize;
    }

    char* targetData = new char[targetLength]();
    std::copy(plainText, plainText + length, targetData);

    // create a dummy object to return on fail result
    node::Buffer* cipherText = node::Buffer::New(1);

    // copy of the key and iv due to mcrypt_generic_init not accepts
    // const char for key and iv. direct passing is not safe because
    // iv and key could be modified by mcrypt_generic_init in this case
    char keyBuf[key.length()];
    key.copy(keyBuf, key.length());

    char ivBuf[iv.length()];
    iv.copy(ivBuf, iv.length());

    if ((*result = mcrypt_generic_init(mcrypt_, keyBuf, key.length(), ivBuf)) < 0) {
        delete[] targetData;

        return cipherText;
    }

    if ((*result = modify(mcrypt_, targetData, targetLength)) != 0) {
        delete[] targetData;

        return cipherText;
    }

    if ((*result = mcrypt_generic_deinit(mcrypt_)) < 0) {
        delete[] targetData;

        return cipherText;
    }

    cipherText = node::Buffer::New(targetData, targetLength);

    delete[] targetData;

    return cipherText;
}

std::vector<size_t> MCrypt::getKeySizes() {

    int count = 0;
    int* sizes = mcrypt_enc_get_supported_key_sizes(mcrypt_, &count);

    if (count <= 0) {
        mcrypt_free(sizes);

        size_t size = mcrypt_enc_get_key_size(mcrypt_);

        if (size > 0) {
            std::vector<size_t> keySizes(1);
            keySizes[0] = size;
            return keySizes;
        }

        std::vector<size_t> keySizes(0);
        return keySizes;
    }

    std::vector<size_t> keySizes(count);

    for (int i = 0; i < count; i++) {
        keySizes[i] = sizes[i];
    }

    mcrypt_free(sizes);

    return keySizes;
}

NODE_MCRYPT_METHOD(New) {
    HandleScope scope;

    if (!args.IsConstructCall()) {
        Local<Value> argv[] = {args[0], args[1], args[2], args[3]};
        return scope.Close(constructor->NewInstance(4, argv));
    }

    if (args.Length() < 2) {
        return ThrowException(Exception::TypeError(String::New("Missing parameters. Algorithm and mode should be specified.")));
    }

    MCrypt* mcrypt = new MCrypt(args);

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    mcrypt->Wrap(args.This());

    return args.This();
}

NODE_MCRYPT_METHOD(Open) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(Exception::TypeError(String::New("Missing parameter. Key should be specified.")));
    }

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (args[0]->IsString()) {
        String::Utf8Value value(args[0]);

        mcrypt->key = std::string(*value, value.length());

    } else if (node::Buffer::HasInstance(args[0])) {

        mcrypt->key = std::string(node::Buffer::Data(args[0]), node::Buffer::Length(args[0]));

    } else {
        return ThrowException(Exception::TypeError(String::New("Key has got incorrect type. Should be Buffer or String.")));
    }

    if (mcrypt->checkKeySize) {
        std::vector<size_t> keySizes = mcrypt->getKeySizes();

        if (keySizes.size() > 0) {

            bool invalid = true;

            std::stringstream serror;

            serror << "Invalid key size. Available key size are [";

            for(size_t i = 0; i < keySizes.size(); i++) {

                if (i != 0) {
                    serror << ", ";
                }

                serror << keySizes[i];

                if (keySizes[i] == mcrypt->key.length()) {
                    invalid = false;
                }
            }

            serror << "]";

            std::string error = serror.str();

            if (invalid) {
                return ThrowException(Exception::TypeError(String::New(error.c_str(), error.length())));
            }
        }
    }

    if (args[1]->IsUndefined()) {
        return scope.Close(Undefined());
    }

    size_t ivLen;

    if (args[1]->IsString()) {

        String::Utf8Value value(args[1]);

        ivLen = value.length();
        mcrypt->iv = std::string(*value, ivLen);

    } else if (node::Buffer::HasInstance(args[1])) {

        ivLen = node::Buffer::Length(args[1]);
        mcrypt->iv = std::string(node::Buffer::Data(args[1]), ivLen);
    } else {
        return ThrowException(Exception::TypeError(String::New("Iv has got incorrect type. Should be Buffer or String.")));
    }

    if (mcrypt->checkIvSize) {
        if ((size_t)mcrypt_enc_get_iv_size(mcrypt->mcrypt_) != ivLen) {
            return ThrowException(Exception::TypeError(String::New("Invalid iv size. You can determine iv size using getIvSize()")));
        }
    }

    return scope.Close(Undefined());
}

NODE_MCRYPT_METHOD(Encrypt) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(Exception::TypeError(String::New("Missing parameter. Plaintext should be specified.")));
    }

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int result = 0;
    node::Buffer* cipherText = node::Buffer::New(1);

    if (args[0]->IsString()) {

        String::Utf8Value value(args[0]);
        cipherText = mcrypt->transform<mcrypt_generic>(*value, value.length(), &result);

    } else if(node::Buffer::HasInstance(args[0])) {

        cipherText = mcrypt->transform<mcrypt_generic>(node::Buffer::Data(args[0]), node::Buffer::Length(args[0]), &result);

    } else {
        return ThrowException(Exception::TypeError(String::New("Plaintext has got incorrect type. Should be Buffer or String.")));
    }

    if (result != 0) {
        const char* error = mcrypt_strerror(result);
        return ThrowException(Exception::Error(String::New(error)));
    }

    return scope.Close(cipherText->handle_);
}

NODE_MCRYPT_METHOD(Decrypt) {
    HandleScope scope;

    if (args.Length() < 1) {
        return ThrowException(Exception::TypeError(String::New("Missing parameter. Plaintext should be specified.")));
    }

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int result = 0;
    node::Buffer* plainText = node::Buffer::New(1);

    if (args[0]->IsString()) {

        String::Utf8Value value(args[0]);
        plainText = mcrypt->transform<mdecrypt_generic>(*value, value.length(), &result);

    } else if (node::Buffer::HasInstance(args[0])) {

        plainText = mcrypt->transform<mdecrypt_generic>(node::Buffer::Data(args[0]), node::Buffer::Length(args[0]), &result);

    } else {
        return ThrowException(Exception::TypeError(String::New("Ciphertext has got incorrect type. Should be Buffer or String.")));
    }

    if (result != 0) {
        const char* error = mcrypt_strerror(result);
        return ThrowException(Exception::Error(String::New(error)));
    }

    return scope.Close(plainText->handle_);
}

NODE_MCRYPT_METHOD(ValidateKeySize) {
    HandleScope scope;

    if(args.Length() == 0) {
        return scope.Close(Undefined());
    }

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());
    Local<Boolean> state = args[0]->ToBoolean();
    mcrypt->checkKeySize = state->Value();

    return scope.Close(Undefined());
}

NODE_MCRYPT_METHOD(ValidateIvSize) {
    HandleScope scope;

    if(args.Length() == 0) {
        return scope.Close(Undefined());
    }

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());
    Local<Boolean> state = args[0]->ToBoolean();
    mcrypt->checkIvSize = state->Value();

    return scope.Close(Undefined());
}

NODE_MCRYPT_METHOD(SelfTest) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (mcrypt_enc_self_test(mcrypt->mcrypt_) == 0) {
        return scope.Close(True());
    }

    return scope.Close(False());
}

NODE_MCRYPT_METHOD(IsBlockAlgorithmMode) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (mcrypt_enc_is_block_algorithm_mode(mcrypt->mcrypt_) == 1) {
        return scope.Close(True());
    }

    return scope.Close(False());
}

NODE_MCRYPT_METHOD(IsBlockAlgorithm) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (mcrypt_enc_is_block_algorithm(mcrypt->mcrypt_) == 1) {
        return scope.Close(True());
    }

    return scope.Close(False());
}

NODE_MCRYPT_METHOD(IsBlockMode) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (mcrypt_enc_is_block_mode(mcrypt->mcrypt_) == 1) {
        return scope.Close(True());
    }

    return scope.Close(False());
}

NODE_MCRYPT_METHOD(GetBlockSize) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int blockSize = mcrypt_enc_get_block_size(mcrypt->mcrypt_);

    return scope.Close(Number::New(blockSize));
}

NODE_MCRYPT_METHOD(GetKeySize) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int keySize = mcrypt_enc_get_key_size(mcrypt->mcrypt_);

    return scope.Close(Number::New(keySize));
}

NODE_MCRYPT_METHOD(GetSupportedKeySizes) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    std::vector<size_t> keySizes = mcrypt->getKeySizes();

    Handle<Array> array = Array::New(keySizes.size());

    for (size_t i = 0; i < keySizes.size(); i++) {
        array->Set(i, Number::New(keySizes[i]));
    }

    return scope.Close(array);
}

NODE_MCRYPT_METHOD(GetIvSize) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int ivSize = mcrypt_enc_get_iv_size(mcrypt->mcrypt_);

    return scope.Close(Number::New(ivSize));
}

NODE_MCRYPT_METHOD(HasIv) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    if (mcrypt_enc_mode_has_iv(mcrypt->mcrypt_) == 1) {
        return scope.Close(True());
    }

    return scope.Close(False());
}

NODE_MCRYPT_METHOD(GetAlgorithmName) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    char* name = mcrypt_enc_get_algorithms_name(mcrypt->mcrypt_);
    Handle<String> ret = String::New(name);
    mcrypt_free(name);

    return scope.Close(ret);
}

NODE_MCRYPT_METHOD(GetModeName) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    char* name = mcrypt_enc_get_modes_name(mcrypt->mcrypt_);
    Handle<String> ret = String::New(name);
    mcrypt_free(name);

    return scope.Close(ret);
}

NODE_MCRYPT_METHOD(GenerateIv) {
    HandleScope scope;

    MCrypt* mcrypt = ObjectWrap::Unwrap<MCrypt>(args.This());

    MCRYPT_MODULE_ERROR_CHECK(mcrypt)

    int ivSize = mcrypt_enc_get_iv_size(mcrypt->mcrypt_);

    node::Buffer* buffer = node::Buffer::New(ivSize);

    char* iv = node::Buffer::Data(buffer);

    while(ivSize) {
        iv[--ivSize] = 255.0 * std::rand() / RAND_MAX;
    }

    return scope.Close(buffer->handle_);
}

NODE_MCRYPT_METHOD(GetAlgorithmNames) {
    HandleScope scope;

    String::Utf8Value path(args[0]);

    int size = 0;
    char** algos = mcrypt_list_algorithms(*path, &size);

    Handle<Array> array = Array::New(size);

    if (array.IsEmpty()) {
        return Handle<Array>();
    }

    for (int i = 0; i < size; i++) {
        array->Set(i, String::New(algos[i]));
    }

    mcrypt_free_p(algos, size);

    return scope.Close(array);
}

NODE_MCRYPT_METHOD(GetModeNames) {
    HandleScope scope;

    String::Utf8Value path(args[0]);

    int size = 0;
    char** modes = mcrypt_list_modes(*path, &size);

    Handle<Array> array = Array::New(size);

    if (array.IsEmpty())
        return Handle<Array>();

    for (int i = 0; i < size; i++) {
        array->Set(i, String::New(modes[i]));
    }

    mcrypt_free_p(modes, size);

    return scope.Close(array);
}

void MCrypt::Init(Handle<Object> exports) {
    Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
    tpl->SetClassName(String::NewSymbol("MCrypt"));
    tpl->InstanceTemplate()->SetInternalFieldCount(1);

    Local<ObjectTemplate> prototype = tpl->PrototypeTemplate();

    // prototype
    prototype->Set(String::NewSymbol("encrypt"), FunctionTemplate::New(Encrypt)->GetFunction());
    prototype->Set(String::NewSymbol("decrypt"), FunctionTemplate::New(Decrypt)->GetFunction());
    prototype->Set(String::NewSymbol("open"), FunctionTemplate::New(Open)->GetFunction());
    prototype->Set(String::NewSymbol("validateKeySize"), FunctionTemplate::New(ValidateKeySize)->GetFunction());
    prototype->Set(String::NewSymbol("validateIvSize"), FunctionTemplate::New(ValidateIvSize)->GetFunction());
    prototype->Set(String::NewSymbol("selfTest"), FunctionTemplate::New(SelfTest)->GetFunction());
    prototype->Set(String::NewSymbol("isBlockAlgorithmMode"), FunctionTemplate::New(IsBlockAlgorithmMode)->GetFunction());
    prototype->Set(String::NewSymbol("isBlockAlgorithm"), FunctionTemplate::New(IsBlockAlgorithm)->GetFunction());
    prototype->Set(String::NewSymbol("isBlockMode"), FunctionTemplate::New(IsBlockMode)->GetFunction());
    prototype->Set(String::NewSymbol("getBlockSize"), FunctionTemplate::New(GetBlockSize)->GetFunction());
    prototype->Set(String::NewSymbol("getKeySize"), FunctionTemplate::New(GetKeySize)->GetFunction());
    prototype->Set(String::NewSymbol("getSupportedKeySizes"), FunctionTemplate::New(GetSupportedKeySizes)->GetFunction());
    prototype->Set(String::NewSymbol("getIvSize"), FunctionTemplate::New(GetIvSize)->GetFunction());
    prototype->Set(String::NewSymbol("hasIv"), FunctionTemplate::New(HasIv)->GetFunction());
    prototype->Set(String::NewSymbol("getAlgorithmName"), FunctionTemplate::New(GetAlgorithmName)->GetFunction());
    prototype->Set(String::NewSymbol("getModeName"), FunctionTemplate::New(GetModeName)->GetFunction());
    prototype->Set(String::NewSymbol("generateIv"), FunctionTemplate::New(GenerateIv)->GetFunction());

    // exports
    constructor = Persistent<Function>::New(tpl->GetFunction());
    exports->Set(String::NewSymbol("MCrypt"), constructor);
    exports->Set(String::NewSymbol("getAlgorithmNames"), FunctionTemplate::New(GetAlgorithmNames)->GetFunction());
    exports->Set(String::NewSymbol("getModeNames"), FunctionTemplate::New(GetModeNames)->GetFunction());
}

NODE_MODULE(mcrypt, MCrypt::Init)


text:
\hypertarget{_unigram___train___data___formatter_8cpp}{
\section{src/Unigram\_\-Model/Formatter/Unigram\_\-Train\_\-Data\_\-Formatter.cpp File Reference}
\label{_unigram___train___data___formatter_8cpp}\index{src/Unigram\_\-Model/Formatter/Unigram\_\-Train\_\-Data\_\-Formatter.cpp@{src/Unigram\_\-Model/Formatter/Unigram\_\-Train\_\-Data\_\-Formatter.cpp}}
}
{\ttfamily \#include \char`\"{}Unigram\_\-Train\_\-Data\_\-Formatter.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}glog/logging.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}commons/Context.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}commons/document.pb.h\char`\"{}}\par
{\ttfamily \#include \char`\"{}commons/constants.h\char`\"{}}\par


text:
export const BOOKS_I_READ = 'BOOKS_I_READ';
export const MY_FAVORITES = 'MY_FAVORITES';
export const ADDITIONAL_DATA_MAP_KEYS = {
  KEY: 'key',
  VALUE: 'value',
};


text:
#include "couchbase.h"
#include <Zend/zend_alloc.h>

zend_class_entry *pcbc_cluster_options_ce;

extern zend_class_entry *pcbc_meter_ce;
extern zend_class_entry *pcbc_request_tracer_ce;

PHP_METHOD(ClusterOptions, credentials)
{
    zend_string *username, *password;
    int rv = zend_parse_parameters_throw(ZEND_NUM_ARGS(), "SS", &username, &password);
    if (rv == FAILURE) {
        RETURN_NULL();
    }
    pcbc_update_property_str(pcbc_cluster_options_ce, getThis(), ("username"), username);
    pcbc_update_property_str(pcbc_cluster_options_ce, getThis(), ("password"), password);
    RETURN_ZVAL(getThis(), 1, 0);
}

PHP_METHOD(ClusterOptions, meter)
{
    zval *meter = NULL;
    int rv = zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &meter, pcbc_meter_ce);
    if (rv == FAILURE) {
        RETURN_NULL();
    }
    pcbc_update_property(pcbc_cluster_options_ce, getThis(), ("meter"), meter);
    RETURN_ZVAL(getThis(), 1, 0);
}

PHP_METHOD(ClusterOptions, tracer)
{
    zval *tracer = NULL;
    int rv = zend_parse_parameters_throw(ZEND_NUM_ARGS(), "O", &tracer, pcbc_request_tracer_ce);
    if (rv == FAILURE) {
        RETURN_NULL();
    }
    pcbc_update_property(pcbc_cluster_options_ce, getThis(), ("tracer"), tracer);
    RETURN_ZVAL(getThis(), 1, 0);
}

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_ClusterOptions_credentials, 0, 1, Couchbase\\ClusterOptions, 0)
ZEND_ARG_TYPE_INFO(0, username, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_ClusterOptions_meter, 0, 1, Couchbase\\ClusterOptions, 0)
ZEND_ARG_OBJ_INFO(0, meter, Couchbase\\Meter, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(ai_ClusterOptions_tracer, 0, 1, Couchbase\\ClusterOptions, 0)
ZEND_ARG_OBJ_INFO(0, tracer, Couchbase\\RequestTracer, 0)
ZEND_END_ARG_INFO()

// clang-format off
zend_function_entry cluster_options_methods[] = {
    PHP_ME(ClusterOptions, credentials, ai_ClusterOptions_credentials, ZEND_ACC_PUBLIC)
    PHP_ME(ClusterOptions, meter, ai_ClusterOptions_meter, ZEND_ACC_PUBLIC)
    PHP_ME(ClusterOptions, tracer, ai_ClusterOptions_tracer, ZEND_ACC_PUBLIC)
    PHP_FE_END
};
// clang-format on

PHP_MINIT_FUNCTION(ClusterOptions)
{
    zend_class_entry ce;

    INIT_NS_CLASS_ENTRY(ce, "Couchbase", "ClusterOptions", cluster_options_methods);
    pcbc_cluster_options_ce = zend_register_internal_class(&ce);

    zend_declare_property_null(pcbc_cluster_options_ce, ZEND_STRL("username"), ZEND_ACC_PRIVATE);
    zend_declare_property_null(pcbc_cluster_options_ce, ZEND_STRL("password"), ZEND_ACC_PRIVATE);
    zend_declare_property_null(pcbc_cluster_options_ce, ZEND_STRL("meter"), ZEND_ACC_PRIVATE);
    zend_declare_property_null(pcbc_cluster_options_ce, ZEND_STRL("tracer"), ZEND_ACC_PRIVATE);

    return SUCCESS;
}


text:
using Storage.Net.Blobs;
using Storage.Net.Messaging;

namespace Storage.Net.ConnectionString
{
   /// <summary>
   /// Connection factory is responsible for creating storage instances from connection strings. It
   /// is usually implemented by every external module, however is optional.
   /// </summary>
   public interface IConnectionFactory
   {
      /// <summary>
      /// Creates a blob storage instance from connection string if possible. When this factory does not support this connection
      /// string it returns null.
      /// </summary>
      IBlobStorage CreateBlobStorage(StorageConnectionString connectionString);

      /// <summary>
      /// Creates a message publisher
      /// </summary>
      IMessenger CreateMessenger(StorageConnectionString connectionString);
   }
}


text: CLI tool to provide a summary of commit history on many GIT repos over a period of time


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

<title>Quaternion</title>
<meta name="date" content="2013-03-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

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.tyrlib2.math

Class Quaternion

java.lang.Object

com.tyrlib2.math.Quaternion

public class Quaternion
extends java.lang.Object

Represents a rotation in 3D space

Author:

Sascha

Field Summary

Fields

Modifier and Type
Field and Description

float
w

float
x

float
y

float
z

Constructor Summary

Constructors

Constructor and Description

Quaternion()

Defaults to the identity quaternion

Quaternion(float x,
          float y,
          float z,
          float w)

Quaternion(Quaternion other)

Method Summary

Methods

Modifier and Type
Method and Description

static Quaternion
fromAxisAngle(Vector3 axis,
             float angle)

Create a quaternion from an axis-angle rotation

static Quaternion
getIdentity()

Quaternion
inverse()

Get the inverse of this quaternion

void
invert()

Invert this quaternion

float
length()

Get the "length" of this quaternion

Quaternion
multiply(Quaternion other)

Multiply this quaternion with another

Vector3
multiply(Vector3 vector)

void
multiplyNoTmp(Quaternion other)

Multiply this quaternion with another

void
multiplyNoTmp(Vector3 vector)

void
normalize()

Normalize this quaternion

Quaternion
normalized()

Get a normalized version of this quaternion

Quaternion
rotate(Vector3 axis,
      float angle)

static Quaternion
slerp(Quaternion start,
     Quaternion end,
     float alpha)

Perform a spherical linear interpolation between the two quaternion q1 and q2

float[]
toMatrix()

Converts this quaternion to a 4x4 matrix

void
toMatrix(float[] matrix)

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

x

public float x

y

public float y

z

public float z

w

public float w

Constructor Detail

Quaternion

public Quaternion()

Defaults to the identity quaternion

Quaternion

public Quaternion(float x,
          float y,
          float z,
          float w)

Quaternion

public Quaternion(Quaternion other)

Method Detail

normalized

public Quaternion normalized()

Get a normalized version of this quaternion

Returns:

The normalized quaternion

length

public float length()

Get the "length" of this quaternion

Returns:

normalize

public void normalize()

Normalize this quaternion

inverse

public Quaternion inverse()

Get the inverse of this quaternion

Returns:

The inverse of this quaternion

invert

public void invert()

Invert this quaternion

multiply

public Quaternion multiply(Quaternion other)

Multiply this quaternion with another

Parameters:

other -

Returns:

The resulting quaternion

multiplyNoTmp

public void multiplyNoTmp(Quaternion other)

Multiply this quaternion with another

Parameters:

other -

rotate

public Quaternion rotate(Vector3 axis,
                float angle)

toMatrix

public float[] toMatrix()

Converts this quaternion to a 4x4 matrix

Returns:

toMatrix

public void toMatrix(float[] matrix)

getIdentity

public static Quaternion getIdentity()

fromAxisAngle

public static Quaternion fromAxisAngle(Vector3 axis,
                       float angle)

Create a quaternion from an axis-angle rotation

slerp

public static Quaternion slerp(Quaternion start,
               Quaternion end,
               float alpha)

Perform a spherical linear interpolation between the two quaternion q1 and q2

Parameters:

start - The start rotation

end - The end rotation

alpha - The blending factor (0 <= alpha <= 1) with
                                0:      start rotation and
                                1:      end rotation

Returns:

A quaternion representing the interpolated rotation

multiply

public Vector3 multiply(Vector3 vector)

multiplyNoTmp

public void multiplyNoTmp(Vector3 vector)

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:
package com.bramyeh.buttonsaroundcircle.fragment;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.bramyeh.buttonsaroundcircle.R;

public class DemoFragment extends Fragment {

	private CustumizedButton mCustumizedButton;
	private View mView;

	public DemoFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View rootView = inflater.inflate(R.layout.fragment_main, container,
				false);

		mCustumizedButton = (CustumizedButton) rootView
				.findViewById(R.id.custumizedButton);
		mCustumizedButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				int color = mCustumizedButton.getCurrentColor();
				if (mView != null && color != Color.TRANSPARENT) {
					mView.setBackgroundColor(color);
				}
			}
		});

		mView = (View) rootView.findViewById(R.id.view);
		mView.setBackgroundColor(Color.BLACK);

		return rootView;
	}

}


text:
ACCEPTED

#### According to
Index Fungorum

#### Published in
null

#### Original name
Trametes odorata f. globosa Pilát

### Remarks
null


text:
preventChangingApps=yes

#To Prevent Changing the Location of the Dock, set this to yes
preventChangingLocation=yes

#To Prevent Changing the Size of the Dock, set this to yes
preventChangingSize=yes

####################################################################################################
#
# SCRIPT CONTENTS - DO NOT MODIFY BELOW THIS LINE
#
####################################################################################################

user=`ls -l /dev/console | awk '/ / { print $3 }'`
sudo -u $user defaults write com.apple.Dock contents-immutable -bool $preventChangingApps
sudo -u $user defaults write com.apple.Dock position-immutable -bool $preventChangingLocation
sudo -u $user defaults write com.apple.Dock size-immutable -bool $preventChangingSize
sudo killall Dock


text:
layout: page
title: About
permalink: /about/
---

Seorang lelaki yang terlahir di tempat nun jauh dari ibu kota, tempat yang indah dan penuh dengan orang-orang ramah yang gemar bersuara keras, Gorontalo.

Mulai tinggal terpisah dari orang tua demi menimba ilmu sejak bersekolah di Madrasah Aliyah Negeri Insan Cendekia Gorontalo. Alhamdulillah setelah 3 tahun bisa lulus, ga pake remedial.

Setelah itu berangkat ke kota hujan demi menuntut ilmu di perguruan tinggi Institut Pertanian Bogor. Alhamdulillah mendapatkan jurusan yang sesuai *passion*, Ilmu Komputer. Ya meskipun lulusnya nilai akhirnya ga bagus-bagus amat, Alhamdulillah masih bisa lulus 4 tahun lebih sedikit.

Lulus dari dunia perkuliahan melanglang buana dalam beberapa profesi di dunia programmer, bahasa pemrogramannya pun berganti-ganti. Sekarang sudah setahun lebih berkutat dengan Java, dan mulai bergeser lagi ke Ruby (on Rails) dan Node JS. Saat ini berprofesi sebagai software engineer di salah satu perusahaan teknologi finansial di Indonesia.

Semoga lewat blog ini saya bisa menyebarkan kebaikan ke sesama makhluk Allah swt. dan bisa pula menyebarkan ilmu yang mungkin bisa menjadi amal jariyah untuk saya :).

Salam hangat,

Alfat Saputra Harun


text:
"""
A second, custom AdminSite -- see tests.CustomAdminSiteTests.
"""
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.urls import path

from . import admin as base_admin
from . import forms, models

class Admin2(admin.AdminSite):
    app_index_template = "custom_admin/app_index.html"
    login_form = forms.CustomAdminAuthenticationForm
    login_template = "custom_admin/login.html"
    logout_template = "custom_admin/logout.html"
    index_template = ["custom_admin/index.html"]  # a list, to test fix for #18697
    password_change_template = "custom_admin/password_change_form.html"
    password_change_done_template = "custom_admin/password_change_done.html"

    # A custom index view.
    def index(self, request, extra_context=None):
        return super().index(request, {"foo": "*bar*"})

    def get_urls(self):
        return [
            path("my_view/", self.admin_view(self.my_view), name="my_view"),
        ] + super().get_urls()

    def my_view(self, request):
        return HttpResponse("Django is a magical pony!")

    def password_change(self, request, extra_context=None):
        return super().password_change(request, {"spam": "eggs"})

    def get_app_list(self, request, app_label=None):
        app_list = super().get_app_list(request, app_label=app_label)
        # Reverse order of apps and models.
        app_list = list(reversed(app_list))
        for app in app_list:
            app["models"].sort(key=lambda x: x["name"], reverse=True)
        return app_list

class UserLimitedAdmin(UserAdmin):
    # used for testing password change on a user not in queryset
    def get_queryset(self, request):
        qs = super().get_queryset(request)
        return qs.filter(is_superuser=False)

class CustomPwdTemplateUserAdmin(UserAdmin):
    change_user_password_template = [
        "admin/auth/user/change_password.html"
    ]  # a list, to test fix for #18697

class BookAdmin(admin.ModelAdmin):
    def get_deleted_objects(self, objs, request):
        return ["a deletable object"], {"books": 1}, set(), []

site = Admin2(name="admin2")

site.register(models.Article, base_admin.ArticleAdmin)
site.register(models.Book, BookAdmin)
site.register(
    models.Section, inlines=[base_admin.ArticleInline], search_fields=["name"]
)
site.register(models.Thing, base_admin.ThingAdmin)
site.register(models.Fabric, base_admin.FabricAdmin)
site.register(models.ChapterXtra1, base_admin.ChapterXtra1Admin)
site.register(User, UserLimitedAdmin)
site.register(models.UndeletableObject, base_admin.UndeletableObjectAdmin)
site.register(models.Simple, base_admin.AttributeErrorRaisingAdmin)

simple_site = Admin2(name="admin4")
simple_site.register(User, CustomPwdTemplateUserAdmin)


text:
import Page from './Page';
import { adminEmail, adminPassword } from '../../data/user';

class SetupWizard extends Page {
	get nextStep() { return browser.element('[data-qa="setup-wizard"] [data-qa="active-step"] [data-qa="next-step"]'); }

	get goToWorkspace() { return browser.element('[data-qa="setup-wizard"] [data-qa="go-to-workspace"]'); }

	get organizationType() { return browser.element('[data-qa="setup-wizard"] [data-qa="Organization_Type"]'); }

	get organizationName() { return browser.element('[data-qa="setup-wizard"] [data-qa="Organization_Name"]'); }

	get industry() { return browser.element('[data-qa="setup-wizard"] [data-qa="Industry"]'); }

	get size() { return browser.element('[data-qa="setup-wizard"] [data-qa="Size"]'); }

	get country() { return browser.element('[data-qa="setup-wizard"] [data-qa="Country"]'); }

	get website() { return browser.element('[data-qa="setup-wizard"] [data-qa="Website"]'); }

	get siteName() { return browser.element('[data-qa="setup-wizard"] [data-qa="Site_Name"]'); }

	get language() { return browser.element('[data-qa="setup-wizard"] [data-qa="Language"]'); }

	get serverType() { return browser.element('[data-qa="setup-wizard"] [data-qa="Server_Type"]'); }

	get registeredServer() { return browser.element('[data-qa="setup-wizard"] [data-qa="register-server"]'); }

	get standaloneServer() { return browser.element('[data-qa="setup-wizard"] [data-qa="register-server-standalone"]'); }

	get serviceTermsAndPrivacyPolicyLabel() { return browser.element('[data-qa="setup-wizard"] [data-qa="agree-terms-and-privacy"]').parent(); }

	get serviceTermsAndPrivacyPolicy() { return browser.element('[data-qa="setup-wizard"] [data-qa="agree-terms-and-privacy"]'); }

	login() {
		cy.login(adminEmail, adminPassword);
	}

	goNext() {
		this.nextStep.click();
	}

	goToHome() {
		this.goToWorkspace.click();
	}
}

module.exports = new SetupWizard();


text:
<?xml version="1.0" encoding="UTF-8"?>
<algorithms version="100401">
<algorithm name="SectLabel" version="100410">
<variant no="0" confidence="0.000000">
<bodyText confidence="0.397487333333333">
Proceedings of the Workshop on Effective Tools and Methodologies for Teaching
Natural Language Processing and Computational Linguistics, Philadelphia,
July 2002, pp. 10-18. Association for Computational Linguistics.
</bodyText>
<title confidence="0.929675">
An Interactive Spreadsheet for Teaching the Forward-Backward Algorithm
</title>
<author confidence="0.996647">
Jason Eisner
</author>
<affiliation confidence="0.968146">
Department of Computer Science
Johns Hopkins University
</affiliation>
<address confidence="0.993556">
Baltimore, MD, USA 21218-2691
</address>
<email confidence="0.99773">
jason@cs.jhu.edu
</email>
<sectionHeader confidence="0.991941" genericHeader="abstract">
Abstract
</sectionHeader>
<bodyText confidence="0.977459435897435">
This paper offers a detailed lesson plan on the forward-
backward algorithm. The lesson is taught from a live, com-
mented spreadsheet that implements the algorithm and graphs
its behavior on a whimsical toy example. By experimenting
with different inputs, one can help students develop intuitions
about HMMs in particular and Expectation Maximization in
general. The spreadsheet and a coordinated follow-up assign-
ment are available.
1 Why Teach from a Spreadsheet?
Algorithm animations are a wonderful teaching tool.
They are concrete, visual, playful, sometimes inter-
active, and remain available to students after the lec-
ture ends. Unfortunately, they have mainly been lim-
ited to algorithms that manipulate easy-to-draw data
structures.
Numerical algorithms can be "animated" by
spreadsheets. Although current spreadsheets do not
provide video, they can show "all at once" how a
computation unfolds over time, displaying interme-
diate results in successive rows of a table and on
graphs. Like the best algorithm animations, they
let the user manipulate the input data to see what
changes. The user can instantly and graphically see
the effect on the whole course of the computation.
Spreadsheets are also transparent. In Figure 1, the
user has double-clicked on a cell to reveal its un-
derlying formula. The other cells that it depends on
are automatically highlighted, with colors keyed to
the references in the formula. There is no program-
ming language to learn: spreadsheet programs are
aimed at the mass market, with an intuitive design
and plenty of online help, and today's undergrad-
uates already understand their basic operation. An
adventurous student can even experiment with mod-
ifying the formulas, or can instrument the spread-
sheet with additional graphs.
Finally, modern spreadsheet programs such as
Microsoft Excel support visually attractive layouts
with integrated comments, color, fonts, shading, and
</bodyText>
<figureCaption confidence="0.69174">
Figure 1: User has double-clicked on cell D29.
</figureCaption>
<bodyText confidence="0.989554222222222">
drawings. This makes them effective for both class-
room presentation and individual study.
This paper describes a lesson plan that was cen-
tered around a live spreadsheet, as well as a subse-
quent programming assignment in which the spread-
sheet served as a debugging aid. The materials are
available for use by others.
Students were especially engaged in class, appar-
ently for the following reasons:
</bodyText>
<listItem confidence="0.876971416666667">
• Striking results ("It learned it!") that could be im-
mediately apprehended from the graphs.
• Live interactive demo. The students were eager
to guess what the algorithm would do on partic-
ular inputs and test their guesses.
• A whimsical toy example.
• The departure from the usual class routine.
• Novel use of spreadsheets. Several students who
thought of them as mere bookkeeping tools were
awed by this, with one calling it "the coolest-ass
spreadsheet ever."
2 How to Teach from a Spreadsheet?
</listItem>
<bodyText confidence="0.999484166666667">
It is possible to teach from a live spreadsheet by us-
ing an RGB projector. The spreadsheet's zoom fea-
ture can compensate for small type, although under-
graduate eyes prove sharp enough that it may be un-
necessary. (Invite the students to sit near the front.)
Of course, interesting spreadsheets are much too
big to fit on the screen, even with a "View / Full
Screen" command. But scrolling is easy to follow
if it is not too fast and if the class has previously
been given a tour of the overall spreadsheet layout
(by scrolling and/or zooming out). Split-screen fea-
tures such as hide rows/columns, split panes, and
freeze panes can be moderately helpful; so can com-
mands to jump around the spreadsheet, or switch be-
tween two windows that display different areas. It
is a good idea to memorize key sequences for such
commands rather than struggle with mouse menus
or dialog boxes during class.
</bodyText>
<sectionHeader confidence="0.999759" genericHeader="method">
3 The Subject Matter
</sectionHeader>
<bodyText confidence="0.992899697674418">
Among topics in natural language processing,
the forward-backward or Baum-Welch algorithm
(Baum, 1972) is particularly difficult to teach.
The algorithm estimates the parameters of a
Hidden Markov Model (HMM) by Expectation-
Maximization (EM), using dynamic programming
to carry out the expectation steps efficiently.
HMMs have long been central in speech recog-
nition (Rabiner, 1989). Their application to part-
of-speech tagging (Church, 1988; DeRose, 1988)
kicked off the era of statistical NLP, and they have
found additional NLP applications to phrase chunk-
ing, text segmentation, word-sense disambiguation,
and information extraction.
The algorithm is also important to teach for ped-
agogical reasons, as the entry point to a family of
EM algorithms for unsupervised parameter estima-
tion. Indeed, it is an instructive special case of (1)
the inside-outside algorithm for estimation of prob-
abilistic context-free grammars; (2) belief propa-
gation for training singly-connected Bayesian net-
works and junction trees (Pearl, 1988; Lauritzen,
1995); (3) algorithms for learning alignment mod-
els such as weighted edit distance; (4) general finite-
state parameter estimation (Eisner, 2002).
Before studying the algorithm, students should
first have worked with some if not all of the key
ideas in simpler settings. Markov models can be
introduced through n-gram models or probabilistic
finite-state automata. EM can be introduced through
simpler tasks such as soft clustering. Global opti-
mization through dynamic programming can be in-
troduced in other contexts such as probabilistic CKY
parsing or edit distance. Finally, the students should
understand supervised training and Viterbi decod-
ing of HMMs, for example in the context of part-
of-speech tagging.
Even with such preparation, however, the
forward-backward algorithm can be difficult for be-
ginning students to apprehend. It requires them to
think about all of the above ideas at once, in com-
bination, and to relate them to the nitty-gritty of the
algorithm, namely
</bodyText>
<listItem confidence="0.869154869565217">
• the two-pass computation of mysterious a and Q
probabilities
• the conversion of these prior path probabilities to
posterior expectations of transition and emission
counts
Just as important, students must develop an under-
standing of the algorithm's qualitative properties,
which it shares with other EM algorithms:
• performs unsupervised learning (what is this and
why is it possible?)
• alternates expectation and maximization steps
• maximizes p(observed training data) (i.e., total
probability of all hidden paths that generate those
data)
• finds only a local maximum, so is sensitive to
initial conditions
• cannot escape zeroes or symmetries, so they
should be avoided in initial conditions
• uses the states as it sees fit, ignoring the sugges-
tive names that we may give them (e.g., part of
speech tags)
• may overfit the training data unless smoothing is
used
</listItem>
<bodyText confidence="0.979485923076923">
The spreadsheet lesson was deployed in two 50-
minute lectures at Johns Hopkins University, in an
introductory NLP course aimed at upper-level un-
dergraduates and first-year graduate students. A sin-
gle lecture might have sufficed for a less interactive
presentation.
The lesson appeared in week 10 of 13, by which
time the students had already been exposed to most
of the preparatory topics mentioned above, includ-
ing Viterbi decoding of a part-of-speech trigram tag-
ging model. However, the present lesson was their
first exposure to EM or indeed to any kind of unsu-
pervised learning.
</bodyText>
<figureCaption confidence="0.999911">
Figure 2: Initial guesses of parameters.
Figure 3: Diary data and reconstructed weather.
</figureCaption>
<sectionHeader confidence="0.946507" genericHeader="method">
4 The Ice Cream Climatology Data
</sectionHeader>
<bodyText confidence="0.998173024390244">
[While the spreadsheet could be used in many ways,
the next several sections offer one detailed lesson
plan. Questions for the class are included; subse-
quent points often depend on the answers, which are
concealed here in footnotes. Some fragments of the
full spreadsheet are shown in the figures.]
The situation: You are climatologists in the year
2799, studying the history of global warming. You
can't find any records of Baltimore weather, but you
do find my diary, in which I assiduously recorded
how much ice cream I ate each day (see Figure 3).
What can you figure outfrom this about the weather
that summer?
Let's simplify and suppose there are only two
kinds of days: C (cold) and H (hot). And let's sup-
pose you have guessed some probabilities as shown
on the spreadsheet (Figure 2).
Thus, you guess that on cold days, I usually ate
only 1 ice cream cone: my probabilities of 1, 2,
or 3 cones were 70%, 20% and 10%. That adds
up to 100%. On hot days, the probabilities were
reversed—I usually ate 3 ice creams. So other things
equal, if you know I ate 3 ice creams, the odds are
7 to 1 that it was a hot day, but if I ate 2 ice creams,
the odds are 1 to 1 (no information).
You also guess (still Figure 2) that if today is cold,
tomorrow is probably cold, and if today is hot, to-
morrow is probably hot. (Q: How does this setup
resemble part-of-speech tagging?1)
We also have some boundary conditions. I only
kept this diary for a while. If I was more likely to
start or stop the diary on a hot day, then that is use-
ful information and it should go in the table. (Q: Is
there an analogy in part-of-speech tagging ?2) For
simplicity, let's guess that I was equally likely to
start or stop on a hot or cold day. So the first day I
started writing was equally likely (50%) to be hot or
cold, and any given day had the same chance (10%)
of being the last recorded day, e.g., because on any
day I wrote (regardless of temperature), I had a 10%
chance of losing my diary.
</bodyText>
<sectionHeader confidence="0.721247" genericHeader="method">
5 The Trellis and ao Decoding
</sectionHeader>
<bodyText confidence="0.959592233333333">
[The notation pi (H) in this paper stands for the prob
ability of H on day i, given all the observed ice cream
data. On the spreadsheet itself the subscript i is
clear from context and is dropped; thus in Figure 3,
p(H) denotes the conditional probability pi (H), not a
prior. The spreadsheet likewise omits subscripts on
αi(H) and βi (H).]
Scroll down the spreadsheet and look at the lower
line of Figure 3, which shows a weather reconstruc-
tion under the above assumptions. It estimates the
relative hot and cold probabilities for each day. Ap-
parently, the summer was mostly hot with a cold
spell in the middle; we are unsure about the weather
on a few transitional days.
We will now see how the reconstruction was ac-
complished. Look at the trellis diagram on the
spreadsheet (Figure 4). Consistent with visual intu-
ition, arcs (lines) represent days and states (points)
represent the intervening midnights. A cold day is
represented by an arc that ends in a C state.3 (So
1A: This is a bigram tag generation model with tags C and H.
Each tag independently generates a word (1, 2, or 3); the word
choice is conditioned on the tag.
2A: A tagger should know that sentences tend to start with
determiners and end with periods. A tagging that ends with a
determiner should be penalized because p(Stop I Det) Pz� 0.
3These conventions are a compromise between a traditional
view of HMMs and a finite-state view used elsewhere in the
course. (The two views correspond to Moore vs. Mealy ma-
chines.) In the traditional view, states would represent days and
</bodyText>
<figureCaption confidence="0.967883">
Figure 4: The a-,3 trellis.
</figureCaption>
<bodyText confidence="0.976941423076923">
each arc effectively inherits the C or H label of its
terminal state.)
Q: According to the trellis, what is the a priori
probability that the first three days of summer are
H,H,C and I eat 2,3,3 cones respectively (as I did)?4
Q: Of the 8 ways to account for the 2,3,3 cones,
which is most probable?5 Q: Why do all 8 paths
have low probabilities?6
Recall that the Viterbi algorithm computes, at
each state of the trellis, the maximum probability
of any path from Start. Similarly, define a at a
state to be the total probability of all paths to that
state from Start. Q: How would you compute it
by dynamic programming?7 Q: Symmetrically, how
would you compute Q at a state, which is defined to
be the total probability of all paths to Stop?
The a and Q values are computed on the spread-
sheet (Figure 1). Q: Are there any patterns in the
values?8
Now for some important questions. Q: What is
the total probability of all paths from Start to
would bear emission probabilities such as p(3 I H). In Figure 4,
as in finite-state machines, this role is played by the arcs (which
also carry transition probabilities such as p(H I C)); this allows
a and ,3 to be described more simply as sums of path probabili-
ties. But we persist in a traditional labeling of the states as H or
</bodyText>
<listItem confidence="0.955739777777778">
C so that the a,3 notation can refer to them.
4A: Consult the path Start --+ H --+ H --+ C, which has
probability (0.5.0.2).(0.8.0.7).(0.1.0.1) = 0.1.0.56.0.01 =
0.00056. Note that the trellis is specialized to these data.
5A: H,H,H gives probability 0.1 . 0.56 . 0.56 = 0.03136.
(Starting with C would be as cheap as starting with H, but then
getting from C to H would be expensive.)
6A: It was a priori unlikely that I'd eat exactly this sequence
of ice creams. (A priori there were many more than 8 possible
</listItem>
<bodyText confidence="0.890280571428571">
paths, but this trellis only shows the paths generating the actual
data 2,3,3.) We'll be interested in the relative probabilities of
these 8 paths.
7A: In terms of a at the predecessor states: just replace
"max" with "+" in the Viterbi algorithm.
8A: a probabilities decrease going down the column, and ,3
probabilities decrease going up, as they become responsible for
</bodyText>
<figureCaption confidence="0.7156745">
generating more and more ice cream data.
Figure 5: Computing expected counts and their totals.
</figureCaption>
<bodyText confidence="0.974433625">
Stop in which day 3 is hot?9 It is shown in col-
umn H of Figure 1. Q: Why is column I of Figure 1
constant at 9.13e-19 across rows?10 Q: What does
that column tell us about ice cream or weather?11
Now the class may be able to see how to complete
the reconstruction:
which is 0.989, as shown in cell K29 of Figure 5.
Figure 3 simply graphs column K.
</bodyText>
<sectionHeader confidence="0.969098" genericHeader="method">
6 Understanding the Reconstruction
</sectionHeader>
<bodyText confidence="0.9818724">
Notice that the lower line in Figure 3 has the same
general shape as the upper line (the original data),
but is smoother. For example, some 2-ice-cream
days were tagged as probably cold and some as
probably hot. Q: Why? 12 Q: Since the first day has
2 ice creams and doesn't follow a hot day, why was
it tagged as hot? 13 Q: Why was day 11, which has
only 1 ice cream, tagged as hot? 14
We can experiment with the spreadsheet (using
the Undo command after each experiment). Q: What
</bodyText>
<footnote confidence="0.866157285714286">
do you predict will happen to Figure 3 if we weaken
9A: By the distributive law, a3 (H) . ,33 (H).
10A: It is the total probability of all paths that go through ei-
ther C or H on a given day. But all paths do that, so this is simply
the total probability of all paths! The choice of day doesn't mat-
ter.
11A: It is the probability of my actual ice cream consumption:
</footnote>
<equation confidence="0.94075">
p(2,3,3 , ...) = Pw p(�w, 2, 3, 3, ...) = 9.13e-19, where w�
</equation>
<bodyText confidence="0.981402181818182">
ranges over all 233 possible weather state sequences such as
H,H,C,.... Each summand is the probability of a trellis path.
12A: Figure 2 assumed a kind of "weather inertia" in which
a hot day tends to be followed by another hot day, and likewise
for cold days.
13Because an apparently hot day follows it. (See footnote 5.)
It is the ,3 factors that consider this information from the future,
and make a1(H) .,31 (H) » a1(C) .,31 (C).
14A: Switching from hot to cold and back (HCH) has proba-
bility 0.01, whereas staying hot (HHH) has probability 0.64. So
although the fact that I ate only one ice cream on day 11 favors
</bodyText>
<figure confidence="0.561079857142857">
C by 7 to 1, the inferred "fact" that days 10 and 12 are hot favors
Hby64to 1.
p( da 3 h 2 _ p(day 3 hot,2,3,3,...)
day hot I >3 >3 > ... ) — p(2,3,3,...)
-3(C)'β3(C)+-3(H)'β3(H) 9.8e-21+9.0e-19
-3(H)'β3(H) =9.0e-19
(a)
</figure>
<figureCaption confidence="0.999125333333333">
Figure 7: Parameters of Figure 2 updated by reestimation.
(b)
Figure 6: With (a) no inertia, and (b) anti-inertia.
</figureCaption>
<bodyText confidence="0.998051428571429">
or remove the "weather inertia" in Figure 2?15 Q:
What happens if we try "anti-inertia"?16
Even though the number of ice creams is not de-
cisive (consider day 11), it is influential. Q: What
do you predict will happen if the distribution of ice
creams is the same on hot and cold days? 17 Q: What
if we also change p(H I Start) from 0.5 to 0?18
</bodyText>
<sectionHeader confidence="0.92552" genericHeader="method">
7 Reestimating Emission Probabilities
</sectionHeader>
<bodyText confidence="0.983214235294118">
We originally assumed (Figure 2) that I had a 20%
chance of eating 2 cones on either a hot or a cold
day. But if our reconstruction is right (Figure 3), I
actually ate 2 cones on 20% of cold days but 40+%
of hot days.
15A: Changing p(C I C) = p(H I C) = p(C I H) = p(H I
H) = 0.45 cancels the smoothing effect (Figure 6a). The lower
line now tracks the upper line exactly.
16A: Setting p(C I H) = p(H I C) = 0.8 and p(C I C) =
p(H I H) = 0. 1, rather than vice-versa, yields Figure 6b.
17A: The ice cream data now gives us no information about
the weather, so pi (H) = pi (C) = 0.5 on every day i.
18A: p1 (H) = 0, but pi (H) increases toward an asymptote
of 0.5 (the "limit distribution"). The weather is more likely to
switch to hot than to cold if it was more likely cold to begin
with; so pi (H) increases if it is < 0.5.
So now that we "know" which days are hot and
which days are cold, we should really update our
probabilities to 0.2 and 0.4, not 0.2 and 0.2. After
all, our initial probabilities were just guesses.
Q: Where does the learning come from—isn't this
circular? Since our reconstruction was based on the
guessed probabilities 0.2 and 0.2, why didn't the re-
construction perfectly reflect those guesses?19
Scrolling rightward on the spreadsheet, we find
a table giving the updated probabilities (Figure 7).
This table feeds into a second copy of the forward-
backward calculation and graph. Q: The second
graph of pi (H) (not shown here) closely resembles
the first; why is it different on days 11 and 27?20
The updated probability table was computed by
the spreadsheet. Q: When it calculated how often I
ate 2 cones on a reconstructed hot day, do you think
it counted day 27 as a hot day or a cold day?21
</bodyText>
<sectionHeader confidence="0.915273" genericHeader="method">
8 Reestimating Transition Probabilities
</sectionHeader>
<bodyText confidence="0.921704285714285">
Notice that Figure 7 also updated the transition prob-
abilities. This involved counting the 4 kinds of days
distinguished by Figure 8:22 e.g., what fraction of H
19A: The reconstruction of the weather underlying the ob-
served data was a compromise between the guessed probabili-
ties (Figure 2) and the demands of the actual data. The model
in Figure 2 disagreed with the data: it would not have predicted
that 2-cone days actually accounted for more than 20% of all
days, or that they were disproportionately likely to fall between
3-cone days.
20A: These days fall between hot and cold days, so smoothing
has little effect: their temperature is mainly reconstructed from
the number of ice creams. 1 ice cream is now better evidence of
a cold day, and 2 ice creams of a hot day. Interestingly, days 11
and 14 can now conspire to "cool down" the intervening 3-ice-
cream days.
21A: Half of each, since p27(H) Pz� 0.5! The actual compu-
tation is performed in Figure 5 and should be discussed at this
point.
22 Notice how p(H --+ C) and p(C --+ H) spike when the
weather changes, on day 14 and either day 27 or 28.
</bodyText>
<figureCaption confidence="0.910634">
Figure 8: Second-order weather reconstruction.
</figureCaption>
<bodyText confidence="0.990605722222222">
days were followed by H? Again, fractional counts
were used to handle uncertainty.
Q: Does Figure 3 (first-order reconstruction)
contain enough information to construct Figure 8
(second-order reconstruction)?23
Continuing with the probabilities from the end of
footnote 23, suppose we increase p(H I Start) to
0.7. Q: What will happen to the first-order graph?24
Q: What if we switch from anti-inertia back to iner-
tia (Figure 9)?25
Q: In this last case, what do you predict will hap-
pen when we reestimate the probabilities?26
This reestimation (Figure 10) slightly improved
the reconstruction. [Defer discussion of what "im-
proved" means: the class still assumes that good re-
constructions look like Figure 3.] Q: Now what?
A: Perhaps we should do it again. And again, and
again... Scrolling rightward past 10 successive rees-
timations, we see that this arrives at the intuitively
23A: No. A dramatic way to see this is to make the dis-
tribution of ice cream distribution the same on hot and cold
days. This makes the first-order graph constant at 0.5 as in foot-
note 17. But we can still get a range of behaviors in the second-
order graph; e.g., if we switch from inertia to anti-inertia as in
footnote 16, then we switch from thinking the weather is un-
known but constant to thinking it is unknown but oscillating.
24A: pi (H) alternates and converges to 0.5 from both sides.
25A: pi (H) converges to 0.5 from above (cf. footnote 18), as
shown in Figure 9.
26A: The first-order graph suggests that the early days of
summer were slightly more likely to be hot than cold. Since
we ate more ice cream on those days, the reestimated probabili-
ties (unlike the initial ones) slightly favor eating more ice cream
on hot days. So the new reconstruction based on these proba-
bilities has a very shallow "U" shape (bottom of Figure 10), in
which the low-ice-cream middle of the summer is slightly less
</bodyText>
<figureCaption confidence="0.845278">
likely to be hot.
Figure 9: An initial poor reconstruction that will be improved
</figureCaption>
<bodyText confidence="0.973229066666667">
by reestimation.
correct answer (Figure 11)!
Thus, starting from an uninformed probability ta-
ble, the spreadsheet learned sensible probabilities
(Figure 11) that enabled it to reconstruct the weather.
The 3-D graph shows how the reconstruction im-
proved over time.
The only remaining detail is how the transition
probabilities in Figure 8 were computed. Recall that
to get Figure 3, we asked what fraction of paths
passed through each state. This time we must ask
what fraction of paths traversed each arc. (Q: How
to compute this?27) Just as there were two possible
states each day, there are four possible arcs each day,
and the graph reflects their relative probabilities.
</bodyText>
<sectionHeader confidence="0.833209" genericHeader="method">
9 Reestimation Experiments
</sectionHeader>
<bodyText confidence="0.718716">
We can check whether the algorithm still learns from
other initial guesses. The following examples appear
on the spreadsheet and can be copied over the table
</bodyText>
<listItem confidence="0.767436272727273">
of initial probabilities. (Except for the pathologi-
cally symmetric third case, they all learn the same
structure.)
1. No weather inertia, but more ice cream on hot
days. The model initially behaves as in foot-
27A: The total probability of all paths traversing q --+ r is
a(q) * p(q — r) *β(r).
Figure 10: The effect of reestimation on Figure 9.
note 15, but over time it learns that weather does
have inertia.
2. Inertia, but only a very slight preference for more
</listItem>
<bodyText confidence="0.78938625">
ice cream on hot days. The pi(H) graph is ini-
tially almost as flat as in footnote 17. But over
several passes the model learns that I eat a lot
more ice cream on hot days.
</bodyText>
<listItem confidence="0.9517578">
3. A completely symmetric initial state: no inertia,
and no preference at all for more ice cream on hot
days. Q: What do you expect to happen under
reestimation?28
4. Like the previous case, but break the symmetry
</listItem>
<bodyText confidence="0.953149533333333">
by giving cold days a slight preference to eat
more ice cream (Figure 12). This initial state is
almost perfectly symmetric. Q: Why doesn't this
case appear to learn the same structure as the pre-
vious ones?29
The final case does not converge to quite the same
result as the others: C and H are reversed. (It is
28A: Nothing changes, since the situation is too symmetric.
As H and C behave identically, there is nothing to differentiate
them and allow them to specialize.
29A: Actually it does; it merely requires more iterations to
converge. (The spreadsheet is only wide enough to hold 10 iter-
ations; to run for 10 more, just copy the final probabilities back
over the initial ones. Repeat as necessary.) It learns both inertia
and a preference for more ice cream on cold days.
</bodyText>
<figureCaption confidence="0.9989158">
Figure 11: Nine more passes of forward-backward reestimation
on Figures 9–10. Note that the final graph is even smoother than
Figure 3.
Figure 12: Breaking symmetry toward the opposite solution.
Figure 13: If T is the sequence of 34 training observations
</figureCaption>
<bodyText confidence="0.985217733333333">
(33 days plus Stop), then p(T) increases rapidly during rees-
timation. To compress the range of the graph, we don't plot
p(T) but rather perplexity per observation = 1/ 3�Ip(T) =
2-(log2 p(T))/34.
now H that is used for the low-ice-cream midsummer
days.) Should you care about this difference? As
climatologists, you might very well be upset that the
spreadsheet reversed cold and hot days. But since C
and H are ultimately just arbitrary labels, then per-
haps the outcome is equally good in some sense.
What does it mean for the outcome of this unsuper-
vised learning procedure to be "good"? The dataset
is just the ice cream diary, which makes no reference
to weather. Without knowing the true weather, how
can we tell whether we did a good job learning it?
</bodyText>
<sectionHeader confidence="0.938609" genericHeader="method">
10 Local Maximization of Likelihood
</sectionHeader>
<bodyText confidence="0.999172620689655">
The answer: A good model is one that predicts the
dataset as accurately as possible. The dataset actu-
ally has temporal structure, since I tended to have
long periods of high and low ice cream consump-
tion. That structure is what the algorithm discov-
ered, regardless of whether weather was the cause.
The state C or H distinguishes between the two kinds
of periods and tends to persist over time.
So did this learned model predict the dataset well?
It was not always sure about the state sequence,
but Figure 13 shows that the likelihood of the ob-
served dataset (summed over all possible state se-
quences) increased on every iteration. (Q: How is
this found?30)
That behavior is actually guaranteed: repeated
30It is the total probability of paths that explain the data, i.e.,
all paths in Figure 4, as given by column I of Figure 1; see
footnote 10.
forward-backward reestimation converges to a local
maximum of likelihood. We have already discov-
ered two symmetric local maxima, both with per-
plexity of 2.827 per day: the model might use C to
represent cold and H to represent hot, or vice versa.
Q: How much better is 2.827 than a model with no
temporal structure?31
Remember that maximizing the likelihood of the
training data can lead to overfitting. Q: Do you see
any evidence of this in the final probability table?32
Q: Is there a remedy?33
</bodyText>
<sectionHeader confidence="0.860269" genericHeader="method">
11 A Trick Ending
</sectionHeader>
<bodyText confidence="0.996222565217391">
We get very different results if we slightly mod-
ify Figure 12 by putting p(1 I H) = 0.3 with
p(2 I H) = 0.4. The structure of the solution is
very different (Figure 14). In fact, the final param-
eters now show anti-inertia, giving a reconstruction
similar to Figure 6b. Q: What went wrong?34
In the two previous local maxima, H meant "low
ice-cream day" or "high ice-cream day." Q: Accord-
ing to Figure 14, what does H mean here?35 Q: What
does the low value of p(H I H) mean?36
So we see that there are actually two kinds of
structure coexisting in this dataset: days with a lot
(little) ice cream tend to repeat, and days with 2 ice
creams tend not to repeat. The first kind of structure
did a better job of lowering the perplexity, but both
31A: A model with no temporal structure is a unigram model.
A good guess is that it will have perplexity 3, since it will be
completely undecided between the 3 kinds of observations. (It
so happens that they were equally frequent in the dataset.) How-
ever, if we prevent the learning of temporal structure (by setting
the initial conditions so that the model is always in state C, or is
always equally likely to be in states C and H), we find that the
perplexity is 3.314, reflecting the four-way unigram distribution
</bodyText>
<equation confidence="0.983893">
p(1) = p(2) = p(3) = 11/34, p(Stop)=1/34.
</equation>
<bodyText confidence="0.97669044">
32A: p(H I Start) --+ 1 because we become increasingly
sure that the training diary started on a hot day. But this single
training observation, no matter how justifiably certain we are of
it, might not generalize to next summer's diary.
33A: Smoothing the fractional counts. Note: If a prior is used
for smoothing, the algorithm is guaranteed to locally maximize
the posterior (in place of the likelihood).
34A: This is a third local maximum of likelihood, unrelated
to the others, with worse perplexity (3.059). Getting stuck in
poor local maxima is an occupational hazard.
35A: H usually emits 2 ice creams, whereas C never does. So
H stands for a 2-ice-cream day.
36A: That 2 ice creams are rarely followed by 2 ice creams.
Looking at the dataset, this is true. So even this local maximum
successfully discovered some structure: it discovered (to my
surprise) that when I make up data, I tend not to repeat 2's!
Figure 14: A suboptimal local maximum.
are useful. Q: How could we get our model to dis-
cover both kinds of structure (thereby lowering the
perplexity further)?37
Q: We have now seen three locally optimal mod-
els in which the H state was used for 3 different
things—even though we named it H for "Hot." What
does this mean for the application of this algorithm
to part-of-speech tagging?38
</bodyText>
<sectionHeader confidence="0.991368" genericHeader="method">
12 Follow-Up Assignment
</sectionHeader>
<bodyText confidence="0.999623851851852">
In a follow-up assignment, students applied Viterbi
decoding and forward-backward reestimation to
part-of-speech tagging. 39
In the assignment, students were asked to test
their code first on the ice cream data (provided as
a small tagged corpus) before switching to real data.
This cemented the analogy between the ice cream
and tagging tasks, helping students connect the class
to the assignment.
37A: Use more states. Four states would suffice to distinguish
hot/2, cold/2, hot/not2, and cold/not2 days.
38A: There is no guarantee that N and V will continue to dis-
tinguish nouns and verbs after reestimation. They will evolve to
make whatever distinctions help to predict the word sequence.
39Advanced students might also want to read about a mod-
ern supervised trigram tagger (Brants, 2000), or the mixed re-
sults when one actually trains trigram taggers by EM (Merialdo,
1994).
Furthermore, students could check their ice cream
output against the spreadsheet, and track down basic
bugs by comparing their intermediate results to the
spreadsheet's. They reported this to be very useful.
Presumably it helps learning when students actually
find their bugs before handing in the assignment, and
when they are able to isolate their misconceptions
on their own. It also made office hours and grading
much easier for the teaching assistant.
</bodyText>
<sectionHeader confidence="0.933452" genericHeader="conclusions">
13 Availability
</sectionHeader>
<bodyText confidence="0.973627">
The spreadsheet (in Microsoft Excel) and assign-
ment are available at http://www.cs.jhu.
edu/˜jason/papers/#tnlp02.
Also available is a second version of the spread-
sheet, which uses the Viterbi approximation for de-
coding and reestimation. The Viterbi algorithm is
implemented in an unconventional way so that the
two spreadsheets are almost identical; there is no
need to follow backpointers. The probability of the
best path through state H on day 3 is A3(H) • v3 (H),
where A and v are computed like a and Q but maxi-
mizing rather than summing path probabilities. The
Viterbi approximation treats p3 (H) as 1 or 0 accord-
ing to whether A3(H) • v3(H) equals max(A3(C)
</bodyText>
<equation confidence="0.775794">
v3 (C), A3 (H) • v3 (H)).
</equation>
<bodyText confidence="0.738608">
Have fun! Comments are most welcome.
</bodyText>
<sectionHeader confidence="0.972812" genericHeader="references">
References
</sectionHeader>
<reference confidence="0.957117">
L. E. Baum. 1972. An inequality and associated max-
imization technique in statistical estimation of proba-
bilistic functions of a Markov process. Inequalities, 3.
Thorsten Brants. 2000. TnT: A statistical part-of-speech
tagger. In Proc. ofANLP, Seattle.
K. W. Church. 1988. A stochastic parts program and noun
phrase parser for unrestricted text. Proc. ofANLP.
Steven J. DeRose. 1988. Grammatical category disam-
biguation by statistical optimization. Computational
Linguistics, 14(1):31–39.
Jason Eisner. 2002. Parameter estimation for probabilis-
tic finite-state transducers. In Proc. ofACL.
Steffen L. Lauritzen. 1995. The EM algorithm for graph-
ical association models with missing data. Computa-
tional Statistics and Data Analysis, 19:191–201.
Bernard Merialdo. 1994. Tagging English text with a
probabilistic model. Comp. Ling., 20(2):155–172.
Judea Pearl. 1988. Probabilistic Reasoning in Intelli-
gent Systems: Networks of Plausible Inference. Mor-
gan Kaufmann, San Mateo, California.
L. R. Rabiner. 1989. A tutorial on hidden Markov mod-
els and selected applications in speech recognition.
Proceedings ofIEEE, 77(2):257 –285, February.
</reference>
</variant>
</algorithm>
</algorithms>


text:
export * from "./extend-app.module";
export * from "./extend-app.component";


text:
#ifndef _SPC_REWRITER_H_
#define _SPC_REWRITER_H_

#include"simplifier.h"
#include"order.h"
#include"substitution_tree.h"
#include"spc_clause.h"
#include"spc_asserted_literals.h"
#include"sparse_use_list.h"

namespace spc {

    /**
       \brief Apply rewriting steps using demodulation rule:

       C[s] ==> C[sigma(r)]
       when

       l = r is a known equality (demodulator)
       sigma(l) = s
       sigma(l) > sigma(r)

       It also applies the following rules:

       - Duplicate literal deletion

       - Resolved literal deletion

       - Positive simplify reflect
       s = t,  (u[p <- sigma(s)] != u[p <- sigma(t)] or R)
       ==>
       R

       - Negative simplify reflect
       s != t  (sigma(s = t) or R)
       ===>
       R
    */
    class rewriter : public simplifier {
    protected:
        typedef sparse_use_list<expr, ptr_vector<clause> > clause_use_list;
        asserted_literals &       m_asserted_literals;
        order &                   m_order;
        family_id                 m_spc_fid;

        substitution              m_subst;
        substitution_tree         m_st; // index for potential demodulators left-hand-side
        clause_use_list           m_cls_use_list; // index for demodulators left-hand-side to equation.
        found_literals            m_found_literals;

        ptr_vector<justification> m_justifications;

        struct visitor : public st_visitor {
            ast_manager &     m_manager;
            order &           m_order;
            clause_use_list & m_cls_use_list;
            bool              m_found;
            clause *          m_clause;
            expr *            m_source;
            expr *            m_target;

            visitor(order & ord, substitution & subst, clause_use_list & ul):
                st_visitor(subst), m_manager(ord.get_manager()), m_order(ord), m_cls_use_list(ul) {
            }

            virtual bool operator()(expr * e);
        };

        unsigned                  m_max_scope_lvl; // maximal scope level used during rewrite.
        visitor                   m_visitor;

        proof * mk_demodulation_proof(expr * old_expr, expr * new_expr, proof * parent);

        bool demodulator(clause * cls) const;
        void insert(clause * cls, expr * source);
        void erase(clause * cls, expr * source);
        void reserve_vars(unsigned num_vars);
        void reserve_offsets(unsigned num_offsets);
        void save_justification(justification * j);

        void reduce_literal(literal const & l, literal & l_r, proof * & l_pr);

    public:
        rewriter(ast_manager & m, simplifier & s, order & ord, asserted_literals & al);
        virtual ~rewriter();

        /**
           \brief Insert clause into rewriter indexes
        */
        void insert(clause * cls);

        /**
           \brief Remove clause from rewriter indexes
        */
        void erase(clause * cls);

        clause * operator()(clause * cls);

        void reset();
    };
};

#endif /* _SPC_REWRITER_H_ */


text:
legitco.github.io
=================

Totally legit. 100%. For serious.


text:
FROM centos:7
MAINTAINER Jay Johnson <jay.p.h.johnson@gmail.com>

RUN yum install -y \
    python-pip \
    python-devel \
    wget \
    python-setuptools

RUN wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm -d && \
    yum localinstall mysql-community-release-el7-5.noarch.rpm -y && \
    yum install mysql-community-server -y && \
    rm mysql-community-release-el7-5.noarch.rpm && \
    yum clean all

RUN yum install -y MySQL-python epel-release

RUN yum update -y && yum install -y \
    autoconf \
    binutils \
    boost \
    boost-devel \
    build-essential \
    bzip2 \
    ca-certificates \
    cron \
    curl \
    curl-devel \
    emacs \
    fonts-dejavu \
    gcc \
    gcc-c++ \
    gfortran \
    git \
    hostname \
    jed \
    julia \
    libaio \
    libav-tools \
    libmysqlclient-dev \
    libnettle4 \
    libsm6 \
    libxml2-devel \
    libxrender1 \
    libxslt \
    libxslt-devel \
    locales \
    logrotate \
    llvm \
    llvm-devel \
    make \
    mariadb-server \
    mlocate \
    net-tools \
    pandoc \
    pcre-devel \
    perl \
    perl-devel \
    postgresql-devel \
    procps \
    pwgen \
    python-dev \
    python-devel \
    python-pip \
    python-setuptools \
    redis \
    rsyslog \
    sqlite \
    sqlite-devel \
    sudo \
    tar \
    telnet \
    texlive-fonts-extra \
    texlive-fonts-recommended \
    texlive-generic-recommended \
    texlive-latex-base \
    texlive-latex-extra \
    tree \
    unzip \
    vim \
    vim-enhanced \
    wget \
    which \
    freetype \
    freetype-devel \
    libpng \
    libpng-devel \
    libpng-devel \
    python-virtualenv \
    mariadb-devel \
    libattr-devel \
    openssh \
    openssh-client \
    openssl-devel \
    libpcap \
    libpcap-devel \
    tkinter \
    && yum clean all

RUN easy_install pip && \
    /usr/bin/pip install --upgrade pip && \
    /usr/bin/pip install --upgrade setuptools

# Environment Deployment Type
ENV ENV_DEPLOYMENT_TYPE DEV
ENV ENV_IN_DOCKER 1
ENV ENV_DEBUG_LOADING 0
ENV ENV_PROJ_DIR /opt/work
ENV ENV_DATA_DIR /opt/work/data
ENV ENV_DATA_SRC_DIR /opt/work/data/src
ENV ENV_DATA_DST_DIR /opt/work/data/dst
ENV ENV_SRC_DIR /opt/work/src
ENV ENV_THIRD_PARTY_DIR /opt/work/thirdparty
ENV ENV_CONFIGS_DIR /opt/work/configs
ENV ENV_CL_ENV_DIR /opt/work/env

# Allow running starters from outside the container
ENV ENV_BIN_DIR /opt/work/bins
ENV ENV_PRESTART_SCRIPT /opt/tools/pre-start.sh
ENV ENV_START_SCRIPT /opt/tools/start-services.sh
ENV ENV_POSTSTART_SCRIPT /opt/tools/post-start.sh
ENV ENV_CUSTOM_SCRIPT /opt/tools/custom-pre-start.sh
ENV ENV_DEFAULT_VENV /venv
ENV ENV_AWS_ACCESS_KEY NOT_A_REAL_KEY
ENV ENV_AWS_SECRET_KEY NOT_A_REAL_KEY
ENV ENV_SET_AS_PYTHONPATH /opt/work

ENV ENV_SSH_CREDS /opt/shared/.ssh
ENV ENV_GIT_CONFIG /opt/shared/.gitconfig
ENV ENV_AWS_CREDS /root/.aws/credentials
ENV ENV_AWS_PROFILE default

RUN mkdir -p -m 777 /opt \
    && mkdir -p -m 777 /opt/deps \
    && mkdir -p -m 777 /opt/work \
    && mkdir -p -m 777 /opt/work/bins \
    && mkdir -p -m 777 /opt/work/configs \
    && mkdir -p -m 777 /opt/work/data \
    && mkdir -p -m 777 /opt/work/data/dst \
    && mkdir -p -m 777 /opt/work/data/src \
    && mkdir -p -m 777 /opt/work/src \
    && mkdir -p -m 777 /opt/work/env \
    && mkdir -p -m 777 /opt/work/thirdparty \
    && mkdir -p -m 777 /opt/shared \
    && mkdir -p -m 777 /opt/tools \
    && touch /tmp/firsttimerunning

WORKDIR /opt/work

# Add the starters and installers:
ADD ./docker/ /opt/tools/

RUN chmod 777 /opt/tools/*.sh \
    && mv /opt/tools/python2 /opt/ \
    && chmod 777 /opt/python2

RUN pushd /opt/python2 && /opt/python2/install_confluent_platform.sh && popd

RUN virtualenv /venv && /opt/python2/install_pips.sh && /venv/bin/pip list

RUN /venv/bin/pip freeze > /opt/shared/python2-requirements.txt

# Add files to start default-locations
RUN cp /opt/tools/bashrc /root/.bashrc \
    && cp /opt/tools/vimrc /root/.vimrc \
    && cp /opt/tools/gitconfig /root/.gitconfig \
    && cp /opt/tools/pre-start.sh /usr/local/bin/ \
    && cp /opt/tools/start-container.sh /usr/local/bin/ \
    && cp /opt/tools/post-start.sh /usr/local/bin/ \
    && cp /opt/tools/custom-pre-start.sh /usr/local/bin/ \
    && cp /opt/tools/start-services.sh /usr/local/bin/ \
    && cp /opt/tools/start-container.sh /opt/start-container.sh \
    && cp /opt/start-container.sh /usr/local/bin/start-container.sh \
    && chmod 644 /root/.bashrc && chown root:root /root/.bashrc \
    && cat /opt/tools/inputrc >> /etc/inputrc

CMD [ "/opt/start-container.sh" ]


text:
WinWidgets
==========

A simple API for using the native window manager.