text:
// CollectionNode.java

package org.sf.cafebabe.gadget.classtree;

import org.sf.classfile.EntryCollection;

/**
 * This class represents collection node
 *
 * @version 1.0 02/06/2002
 * @author Alexander Shvets
 */
public class CollectionNode extends FolderNode {
  private EntryCollection entries;

  /**
   * Creates new entries collection node
   *
   * @param text the text that will be displayed on the node
   * @param entries the entries collection
   */
  public CollectionNode(String text, EntryCollection entries) {
    super(text);

    this.entries = entries;
  }

  /**
   * Gets the entries collection
   *
   * @return the entries collection
   */
  public EntryCollection getEntries() {
    return entries;
  }

}


text:
package org.jetbrains.java.decompiler.struct.gen;

public interface NewClassNameBuilder {
  String buildNewClassname(String className);
}

redpajama_set_name: RedPajamaGithub


text:
@implementation GrowlRemotePathway

- (BOOL) registerApplicationWithDictionary:(bycopy NSDictionary *)dict {
	if (enabled && [[GrowlPreferencesController sharedController] isGrowlServerEnabled]) {
		[super registerApplicationWithDictionary:dict];
		return YES;
	} else {
		return NO;
	}
}

- (oneway void) postNotificationWithDictionary:(bycopy NSDictionary *)dict {
	if (enabled) {
		[super postNotificationWithDictionary:dict];
	}
}

- (GrowlNotificationResult)resultOfPostNotificationWithDictionary:(bycopy NSDictionary *)notification {
	if(!enabled)
		return GrowlNotificationResultDisabled;
	return [super resultOfPostNotificationWithDictionary:notification];
}

#pragma mark -

@synthesize enabled;

@end


text:
<?php

namespace Helmut\Forms\Testing;

class DropdownTest extends FormTestCase {

	/** @test */
	public function it_can_be_rendered()
	{
		$form = $this->form();
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);
		$this->assertContains('<select name="foo"', $form->render());
		$this->assertContains('<option value="a">A</option>', $form->render());
		$this->assertContains('<option value="b">B</option>', $form->render());
		$this->assertContains('<option value="c">C</option>', $form->render());
	}

	/** @test */
	public function it_renders_a_default_value()
	{
		$form = $this->form();
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b');

		$this->assertContains('<option value="a">A</option>', $form->render());
		$this->assertContains('<option value="b" selected="selected">B</option>', $form->render());
		$this->assertContains('<option value="c">C</option>', $form->render());
	}

	/** @test */
	public function it_renders_model_values()
	{
		$form = $this->form();
		$form->defaults($this->model(['foo'=>'b']));
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);

		$this->assertContains('<option value="a">A</option>', $form->render());
		$this->assertContains('<option value="b" selected="selected">B</option>', $form->render());
		$this->assertContains('<option value="c">C</option>', $form->render());
	}

	/** @test */
	public function it_can_fill_model_values()
	{
		$model = $this->model(['foo'=>'']);

		$form = $this->form();
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b');
		$form->fill($model);

		$form->assertEquals($model->foo, 'b');
	}

	/** @test */
	public function it_provides_expected_values()
	{
		$form = $this->form();
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);

		$this->assertSame($form->get('foo'), '');
	}

	/** @test */
	public function it_provides_expected_default_values()
	{
		$form = $this->form();
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('c');

		$this->assertSame($form->get('foo'), 'c');
	}

	/** @test */
    public function it_validates_required()
    {
    	$this->assertValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); });

    	$this->assertNotValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->required(); });
	}

}


text:
"""
    User management
"""
from django.shortcuts import render, redirect
from django.core.urlresolvers import reverse
from django.contrib.auth import login, logout, authenticate
from django_remote_submission.tasks import copy_key_to_server

# Application-specific imports
from django.conf import settings
from users.view_util import fill_template_values

def perform_login(request):
    """
        Perform user authentication
    """
    user = None
    login_failure = None
    if request.method == 'POST':
        username = request.POST["username"]
        password = request.POST["password"]
        user = authenticate(username=username, password=password)
        # Handling of local testing
        if user is not None and settings.JOB_HANDLING_HOST == 'localhost':
            login_failure = ["You are running locally"]
            login(request, user)
        elif user is not None and not user.is_anonymous():
            try:
                copy_key_to_server(
                    username=username,
                    password=password,
                    hostname=settings.JOB_HANDLING_HOST,
                    port=settings.JOB_HANDLING_PORT,
                )
                login(request, user)
            except:
                login_failure = ["Could not connect to computing resource: it may be unavailable"]
        else:
            login_failure = ["Invalid username or password"]

    if request.user.is_authenticated():
        # If we came from a given page and just needed
        # authentication, go back to that page.
        if "next" in request.GET:
            redirect_url = request.GET["next"]
            return redirect(redirect_url)
        return redirect(reverse(settings.LANDING_VIEW))
    else:
        # Breadcrumbs
        breadcrumbs = "home › login" % reverse(settings.LANDING_VIEW)

        template_values = {'breadcrumbs': breadcrumbs,
                           'user_alert': login_failure}
        template_values = fill_template_values(request, **template_values)
        return render(request, 'users/authenticate.html', template_values)

def perform_logout(request):
    """
        Logout user
    """
    logout(request)
    return redirect(reverse(settings.LANDING_VIEW))


text:
require 'minitest'
require 'minitest/reporters'
require 'minitest/reporters/base_reporter'

module Minitest
  module Reporters
    require 'minitest/reporters/turn_again_reporter/version'

    # Reporter whose output more closely mimics the format of the turn gem.
    # Specifically:
    # 1. The status banner and time on the left, which removes the need to
    #    limit the length of test names to not risk mis-aligning status flags.
    # 2. Displays time as minutes:seconds, optionally with hours as well.
    # 3. Allows configuration of indentation for each test output. Turn uses
    #    4 spaces, and thus this was chosen as the default.
    #
    # Source is mostly a verbatim copy from minitest-reporter's
    # SpecReporter class. Was unable to simply subclass SpecReporter without
    # significant code gynmastics or metaprogramming unbecoming of a simple
    # library formatter. This mostly due to SpecReporter's necessary
    # calls to super within the #record method, mixed with unavoidable output.
    #
    # @see https://github.com/kern/minitest-reporters/blob/master/lib/minitest/reporters/spec_reporter.rb SpecReporter
    # @see https://github.com/TwP/turn turn
    class TurnAgainReporter < BaseReporter
      require 'ansi'
      include ANSI::Code
      include RelativePosition

      attr_reader :hours, :indent,
                  :pass_color, :fail_color, :error_color, :skip_color

      def initialize(options = {})
        options       = option_defaults.merge(options)
        @hours        = !!options.fetch(:hours)
        @indent       = options.fetch(:indent)
        @pass_color   = options.fetch(:pass_color)
        @fail_color   = options.fetch(:fail_color)
        @error_color  = options.fetch(:error_color)
        @skip_color   = options.fetch(:skip_color)
        super(options)
      end

      def option_defaults
        { hours:        false,
          indent:       4,
          pass_color:   :green,
          fail_color:   :red,
          error_color:  :yellow,
          skip_color:   :cyan,
        }
      end

      def start
        super
        puts('Started with run options %s' % options[:args])
        puts
      end

      def report
        super

        passed = count - (failures + errors + skips)

        puts('Finished in %.5fs' % total_time)
        puts
        print(bold { '%d tests' } % count)
        print(', ')
        print(send(report_passed_color)    { '%d passed' }   % passed)
        print(', ')
        print(send(report_failures_color)  { '%d failures' } % failures)
        print(', ')
        print(send(report_errors_color)    { '%d errors' }   % errors)
        print(', ')
        print(send(report_skips_color)     { '%d skips' }    % skips)
        print(', ')
        print('%d assertions' % assertions)
        puts
      end

      def print_colored_status(test)
        print_status = -> { pad_mark( result(test).to_s.upcase ) }
        if test.passed?
          print(send(pass_color,  &print_status))
        elsif test.skipped?
          print(send(skip_color,  &print_status))
        elsif test.error?
          print(send(error_color, &print_status))
        else
          print(send(fail_color,  &print_status))
        end
      end

      ##
      # To match the interface of printing of colors via methods with blocks.
      def no_color(&block)
        block.call
      end

      def record(test)
        super
        print (' ' * indent)
        print_colored_status(test)
        print format_time(test.time)
        print test.name
        puts
        if !test.skipped? && test.failure
          print_info(test.failure)
          puts
        end
      end

      ##
      # Divergence from Minitest::Reporters::SpecReporter is that here we are
      # printing the exception name with padding, so that it doesn't break the
      # visual flow/alignment of all the vertical, colored test result statuses.
      def print_info(e, name=true)
        print_with_info_padding("#{e.exception.class.to_s}: ") if name
        e.message.each_line { |line| print_with_info_padding(line) }

        # When e is a Minitest::UnexpectedError, the filtered backtrace is already part of the message printed out
        # by the previous line. In that case, and that case only, skip the backtrace output.
        unless e.is_a?(MiniTest::UnexpectedError)
          trace = filter_backtrace(e.backtrace)
          trace.each { |line| print_with_info_padding(line) }
        end
      end

protected ######################################################################

      def report_passed_color
        failures.zero? && errors.zero? ? pass_color : :no_color
      end

      def report_failures_color
        failures.zero? ? :no_color : fail_color
      end

      def report_errors_color
        errors.zero? ? :no_color : error_color
      end

      def report_skips_color
        skips.zero? ? :no_color : skip_color
      end

      def before_suite(suite)
        puts suite
      end

      def after_suite(suite)
        puts
      end

      def format_time(t)
        if hours
          ' (%02d:%02d:%06.3f) ' % [
            t.to_i / 3600,        # hours
            (t.to_i % 3600) / 60, # mins
            t % 60,               # seconds (kept as float)
          ]
        else
          ' (%02d:%06.3f) ' % [
            (t.to_i % 3600) / 60, # mins
            t % 60                # seconds (kept as float)
          ]
        end
      end

    end
  end
end


text:
var THREE

module.exports = function (three) {

  THREE = three // hack until three.js fixes multiple instantiation

  var LabelPlugin = {
  labels: [],
  init: function() {},
  add: function(l) {this.labels.push(l);},
  remove: function(l) {
    this.labels = this.labels.filter(function (label) {
      return label != l;
    });
  },
  update: function(l) {
    for (var i=0; i<this.labels.length; i++) {
    var currentLabel = this.labels[i]
      if (currentLabel.id = l.id) {
        currentLabel.content = l.content
      }
    }
  },
  render: function() {
    for (var i=0; i<this.labels.length; i++) {
      var args = Array.prototype.slice.call(arguments);
      this.labels[i].render.apply(this.labels[i], args);
    }
  }
};
  return LabelPlugin;

}


text:
using System.Collections.Generic;
using SimplCommerce.Infrastructure.Localization;
using SimplCommerce.Infrastructure.Modules;

namespace SimplCommerce.Infrastructure
{
    public static class GlobalConfiguration
    {
        public static IList<ModuleInfo> Modules { get; set; } = new List<ModuleInfo>();

        public static IList<Culture> Cultures { get; set; } = new List<Culture>();

        public static string DefaultCulture => "en-US";

        public static string WebRootPath { get; set; }

        public static string ContentRootPath { get; set; }

        public static IList<string> AngularModules { get; } = new List<string>();

        public static void RegisterAngularModule(string angularModuleName)
        {
            AngularModules.Add(angularModuleName);
        }
    }
}


text:
package com.viaversion.viaversion.api.type.types.minecraft;

import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;

public class OptionalComponentType extends Type<JsonElement> {

    public OptionalComponentType() {
        super(JsonElement.class);
    }

    @Override
    public JsonElement read(ByteBuf buffer) throws Exception {
        boolean present = buffer.readBoolean();
        return present ? Type.COMPONENT.read(buffer) : null;
    }

    @Override
    public void write(ByteBuf buffer, JsonElement object) throws Exception {
        if (object == null) {
            buffer.writeBoolean(false);
        } else {
            buffer.writeBoolean(true);
            Type.COMPONENT.write(buffer, object);
        }
    }
}


text:
namespace System.Net {

    using System.Collections;
    using System.Threading;
    using System.Globalization;
    using System.Net.NetworkInformation;
    using System.Text;

    internal struct HeaderVariantInfo {

        string m_name;
        CookieVariant m_variant;

        internal HeaderVariantInfo(string name, CookieVariant variant) {
            m_name = name;
            m_variant = variant;
        }

        internal string Name {
            get {
                return m_name;
            }
        }

        internal CookieVariant Variant {
            get {
                return m_variant;
            }
        }
    }

    //
    // CookieContainer
    //
    //  Manage cookies for a user (implicit). Based on RFC 2965
    //

    /// <devdoc>
    ///    <para>[To be supplied.]</para>
    /// </devdoc>
    [Serializable]
    public class CookieContainer {

        public const int DefaultCookieLimit = 300;
        public const int DefaultPerDomainCookieLimit = 20;
        public const int DefaultCookieLengthLimit = 4096;

        static readonly HeaderVariantInfo [] HeaderInfo = {
            new HeaderVariantInfo(HttpKnownHeaderNames.SetCookie,  CookieVariant.Rfc2109),
            new HeaderVariantInfo(HttpKnownHeaderNames.SetCookie2, CookieVariant.Rfc2965)
        };

    // fields

        Hashtable m_domainTable = new Hashtable();
        int m_maxCookieSize = DefaultCookieLengthLimit;
        int m_maxCookies = DefaultCookieLimit;
        int m_maxCookiesPerDomain = DefaultPerDomainCookieLimit;
        int m_count = 0;
        string  m_fqdnMyDomain = String.Empty;

    // constructors

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public CookieContainer() {
            string domain = IPGlobalProperties.InternalGetIPGlobalProperties().DomainName;
            if (domain != null && domain.Length > 1)
            {
                m_fqdnMyDomain = '.' + domain;
            }
            //Otherwise it will remain string.Empty
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public CookieContainer(int capacity) : this(){
            if (capacity <= 0) {
                throw new ArgumentException(SR.GetString(SR.net_toosmall), "Capacity");
            }
            m_maxCookies = capacity;
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public CookieContainer(int capacity, int perDomainCapacity, int maxCookieSize) : this(capacity) {
            if (perDomainCapacity != Int32.MaxValue && (perDomainCapacity <= 0 || perDomainCapacity > capacity)) {
                throw new ArgumentOutOfRangeException("perDomainCapacity", SR.GetString(SR.net_cookie_capacity_range, "PerDomainCapacity", 0, capacity));
            }
            m_maxCookiesPerDomain = perDomainCapacity;
            if (maxCookieSize <= 0) {
                throw new ArgumentException(SR.GetString(SR.net_toosmall), "MaxCookieSize");
            }
            m_maxCookieSize = maxCookieSize;
        }

    // properties

        /// <devdoc>
        ///    <para>Note that after shrinking the capacity Count can become greater than Capacity.</para>
        /// </devdoc>
        public int Capacity {
            get {
                return m_maxCookies;
            }
            set {
                if (value <= 0 || (value < m_maxCookiesPerDomain && m_maxCookiesPerDomain != Int32.MaxValue)) {
                    throw new ArgumentOutOfRangeException("value", SR.GetString(SR.net_cookie_capacity_range, "Capacity", 0, m_maxCookiesPerDomain));
                }
                if (value < m_maxCookies) {
                    m_maxCookies = value;
                    AgeCookies(null);
                }
                m_maxCookies = value;
            }
        }

        /// <devdoc>
        ///    <para>returns the total number of cookies in the container.</para>
        /// </devdoc>
        public int Count {
            get {
                return m_count;
            }
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int MaxCookieSize {
            get {
                return m_maxCookieSize;
            }
            set {
                if (value <= 0) {
                    throw new ArgumentOutOfRangeException("value");
                }
                m_maxCookieSize = value;
            }
        }

        /// <devdoc>
        ///    <para>After shrinking domain capacity each domain will less hold than new domain capacity</para>
        /// </devdoc>
        public int PerDomainCapacity {
            get {
                return m_maxCookiesPerDomain;
            }
            set {
                if (value <= 0 || (value > m_maxCookies && value != Int32.MaxValue)) {
                    throw new ArgumentOutOfRangeException("value");
                }
                if (value < m_maxCookiesPerDomain) {
                    m_maxCookiesPerDomain = value;
                    AgeCookies(null);
                }
                m_maxCookiesPerDomain = value;
            }
        }

    // methods

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>

        //This method will construct faked URI, Domain property is required for param.
        public void Add(Cookie cookie) {
            if (cookie == null) {
                throw new ArgumentNullException("cookie");
            }

            if (cookie.Domain.Length == 0) {
                throw new ArgumentException(SR.GetString(SR.net_emptystringcall), "cookie.Domain");
            }

            Uri uri;
            StringBuilder uriSb = new StringBuilder();

            // We cannot add an invalid cookie into the container.
            // Trying to prepare Uri for the cookie verification
            uriSb.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter);

            // If the original cookie has an explicitly set domain, copy it over
            // to the new cookie
            if (!cookie.DomainImplicit) {
                if (cookie.Domain[0] == '.') {
                    uriSb.Append("0");                  // Uri cctor should eat this, faked host.
                }
            }
            uriSb.Append(cookie.Domain);

            // Either keep Port as implici or set it according to original cookie
            if (cookie.PortList != null) {
                uriSb.Append(":").Append(cookie.PortList[0]);
            }

            // Path must be present, set to root by default
            uriSb.Append(cookie.Path);

            if (!Uri.TryCreate(uriSb.ToString(), UriKind.Absolute, out uri))
                throw new CookieException(SR.GetString(SR.net_cookie_attribute, "Domain", cookie.Domain));

            // We don't know cookie verification status -> re-create cookie and verify it
            Cookie new_cookie = cookie.Clone();
            new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true);

            Add(new_cookie, true);
        }

        private void AddRemoveDomain(string key, PathList value) {
            // Hashtable support multiple readers and one writer
            // Synchronize writers
            lock (m_domainTable.SyncRoot) {
                if (value == null) {
                    m_domainTable.Remove(key);
                }
                else {
                    m_domainTable[key] = value;
                }
            }
        }

        // This method is called *only* when cookie verification is done,
        // so unlike with public Add(Cookie cookie) the cookie is in sane condition
        internal void Add(Cookie cookie, bool throwOnError) {

            PathList pathList;

            if (cookie.Value.Length > m_maxCookieSize) {
                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_cookie_size, cookie.ToString(), m_maxCookieSize));
                }
                return;
            }

            try {

                lock (m_domainTable.SyncRoot)
                {
                    pathList = (PathList)m_domainTable[cookie.DomainKey];
                    if (pathList == null)
                    {
                        pathList = new PathList();
                        AddRemoveDomain(cookie.DomainKey, pathList);
                    }
                }
                int domain_count = pathList.GetCookiesCount();

                CookieCollection cookies;
                lock (pathList.SyncRoot)
                {
                    cookies = (CookieCollection)pathList[cookie.Path];

                    if (cookies == null)
                    {
                        cookies = new CookieCollection();
                        pathList[cookie.Path] = cookies;
                    }
                }

                if(cookie.Expired) {
                    //Explicit removal command (Max-Age == 0)
                    lock (cookies) {
                        int idx = cookies.IndexOf(cookie);
                        if (idx != -1) {
                            cookies.RemoveAt(idx);
                            --m_count;
                        }
                    }
                }
                else {
                    //This is about real cookie adding, check Capacity first
                    if (domain_count >= m_maxCookiesPerDomain && !AgeCookies(cookie.DomainKey)) {
                            return; //cannot age -> reject new cookie
                    }
                    else if (this.m_count >= m_maxCookies && !AgeCookies(null)) {
                            return; //cannot age -> reject new cookie
                    }

                    //about to change the collection
                    lock (cookies) {
                        m_count += cookies.InternalAdd(cookie, true);
                    }
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }

                if (throwOnError) {
                    throw new CookieException(SR.GetString(SR.net_container_add_cookie), e);
                }
            }
        }

        //
        // This function, once called, must delete at least one cookie
        // If there are expired cookies in given scope they are cleaned up
        // If nothing found the least used Collection will be found and removed
        // from the container.
        //
        // Also note that expired cookies are also removed during request preparation
        // (this.GetCookies method)
        //
        // Param. 'domain' == null means to age in the whole container
        //
        private bool AgeCookies(string domain) {

            // border case => shrinked to zero
            if(m_maxCookies == 0 || m_maxCookiesPerDomain == 0) {
                m_domainTable = new Hashtable();
                m_count = 0;
                return false;
            }

            int      removed = 0;
            DateTime oldUsed = DateTime.MaxValue;
            DateTime tempUsed;

            CookieCollection lruCc = null;
            string   lruDomain =  null;
            string   tempDomain = null;

            PathList pathList;
            int domain_count = 0;
            int itemp = 0;
            float remainingFraction = 1.0F;

            // the container was shrinked, might need additional cleanup for each domain
            if (m_count > m_maxCookies) {
                // Means the fraction of the container to be left
                // Each domain will be cut accordingly
                remainingFraction = (float)m_maxCookies/(float)m_count;

            }
            lock (m_domainTable.SyncRoot) {
                foreach (DictionaryEntry entry in m_domainTable) {
                    if (domain == null) {
                        tempDomain = (string) entry.Key;
                        pathList = (PathList) entry.Value;          //aliasing to trick foreach
                    }
                    else {
                        tempDomain = domain;
                        pathList = (PathList) m_domainTable[domain];
                    }

                    domain_count = 0;                             // cookies in the domain
                    lock (pathList.SyncRoot) {
                        foreach (CookieCollection cc in pathList.Values) {
                            itemp = ExpireCollection(cc);
                            removed += itemp;
                            m_count -= itemp;                      //update this container count;
                            domain_count += cc.Count;
                            // we also find the least used cookie collection in ENTIRE container
                            // we count the collection as LRU only if it holds 1+ elements
                            if (cc.Count > 0 && (tempUsed = cc.TimeStamp(CookieCollection.Stamp.Check)) < oldUsed) {
                                lruDomain = tempDomain;
                                lruCc = cc;
                                oldUsed = tempUsed;
                            }
                        }
                    }

                    // Check if we have reduced to the limit of the domain by expiration only
                    int min_count = Math.Min((int)(domain_count*remainingFraction), Math.Min(m_maxCookiesPerDomain, m_maxCookies)-1);
                    if (domain_count > min_count) {
                        //That case require sorting all domain collections by timestamp
                        Array cookies;
                        Array stamps;
                        lock (pathList.SyncRoot) {
                            cookies = Array.CreateInstance(typeof(CookieCollection), pathList.Count);
                            stamps = Array.CreateInstance(typeof(DateTime), pathList.Count);
                            foreach (CookieCollection cc in pathList.Values) {
                                stamps.SetValue(cc.TimeStamp(CookieCollection.Stamp.Check), itemp);
                                cookies.SetValue(cc, itemp);
                                ++itemp;
                            }
                        }
                        Array.Sort(stamps, cookies);

                        itemp = 0;
                        for (int i = 0; i < cookies.Length; ++i) {
                            CookieCollection cc = (CookieCollection)cookies.GetValue(i);

                            lock (cc) {
                                while (domain_count > min_count && cc.Count > 0) {
                                    cc.RemoveAt(0);
                                    --domain_count;
                                    --m_count;
                                    ++removed;
                                }
                            }
                            if (domain_count <= min_count ) {
                                break;
                            }
                        }

                        if (domain_count > min_count && domain != null) {
                            //cannot complete aging of explicit domain (no cookie adding allowed)
                            return false;
                        }
                    }
                }
            }

            // we have completed aging of specific domain
            if (domain != null) {
                return true;
            }

            //  The rest is  for entire container aging
            //  We must get at least one free slot.

            //Don't need to appy LRU if we already cleaned something
            if (removed != 0) {
                return true;
            }

            if (oldUsed == DateTime.MaxValue) {
            //Something strange. Either capacity is 0 or all collections are locked with cc.Used
                return false;
            }

            // Remove oldest cookies from the least used collection
            lock (lruCc) {
                while (m_count >= m_maxCookies && lruCc.Count > 0) {
                    lruCc.RemoveAt(0);
                    --m_count;
                }
            }
            return true;
        }

        //return number of cookies removed from the collection
        private int ExpireCollection(CookieCollection cc) {
            lock (cc) {
                int oldCount = cc.Count;
                int idx = oldCount-1;
                //Cannot use enumerator as we are going to alter collection
                while (idx >= 0) {
                    Cookie cookie = cc[idx];
                    if (cookie.Expired) {

                        cc.RemoveAt(idx);
                    }
                    --idx;
                }
                return oldCount - cc.Count;
            }
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>

        // <
        public void Add(CookieCollection cookies) {
            if (cookies == null) {
                throw new ArgumentNullException("cookies");
            }
            foreach (Cookie c in cookies) {
                Add(c);
            }
        }

        //
        // This will try (if needed) get the full domain name of the host given the Uri
        // NEVER call this function from internal methods with 'fqdnRemote' == NULL
        // Since this method counts security issue for DNS and hence will slow
        // the performance
        //
        internal bool IsLocalDomain(string host) {

            int dot = host.IndexOf('.');
            if (dot == -1) {
                // No choice but to treat it as a host on the local domain
                // This also covers 'localhost' and 'loopback'
                return true;
            }

            // quick test for usual case - loopback addresses for IPv4 and IPv6
            if ((host == "127.0.0.1") || (host == "::1") || (host == "0:0:0:0:0:0:0:1"))
            {
                return true;
            }

            // test domain membership
            if (string.Compare(m_fqdnMyDomain, 0, host, dot, m_fqdnMyDomain.Length, StringComparison.OrdinalIgnoreCase ) == 0)
            {
                return true;
            }

            // test for "127.###.###.###" without using regex
            string[] ipParts = host.Split('.');
            if (ipParts != null && ipParts.Length == 4 && ipParts[0] == "127")
            {
                int i;
                for (i = 1; i < 4; i++)
                {
                    switch (ipParts[i].Length)
                    {
                        case 3:
                            if (ipParts[i][2] < '0' || ipParts[i][2] > '9')
                            {
                                break;
                            }
                            goto case 2;

                        case 2:
                            if (ipParts[i][1] < '0' || ipParts[i][1] > '9')
                            {
                                break;
                            }
                            goto case 1;

                        case 1:
                            if (ipParts[i][0] < '0' || ipParts[i][0] > '9')
                            {
                                break;
                            }
                            continue;
                    }
                    break;
                }
                if (i == 4)
                {
                    return true;
                }
            }

            return false;
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void Add(Uri uri, Cookie cookie) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            if(cookie == null) {
                throw new ArgumentNullException("cookie");
            }
            Cookie new_cookie = cookie.Clone();
            new_cookie.VerifySetDefaults(new_cookie.Variant, uri, IsLocalDomain(uri.Host), m_fqdnMyDomain, true, true);

            Add(new_cookie, true);

        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>

        public void Add(Uri uri, CookieCollection cookies) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            if(cookies == null) {
                throw new ArgumentNullException("cookies");
            }
            bool isLocalDomain = IsLocalDomain(uri.Host);
            foreach (Cookie c in cookies) {
                Cookie new_cookie = c.Clone();
                new_cookie.VerifySetDefaults(new_cookie.Variant, uri, isLocalDomain, m_fqdnMyDomain, true, true);
                Add(new_cookie, true);
            }
        }

        internal CookieCollection CookieCutter(Uri uri, string headerName, string setCookieHeader, bool isThrow) {
            GlobalLog.Print("CookieContainer#" + ValidationHelper.HashString(this) + "::CookieCutter() uri:" + uri + " headerName:" + headerName + " setCookieHeader:" + setCookieHeader + " isThrow:" + isThrow);
            CookieCollection cookies = new CookieCollection();
            CookieVariant variant = CookieVariant.Unknown;
            if (headerName == null) {
                variant = CookieVariant.Default;
            }
            else for (int i = 0; i < HeaderInfo.Length; ++i) {
                if ((String.Compare(headerName, HeaderInfo[i].Name, StringComparison.OrdinalIgnoreCase ) == 0)) {
                    variant  = HeaderInfo[i].Variant;
                }
            }
            bool isLocalDomain = IsLocalDomain(uri.Host);
            try {
                CookieParser parser = new CookieParser(setCookieHeader);
                do {
                    Cookie cookie = parser.Get();
                    GlobalLog.Print("CookieContainer#" + ValidationHelper.HashString(this) + "::CookieCutter() CookieParser returned cookie:" + ValidationHelper.ToString(cookie));
                    if (cookie == null) {
                        break;
                    }

                    //Parser marks invalid cookies this way
                    if (ValidationHelper.IsBlankString(cookie.Name)) {
                        if(isThrow) {
                            throw new CookieException(SR.GetString(SR.net_cookie_format));
                        }
                        //Otherwise, ignore (reject) cookie
                        continue;
                    }

                    // this will set the default values from the response URI
                    // AND will check for cookie validity
                    if(!cookie.VerifySetDefaults(variant, uri, isLocalDomain, m_fqdnMyDomain, true, isThrow)) {
                        continue;
                    }
                    // If many same cookies arrive we collapse them into just one, hence setting
                    // parameter isStrict = true below
                    cookies.InternalAdd(cookie, true);

                } while (true);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }

                if(isThrow) {
                    throw new CookieException(SR.GetString(SR.net_cookie_parse_header, uri.AbsoluteUri), e);
                }
            }

            foreach (Cookie c in cookies) {
                Add(c, isThrow);
            }

            return cookies;
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public CookieCollection GetCookies(Uri uri) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            return InternalGetCookies(uri);
        }

        internal CookieCollection InternalGetCookies(Uri uri) {

            bool isSecure = (uri.Scheme == Uri.UriSchemeHttps);
            int  port = uri.Port;
            CookieCollection cookies = new CookieCollection();
            ArrayList nameKeys = new ArrayList();
            int firstCompatibleVersion0SpecKey = 0;

            string fqdnRemote = uri.Host;

            int dot = fqdnRemote.IndexOf('.');
            if (dot == -1) {
                // DNS.resolve may return short names even for other inet domains ;-(
                // We _don't_ know what the exact domain is, so try also grab short hostname cookies.
                nameKeys.Add(fqdnRemote);
                // add a preceding dot (null host)
                nameKeys.Add("." + fqdnRemote);
                // grab long name from the local domain
                if (m_fqdnMyDomain != null && m_fqdnMyDomain.Length != 0) {
                    nameKeys.Add(fqdnRemote + m_fqdnMyDomain);
                    // grab the local domain itself
                    nameKeys.Add(m_fqdnMyDomain);
                    firstCompatibleVersion0SpecKey = 3;
                }
                else {
                    firstCompatibleVersion0SpecKey = 1;
                }
            }
            else {
                // grab the host itself
                nameKeys.Add(fqdnRemote);
                // add a preceding dot (null host)
                nameKeys.Add("." + fqdnRemote);
                // grab the host domain
                nameKeys.Add(fqdnRemote.Substring(dot));
                firstCompatibleVersion0SpecKey = 2;
                // The following block is only for compatibility with Version0 spec.
                // Still, we'll add only Plain-Variant cookies if found under below keys
                if (fqdnRemote.Length > 2) {
                    // We ignore the '.' at the end on the name
                    int last = fqdnRemote.LastIndexOf('.', fqdnRemote.Length-2);
                    //AND keys with <2 dots inside.
                    if (last > 0) {
                        last = fqdnRemote.LastIndexOf('.', last-1);
                    }
                    if (last != -1) {
                        while ((dot < last) && (dot = fqdnRemote.IndexOf('.', dot+1)) != -1) {
                            nameKeys.Add(fqdnRemote.Substring(dot));
                        }
                    }
                }
            }

            foreach (string key in nameKeys) {
                bool found = false;
                bool defaultAdded = false;
                PathList pathList;
                lock (m_domainTable.SyncRoot) {
                    pathList = (PathList)m_domainTable[key];
                }
                --firstCompatibleVersion0SpecKey;

                if (pathList == null) {
                    continue;
                }

                lock (pathList.SyncRoot) {
                    foreach (DictionaryEntry entry in pathList) {
                        string path = (string)entry.Key;
                        if (uri.AbsolutePath.StartsWith(CookieParser.CheckQuoted(path))) {
                            found = true;

                            CookieCollection cc = (CookieCollection)entry.Value;
                            cc.TimeStamp(CookieCollection.Stamp.Set);
                            MergeUpdateCollections(cookies, cc, port, isSecure, (firstCompatibleVersion0SpecKey<0));

                            if (path == "/") {
                                defaultAdded = true;
                            }
                        }
                        else if (found) {
                            break;
                        }
                    }
                }

                if (!defaultAdded) {
                    CookieCollection cc = (CookieCollection)pathList["/"];

                    if (cc != null) {
                        cc.TimeStamp(CookieCollection.Stamp.Set);
                        MergeUpdateCollections(cookies, cc, port, isSecure, (firstCompatibleVersion0SpecKey<0));
                    }
                }

                // Remove unused domain
                // (This is the only place that does domain removal)
                if(pathList.Count == 0) {
                    AddRemoveDomain(key, null);
                }
            }
            return cookies;
        }

        private void MergeUpdateCollections(CookieCollection destination, CookieCollection source, int port, bool isSecure, bool isPlainOnly) {

            // we may change it
            lock (source) {

                //cannot use foreach as we going update 'source'
                for (int idx = 0 ; idx < source.Count; ++idx) {
                    bool to_add = false;

                    Cookie cookie = source[idx];

                    if (cookie.Expired) {
                        //If expired, remove from container and don't add to the destination
                        source.RemoveAt(idx);
                        --m_count;
                        --idx;
                    }
                    else {
                        //Add only if port does match to this request URI
                        //or was not present in the original response
                        if(isPlainOnly && cookie.Variant != CookieVariant.Plain) {
                            ;//don;t add
                        }
                        else if(cookie.PortList != null)
                        {
                            foreach (int p in cookie.PortList) {
                                if(p == port) {
                                    to_add = true;
                                    break;
                                }
                            }
                        }
                        else {
                            //it was implicit Port, always OK to add
                            to_add = true;
                        }

                        //refuse adding secure cookie into 'unsecure' destination
                        if (cookie.Secure && !isSecure) {
                            to_add = false;
                        }

                        if (to_add) {
                            // In 'source' are already orederd.
                            // If two same cookies come from dif 'source' then they
                            // will follow (not replace) each other.
                            destination.InternalAdd(cookie, false);
                        }

                    }
                }
            }
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public string GetCookieHeader(Uri uri) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            string dummy;
            return GetCookieHeader(uri, out dummy);

        }

        internal string GetCookieHeader(Uri uri, out string optCookie2) {
            CookieCollection cookies = InternalGetCookies(uri);
            string cookieString = String.Empty;
            string delimiter = String.Empty;

            foreach (Cookie cookie in cookies) {
                cookieString += delimiter + cookie.ToString();
                delimiter = "; ";
            }
            optCookie2 = cookies.IsOtherVersionSeen ?
                          (Cookie.SpecialAttributeLiteral +
                           Cookie.VersionAttributeName +
                           Cookie.EqualsLiteral +
                           Cookie.MaxSupportedVersion.ToString(NumberFormatInfo.InvariantInfo)) : String.Empty;

            return cookieString;
        }

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>

        //<

        public void SetCookies(Uri uri, string cookieHeader) {
            if (uri == null) {
                throw new ArgumentNullException("uri");
            }
            if(cookieHeader == null) {
                throw new ArgumentNullException("cookieHeader");
            }
            CookieCutter(uri, null, cookieHeader, true); //will throw on error
        }
    }

    [Serializable]
    internal class PathList {
        SortedList m_list = (SortedList.Synchronized(new SortedList(PathListComparer.StaticInstance)));

        public PathList() {
        }

        public int Count {
            get {
                return m_list.Count;
            }
        }

        public int GetCookiesCount() {
            int count = 0;
            lock (SyncRoot) {
                foreach (CookieCollection cc in  m_list.Values) {
                    count += cc.Count;
                }
            }
            return count;
        }

        public ICollection Values {
            get {
                return m_list.Values;
            }
        }

        public object this[string s] {
            get {
                return m_list[s];
            }
            set {
                lock (SyncRoot) {
                    m_list[s] = value;
                }
            }
        }

        public IEnumerator GetEnumerator() {
            return m_list.GetEnumerator();
        }

        public object SyncRoot {
            get {
                return m_list.SyncRoot;
            }
        }

        [Serializable]
        class PathListComparer : IComparer {
            internal static readonly PathListComparer StaticInstance = new PathListComparer();

            int IComparer.Compare(object ol, object or) {

                string pathLeft = CookieParser.CheckQuoted((string)ol);
                string pathRight = CookieParser.CheckQuoted((string)or);
                int ll = pathLeft.Length;
                int lr = pathRight.Length;
                int length = Math.Min(ll, lr);

                for (int i = 0; i < length; ++i) {
                    if (pathLeft[i] != pathRight[i]) {
                        return pathLeft[i] - pathRight[i];
                    }
                }
                return lr - ll;
            }
        }
    }
}


text:
import os
from setuptools import setup, find_packages

try:
    import pypandoc
    long_description = pypandoc.convert('README.md', 'rst')
except (IOError, ImportError):
    long_description = 'Thumbor redis-tornado storage adapters'

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name="tc_redis_tornado",
    version="1.0.1",
    author="Thumbor Community",
    description=("Thumbor redis-tornado storage adapters"),
    license="MIT",
    keywords="thumbor redis tornado",
    url="https://github.com/thumbor-community/redis-tornado",
    packages=find_packages(),
    long_description=long_description,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 2.7',
    ],
    install_requires=[
        'thumbor>=5.2.0',
        'redis'
    ]
)


text:
<title>U toku je održavanje web stranice -Discourse.org</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Trenutno ne radimo zbog planiranog održavanja web stranice.

Molimo provjerite opet  za nekoliko minuta

Oprostite na smetnji!


text:
===============================
Software that Enhances *behave*
===============================

Mock

nose.tools and nose.twistedtools

mechanize for pretending to be a browser

selenium webdriver for actually driving a browser

wsgi_intercept for providing more easily testable WSGI servers

BeautifulSoup, lxml and html5lib for parsing HTML

Django-behave, for integration into Django's test framework
https://github.com/rwillmer/django-behave

...?


text:
//
//  NSString+Helper.m
//  BioMonitor
//
//  Created by Mannie Tagarira on 18/11/2010.
//  Copyright 2010 University of Manchester. All rights reserved.
//

#import "AppImports.h"

@implementation NSString (Helper)

typedef enum {
  CMJanuary = 1,
  CMFebruary,
  CMMarch,
  CMApril,
  CMMay,
  CMJune,
  CMJuly,
  CMAugust,
  CMSeptember,
  CMOctober,
  CMNovember,
  CMDecember,
} CalendarMonth;

-(NSString *) stringForCalendarMonth:(CalendarMonth)monthNumber {
  switch (monthNumber) {
    case CMJanuary: return @"January";
    case CMFebruary: return @"February";
    case CMMarch: return @"March";
    case CMApril: return @"April";
    case CMMay: return @"May";
    case CMJune: return @"June";
    case CMJuly: return @"July";
    case CMAugust: return @"August";
    case CMSeptember: return @"September";
    case CMOctober: return @"October";
    case CMNovember: return @"November";
    case CMDecember: return @"December";
    default: return @"Unknown month";
  }
}

-(BOOL) isValidJSONValue {
  BOOL isNull = [self isEqual:[NSNull null]] || [self isEqualToString:JSONNull];

  NSArray *components = [self componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF != %@", @""];
  BOOL isWhiteSpace = [[components filteredArrayUsingPredicate:predicate] count] == 0;

  return !isNull && !isWhiteSpace;
} // isValidJSONValue

-(BOOL) isValidQuery {
  NSString *deURLizedQuery = [self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  deURLizedQuery = [deURLizedQuery stringByReplacingOccurrencesOfString:@" " withString:@""];

  if ([deURLizedQuery length] == 0) {
    return NO;
  }

  if ([[deURLizedQuery componentsSeparatedByCharactersInSet:[NSCharacterSet punctuationCharacterSet]] count] > 1) {
    return NO;
  }

  if ([[deURLizedQuery componentsSeparatedByCharactersInSet:[NSCharacterSet symbolCharacterSet]] count] > 1) {
    return NO;
  }

  return YES;
} // isValidQuery

-(BOOL) isValidEmailAddress {
  /*
   This code was insprired by the DHValidation module by Ben McRedmond;
   http://github.com/benofsky/DHValidation/blob/master/DHValidation.m
   */

  NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
  NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];

  return [emailTest evaluateWithObject:self];
} // isValidEmailAddress

-(BOOL) isRegistryName {
  NSString *name = [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

  BOOL isFeta = [name isEqualToString:@"Feta"];
  BOOL isEMBRACE = [name isEqualToString:@"The EMBRACE Registry"];
  BOOL isSeekDa = [name isEqualToString:@"SeekDa"];

  return isFeta || isEMBRACE || isSeekDa;
} // isRegistryName

-(NSString *) stringByAddingPercentEscapes {
  NSString *processedString = [self stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  processedString = [processedString stringByReplacingOccurrencesOfString:@"@" withString:@"\%40"];
  return processedString;
} // stringByAddingPercentEscapes

-(NSString *) stringByReformattingJSONDate:(BOOL)includeTime {
  NSArray *dateComponents = [self componentsSeparatedByCharactersInSet:[NSCharacterSet letterCharacterSet]];

  NSString *time = ([dateComponents count] > 2 ? [dateComponents objectAtIndex:1] : nil);

  dateComponents = [[dateComponents objectAtIndex:0] componentsSeparatedByCharactersInSet:[NSCharacterSet punctuationCharacterSet]];

  NSString *date = [NSString stringWithFormat:@"%@ %@ %@",
                    [dateComponents lastObject],
                    [self stringForCalendarMonth:[[dateComponents objectAtIndex:1] intValue]],
                    [dateComponents objectAtIndex:0]];

  if (includeTime && time) {
    return [NSString stringWithFormat:@"%@ at %@", date, time];
  } else {
    return date;
  }
} // stringByReformattingJSONDate

-(NSString *) printableResourceScope {
  if ([self isEqualToString:RESTEndpointResourceScope]) {
    return [RESTComponentsText stringByReplacingCharactersInRange:NSMakeRange([RESTComponentsText length] - 1, 1) withString:@""];
  } else if ([self isEqualToString:SOAPOperationResourceScope]) {
    return [SOAPComponentsText stringByReplacingCharactersInRange:NSMakeRange([SOAPComponentsText length] - 1, 1) withString:@""];
  } else if ([self isEqualToString:AnnouncementResourceScope]) {
    return @"Announcement";
  } else if ([self isEqualToString:ServiceResourceScope]) {
    return @"Web Service";
  } else if ([self isEqualToString:UserResourceScope]) {
    return @"User";
  } else {
    return nil;
  }
} // printableBioCatalogueResourceScope

+(NSString *) generateInterestedInMessage:(NSString *)resource withURL:(NSURL *)url {
  return [NSString stringWithFormat:@"This%@ may interest you:\n\n%@\n\n\n", [resource lowercaseString], [url absoluteString]];
}

@end


text:
package fi.jumi.daemon;

import fi.jumi.actors.eventizers.Event;
import fi.jumi.actors.queue.MessageSender;
import fi.jumi.core.api.SuiteListener;
import fi.jumi.core.config.SuiteConfiguration;
import fi.jumi.core.events.SuiteListenerEventizer;
import fi.jumi.core.ipc.IpcCommandSender;
import fi.jumi.core.ipc.api.RequestListener;
import fi.jumi.core.ipc.channel.*;
import fi.jumi.core.ipc.dirs.*;
import fi.jumi.core.ipc.encoding.SuiteListenerEncoding;
import fi.jumi.core.network.*;
import fi.jumi.core.suite.SuiteFactory;
import fi.jumi.core.util.timeout.*;

import javax.annotation.concurrent.ThreadSafe;
import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.*;

@ThreadSafe
public class DaemonNetworkEndpoint implements NetworkEndpoint<Event<RequestListener>, Event<SuiteListener>>, RequestListener {

    // TODO: remove this class

    private final SuiteFactory suiteFactory;
    private final Runnable shutdownHook;
    private final Timeout startupTimeout;
    private final DaemonDir daemonDir;
    private final VacancyTimeout connections;
    private final ExecutorService executor = Executors.newCachedThreadPool();

    private MessageSender<Event<SuiteListener>> sender;

    public DaemonNetworkEndpoint(SuiteFactory suiteFactory, Runnable shutdownHook, Timeout startupTimeout, Timeout idleTimeout, DaemonDir daemonDir) {
        this.suiteFactory = suiteFactory;
        this.shutdownHook = shutdownHook;
        this.startupTimeout = startupTimeout;
        this.daemonDir = daemonDir;
        this.connections = new VacancyTimeout(idleTimeout);
    }

    @Override
    public void onConnected(NetworkConnection connection, MessageSender<Event<SuiteListener>> sender) {
        this.sender = sender;
        startupTimeout.cancel();
        connections.checkIn();
    }

    @Override
    public void onDisconnected() {
        connections.checkOut();
    }

    @Override
    public void onMessage(Event<RequestListener> message) {
        message.fireOn(this);
    }

    @Override
    public void runTests(SuiteConfiguration suite) {
        SuiteListener suiteListener = new SuiteListenerEventizer().newFrontend(sender);
//        suiteFactory.configure(suite);
//        suiteFactory.start(suiteListener);

        // XXX: routing the commands through IPC to make sure that IPC works
        try {
            CommandDir commandDir = daemonDir.createCommandDir();
            IpcCommandSender sender = new IpcCommandSender(commandDir, executor);
            Future<Path> suiteResults = sender.runTests(suite);
            sender.close();

            executor.execute(() -> {
                try {
                    IpcReader<SuiteListener> suiteReader = IpcChannel.reader(suiteResults.get(), SuiteListenerEncoding::new);
                    IpcReaders.decodeAll(suiteReader, suiteListener);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                    throw new RuntimeException(e);
                }
            });

        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    @Override
    public void shutdown() {
//        shutdownHook.run();

        // XXX: routing the commands through IPC to make sure that IPC works
        try {
            CommandDir commandDir = daemonDir.createCommandDir();
            IpcCommandSender sender = new IpcCommandSender(commandDir, executor);
            sender.shutdown();
            sender.close();

        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
}


text:
#include <exception>
#include "tinythread.h"
#include "umundo/Debug.h"

#if defined(_TTHREAD_POSIX_)
#include <unistd.h>
#include <map>
#elif defined(_TTHREAD_WIN32_)
#include <process.h>
#endif

#ifndef WITH_CXX11

namespace umundo {

namespace tthread {

//------------------------------------------------------------------------------
// condition_variable
//------------------------------------------------------------------------------
// NOTE 1: The Win32 implementation of the condition_variable class is based on
// the corresponding implementation in GLFW, which in turn is based on a
// description by Douglas C. Schmidt and Irfan Pyarali:
// http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
//
// NOTE 2: Windows Vista actually has native support for condition variables
// (InitializeConditionVariable, WakeConditionVariable, etc), but we want to
// be portable with pre-Vista Windows versions, so TinyThread++ does not use
// Vista condition variables.
//------------------------------------------------------------------------------

#if defined(_TTHREAD_WIN32_)
#define _CONDITION_EVENT_ONE 0
#define _CONDITION_EVENT_ALL 1
#endif

#if defined(_TTHREAD_WIN32_)
condition_variable::condition_variable() : mWaitersCount(0) {
	mEvents[_CONDITION_EVENT_ONE] = CreateEvent(NULL, FALSE, FALSE, NULL);
	mEvents[_CONDITION_EVENT_ALL] = CreateEvent(NULL, TRUE, FALSE, NULL);
	InitializeCriticalSection(&mWaitersCountLock);
}
#endif

#if defined(_TTHREAD_WIN32_)
condition_variable::~condition_variable() {
	CloseHandle(mEvents[_CONDITION_EVENT_ONE]);
	CloseHandle(mEvents[_CONDITION_EVENT_ALL]);
	DeleteCriticalSection(&mWaitersCountLock);
}
#endif

#if defined(_TTHREAD_WIN32_)
void condition_variable::_wait(unsigned int ms) {
	if (ms <= 0)
		ms = INFINITE;
	// Wait for either event to become signaled due to notify_one() or
	// notify_all() being called
	int result = WaitForMultipleObjects(2, mEvents, FALSE, ms);
	if (result == WAIT_FAILED) {
		LPVOID lpMsgBuf;
		FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
		              FORMAT_MESSAGE_FROM_SYSTEM |
		              FORMAT_MESSAGE_IGNORE_INSERTS,
		              NULL,
		              GetLastError(),
		              MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
		              (LPTSTR) &lpMsgBuf,
		              0,
		              NULL);
		UM_LOG_ERR("%s", lpMsgBuf);
		LocalFree(lpMsgBuf);

	}

	// Check if we are the last waiter
	EnterCriticalSection(&mWaitersCountLock);
	-- mWaitersCount;
	bool lastWaiter = (result == (WAIT_OBJECT_0 + _CONDITION_EVENT_ALL)) &&
	                  (mWaitersCount == 0);
	LeaveCriticalSection(&mWaitersCountLock);

	// If we are the last waiter to be notified to stop waiting, reset the event
	if(lastWaiter)
		ResetEvent(mEvents[_CONDITION_EVENT_ALL]);
}
#endif

#if defined(_TTHREAD_WIN32_)
void condition_variable::notify_one() {
	// Are there any waiters?
	EnterCriticalSection(&mWaitersCountLock);
	bool haveWaiters = (mWaitersCount > 0);
	LeaveCriticalSection(&mWaitersCountLock);

	// If we have any waiting threads, send them a signal
	if(haveWaiters)
		SetEvent(mEvents[_CONDITION_EVENT_ONE]);
}
#endif

#if defined(_TTHREAD_WIN32_)
void condition_variable::notify_all() {
	// Are there any waiters?
	EnterCriticalSection(&mWaitersCountLock);
	bool haveWaiters = (mWaitersCount > 0);
	LeaveCriticalSection(&mWaitersCountLock);

	// If we have any waiting threads, send them a signal
	if(haveWaiters)
		SetEvent(mEvents[_CONDITION_EVENT_ALL]);
}
#endif

//------------------------------------------------------------------------------
// POSIX pthread_t to unique thread::id mapping logic.
// Note: Here we use a global thread safe std::map to convert instances of
// pthread_t to small thread identifier numbers (unique within one process).
// This method should be portable across different POSIX implementations.
//------------------------------------------------------------------------------

#if defined(_TTHREAD_POSIX_)
static thread::id _pthread_t_to_ID(const pthread_t &aHandle) {
	static mutex idMapLock;
	static std::map<pthread_t, unsigned long int> idMap;
	static unsigned long int idCount(1);

	lock_guard<mutex> guard(idMapLock);
	if(idMap.find(aHandle) == idMap.end())
		idMap[aHandle] = idCount ++;
	return thread::id(idMap[aHandle]);
}
#endif // _TTHREAD_POSIX_

//------------------------------------------------------------------------------
// thread
//------------------------------------------------------------------------------

/// Information to pass to the new thread (what to run).
struct _thread_start_info {
	void (*mFunction)(void *); ///< Pointer to the function to be executed.
	void * mArg;               ///< Function argument for the thread function.
	thread * mThread;          ///< Pointer to the thread object.
};

// Thread wrapper function.
#if defined(_TTHREAD_WIN32_)
unsigned WINAPI thread::wrapper_function(void * aArg)
#elif defined(_TTHREAD_POSIX_)
void * thread::wrapper_function(void * aArg)
#endif
{
	// Get thread startup information
	_thread_start_info * ti = (_thread_start_info *) aArg;

	try {
		// Call the actual client thread function
		ti->mFunction(ti->mArg);
	} catch(...) {
		// Uncaught exceptions will terminate the application (default behavior
		// according to C++11)
		std::terminate();
	}

	// The thread is no longer executing
	lock_guard<mutex> guard(ti->mThread->mDataMutex);
	ti->mThread->mNotAThread = true;

	// The thread is responsible for freeing the startup information
	delete ti;

	return 0;
}

thread::thread(void (*aFunction)(void *), void * aArg) {
	// Serialize access to this thread structure
	lock_guard<mutex> guard(mDataMutex);

	// Fill out the thread startup information (passed to the thread wrapper,
	// which will eventually free it)
	_thread_start_info * ti = new _thread_start_info;
	ti->mFunction = aFunction;
	ti->mArg = aArg;
	ti->mThread = this;

	// The thread is now alive
	mNotAThread = false;

	// Create the thread
#if defined(_TTHREAD_WIN32_)
	mHandle = (HANDLE) _beginthreadex(0, 0, wrapper_function, (void *) ti, 0, &mWin32ThreadID);
#elif defined(_TTHREAD_POSIX_)
	if(pthread_create(&mHandle, NULL, wrapper_function, (void *) ti) != 0)
		mHandle = 0;
#endif

	// Did we fail to create the thread?
	if(!mHandle) {
		mNotAThread = true;
		delete ti;
	}
}

thread::~thread() {
	if(joinable())
		std::terminate();
}

void thread::join() {
	if(joinable()) {
#if defined(_TTHREAD_WIN32_)
		WaitForSingleObject(mHandle, INFINITE);
		CloseHandle(mHandle);
#elif defined(_TTHREAD_POSIX_)
		pthread_join(mHandle, NULL);
#endif
	}
}

bool thread::joinable() const {
	mDataMutex.lock();
	bool result = !mNotAThread;
	mDataMutex.unlock();
	return result;
}

void thread::detach() {
	mDataMutex.lock();
	if(!mNotAThread) {
#if defined(_TTHREAD_WIN32_)
		CloseHandle(mHandle);
#elif defined(_TTHREAD_POSIX_)
		pthread_detach(mHandle);
#endif
		mNotAThread = true;
	}
	mDataMutex.unlock();
}

thread::id thread::get_id() const {
	if(!joinable())
		return id();
#if defined(_TTHREAD_WIN32_)
	return id((unsigned long int) mWin32ThreadID);
#elif defined(_TTHREAD_POSIX_)
	return _pthread_t_to_ID(mHandle);
#endif
}

unsigned thread::hardware_concurrency() {
#if defined(_TTHREAD_WIN32_)
	SYSTEM_INFO si;
	GetSystemInfo(&si);
	return (int) si.dwNumberOfProcessors;
#elif defined(_SC_NPROCESSORS_ONLN)
	return (int) sysconf(_SC_NPROCESSORS_ONLN);
#elif defined(_SC_NPROC_ONLN)
	return (int) sysconf(_SC_NPROC_ONLN);
#else
	// The standard requires this function to return zero if the number of
	// hardware cores could not be determined.
	return 0;
#endif
}

//------------------------------------------------------------------------------
// this_thread
//------------------------------------------------------------------------------

thread::id this_thread::get_id() {
#if defined(_TTHREAD_WIN32_)
	return thread::id((unsigned long int) GetCurrentThreadId());
#elif defined(_TTHREAD_POSIX_)
	return _pthread_t_to_ID(pthread_self());
#endif
}
}
}
#endif


text:
require 'nokogiri'
require 'open-uri'
require 'sqlite3'

PWD = Dir.pwd

#
# Create any of the default docset file structure that we may need
#
def resetDocsetDir
  if Dir.exist? './Splunk.docset'
    `rm -Rf ./Splunk.docset`
  end

  Dir.mkdir('./Splunk.docset')
  Dir.mkdir('./Splunk.docset/Contents')
  Dir.mkdir('./Splunk.docset/Contents/Resources')
  Dir.mkdir('./Splunk.docset/Contents/Resources/Documents')

  # get icon.png file

  `wget http://www.splunk.com/content/dam/splunk2/images/icons/favicons/favicon-32x32.png -O ./Splunk.docset/icon.png`

  # copy Info.plist file
  `cp ./template/Info.plist ./Splunk.docset/Contents`
end

#
# create the sqlite index
#
def createSQLiteDB
  if File.exist? './Splunk.docset/Contents/Resources/docSet.dsidx'
    File.delete './Splunk.docset/Contents/Resources/docSet.dsidx'
  end
  db = SQLite3::Database.new './Splunk.docset/Contents/Resources/docSet.dsidx'

  db.execute 'CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);'
  db.execute 'CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);'
  return db
end

#
# Given an html file path, open it, parse it, clean it up,
# and overwirte the existing file.
#
def cleanupHtml(file)
  original = File.open(file)
  page = Nokogiri::HTML(original)
  original.close

  page.xpath('//comment()').each { |comment| comment.remove }

  page.css('#header').remove
  page.css('.bc_bg').remove
  page.css('.head_bg').remove

  page.css('.mainArticleHeader').remove
  page.css('.table_of_contents').remove

  sidebar = page.css('.wikiSidebarBox')[0]
  sidebar.parent.remove

  answers = page.css('#Answers')[0]
  if answers
    answersh2 = answers.parent
    if answersh2
      answersp = answersh2.next_element
      answersp.remove
    end
    answersh2.remove
  end

  page.css('.footer').remove
  page.css('#footerPagination').remove

  page.css('.affectedVersions').remove

  # write the new version
  articleFile = File.open(file,mode="w")
  articleFile.puts page.to_s
  articleFile.flush
  articleFile.close
  puts "saved cleaned up #{file}"
end

def main
  # delete the old dir and setup a new one
  resetDocsetDir

  db = createSQLiteDB

  Dir.chdir './Splunk.docset/Contents/Resources/Documents'

  # grab the list of search commands to be used as the default page for splunk docs
  listUrl = 'http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ListOfSearchCommands'
  listHtml = Nokogiri::HTML(open(listUrl))

  `wget -E -H -k -K -p -nc #{listUrl}`
  cleanupHtml("./docs.splunk.com/Documentation/Splunk/latest/SearchReference/ListOfSearchCommands.html")

  table = listHtml.css("table")[0]
  links = table.css("code a")

  # parse out all of the commands into urls for us to crawl
  commands = {}
  links.each do |l|
    commands[l.text] = l.attribute("href").value
  end

  # for each command, wget it, then clean it up
  commands.each do |command, url|
    `wget -E -H -k -K -p #{url}`

    # cleanup the tail end of the URL using
    base = './docs.splunk.com/Documentation/Splunk/6.2.2/SearchReference/'
    page = url.split('/').last
    path = base + page + '.html'
    cleanupHtml(path)

    # for each thing we want to link to, populate the sqlite index
    db.execute "INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES ('#{command}', 'Command', '#{path}');"
  end

  Dir.chdir PWD

  # # do any general cleanup inside the docset file structure
  #
  # f = File.open("list.html")
  # doc = Nokogiri::HTML(f)
  #
  # links = doc.xpath('//a')
  # sections = {}
  #
  # links.each do |l|
  #   sections[l.text] = l.attribute('href').value
  # end
end

main


text:
<BroadcastMonitor>
  <updated>2015-08-05T15:40:19</updated>
  <stationName>Radio 6</stationName>
  <Current>
    <startTime></startTime>
    <itemId></itemId>
    <titleId></titleId>
    <itemCode></itemCode>
    <itemReference></itemReference>
    <titleName></titleName>
    <artistName></artistName>
    <albumName></albumName>
    <CategoryCode></CategoryCode>
    <CategoryName></CategoryName>
    <itemDuration></itemDuration>
    <MultiMedia1></MultiMedia1>
    <MultiMedia2></MultiMedia2>
    <MultiMedia3></MultiMedia3>
    <MultiMedia4></MultiMedia4>
  </Current>
  <Next>
    <startTime>2015-08-05T15:40:18</startTime>
    <itemId>1000080540:0</itemId>
    <titleId>216113492</titleId>
    <itemCode></itemCode>
    <itemReference></itemReference>
    <titleName>*** JINGLE RUDY HAPPY</titleName>
    <artistName>RUDY</artistName>
    <albumName></albumName>
    <CategoryCode>832</CategoryCode>
    <CategoryName>VORMGEVING</CategoryName>
    <itemDuration>13</itemDuration>
    <MultiMedia1></MultiMedia1>
    <MultiMedia2></MultiMedia2>
    <MultiMedia3></MultiMedia3>
    <MultiMedia4></MultiMedia4>
  </Next>
</BroadcastMonitor>


text:
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include "../lib/libwebsockets.h"

#define LOCAL_RESOURCE_PATH INSTALL_DATADIR"/libwebsockets-test-server"

static int client;
static int terminate;

enum demo_protocols {
	PROTOCOL_FRAGGLE,

	/* always last */
	DEMO_PROTOCOL_COUNT
};

/* fraggle protocol */

enum fraggle_states {
	FRAGSTATE_START_MESSAGE,
	FRAGSTATE_RANDOM_PAYLOAD,
	FRAGSTATE_POST_PAYLOAD_SUM,
};

struct per_session_data__fraggle {
	int packets_left;
	int total_message;
	unsigned long sum;
	enum fraggle_states state;
};

static int
callback_fraggle(struct lws *wsi, enum lws_callback_reasons reason,
		 void *user, void *in, size_t len)
{
	int n;
	unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 8000 +
			  LWS_SEND_BUFFER_POST_PADDING];
	struct per_session_data__fraggle *psf = user;
	int chunk;
	int write_mode = LWS_WRITE_CONTINUATION;
	unsigned long sum;
	unsigned char *p = (unsigned char *)in;
	unsigned char *bp = &buf[LWS_SEND_BUFFER_PRE_PADDING];
	int ran;

	switch (reason) {

	case LWS_CALLBACK_ESTABLISHED:

		fprintf(stderr, "server sees client connect\n");
		psf->state = FRAGSTATE_START_MESSAGE;
		/* start the ball rolling */
		lws_callback_on_writable(wsi);
		break;

	case LWS_CALLBACK_CLIENT_ESTABLISHED:

		fprintf(stderr, "client connects to server\n");
		psf->state = FRAGSTATE_START_MESSAGE;
		break;

	case LWS_CALLBACK_CLIENT_RECEIVE:

		switch (psf->state) {

		case FRAGSTATE_START_MESSAGE:

			psf->state = FRAGSTATE_RANDOM_PAYLOAD;
			psf->sum = 0;
			psf->total_message = 0;
			psf->packets_left = 0;

			/* fallthru */

		case FRAGSTATE_RANDOM_PAYLOAD:

			for (n = 0; n < len; n++)
				psf->sum += p[n];

			psf->total_message += len;
			psf->packets_left++;

			if (lws_is_final_fragment(wsi))
				psf->state = FRAGSTATE_POST_PAYLOAD_SUM;
			break;

		case FRAGSTATE_POST_PAYLOAD_SUM:

			sum = ((unsigned int)p[0]) << 24;
			sum |= p[1] << 16;
			sum |= p[2] << 8;
			sum |= p[3];
			if (sum == psf->sum)
				fprintf(stderr, "EOM received %d correctly "
						"from %d fragments\n",
					psf->total_message, psf->packets_left);
			else
				fprintf(stderr, "**** ERROR at EOM: "
						"length %d, rx sum = 0x%lX, "
						"server says it sent 0x%lX\n",
					     psf->total_message, psf->sum, sum);

			psf->state = FRAGSTATE_START_MESSAGE;
			break;
		}
		break;

	case LWS_CALLBACK_SERVER_WRITEABLE:

		switch (psf->state) {

		case FRAGSTATE_START_MESSAGE:
			lws_get_random(lws_get_context(wsi), &ran, sizeof(ran));
			psf->packets_left = (ran % 1024) + 1;
			fprintf(stderr, "Spamming %d random fragments\n",
							     psf->packets_left);
			psf->sum = 0;
			psf->total_message = 0;
			write_mode = LWS_WRITE_BINARY;
			psf->state = FRAGSTATE_RANDOM_PAYLOAD;

			/* fallthru */

		case FRAGSTATE_RANDOM_PAYLOAD:

			/*
			 * note how one chunk can be 8000, but we use the
			 * default rx buffer size of 4096, so we exercise the
			 * code for rx spill because the rx buffer is full
			 */

			lws_get_random(lws_get_context(wsi), &ran, sizeof(ran));
			chunk = (ran % 8000) + 1;
			psf->total_message += chunk;

			lws_get_random(lws_get_context(wsi), bp, chunk);
			for (n = 0; n < chunk; n++)
				psf->sum += bp[n];

			psf->packets_left--;
			if (psf->packets_left)
				write_mode |= LWS_WRITE_NO_FIN;
			else
				psf->state = FRAGSTATE_POST_PAYLOAD_SUM;

			n = lws_write(wsi, bp, chunk, write_mode);
			if (n < 0)
				return -1;
			if (n < chunk) {
				lwsl_err("Partial write\n");
				return -1;
			}

			lws_callback_on_writable(wsi);
			break;

		case FRAGSTATE_POST_PAYLOAD_SUM:

			fprintf(stderr, "Spamming session over, "
					"len = %d. sum = 0x%lX\n",
						  psf->total_message, psf->sum);

			bp[0] = psf->sum >> 24;
			bp[1] = psf->sum >> 16;
			bp[2] = psf->sum >> 8;
			bp[3] = psf->sum;

			n = lws_write(wsi, (unsigned char *)bp,
							   4, LWS_WRITE_BINARY);
			if (n < 0)
				return -1;
			if (n < 4) {
				lwsl_err("Partial write\n");
				return -1;
			}

			psf->state = FRAGSTATE_START_MESSAGE;

			lws_callback_on_writable(wsi);
			break;
		}
		break;

	case LWS_CALLBACK_CLOSED:

		terminate = 1;
		break;

	/* because we are protocols[0] ... */

	case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED:
		if (strcmp(in, "deflate-stream") == 0) {
			fprintf(stderr, "denied deflate-stream extension\n");
			return 1;
		}
		break;

	default:
		break;
	}

	return 0;
}

/* list of supported protocols and callbacks */

static struct lws_protocols protocols[] = {
	{
		"fraggle-protocol",
		callback_fraggle,
		sizeof(struct per_session_data__fraggle),
	},
	{
		NULL, NULL, 0		/* End of list */
	}
};

static struct option options[] = {
	{ "help",	no_argument,		NULL, 'h' },
	{ "debug",	required_argument,	NULL, 'd' },
	{ "port",	required_argument,	NULL, 'p' },
	{ "ssl",	no_argument,		NULL, 's' },
	{ "interface",  required_argument,	NULL, 'i' },
	{ "client",	no_argument,		NULL, 'c' },
	{ NULL, 0, 0, 0 }
};

int main(int argc, char **argv)
{
	int n = 0;
	int port = 7681;
	int use_ssl = 0;
	struct lws_context *context;
	int opts = 0;
	char interface_name[128] = "";
	const char *iface = NULL;
	struct lws *wsi;
	const char *address;
	int server_port = port;
	struct lws_context_creation_info info;

	memset(&info, 0, sizeof info);

	fprintf(stderr, "libwebsockets test fraggle\n"
			"(C) Copyright 2010-2015 Andy Green <andy@warmcat.com> "
						    "licensed under LGPL2.1\n");

	while (n >= 0) {
		n = getopt_long(argc, argv, "ci:hsp:d:", options, NULL);
		if (n < 0)
			continue;
		switch (n) {
		case 'd':
			lws_set_log_level(atoi(optarg), NULL);
			break;
		case 's':
			use_ssl = 1;
			break;
		case 'p':
			port = atoi(optarg);
			server_port = port;
			break;
		case 'i':
			strncpy(interface_name, optarg, sizeof interface_name);
			interface_name[(sizeof interface_name) - 1] = '\0';
			iface = interface_name;
			break;
		case 'c':
			client = 1;
			fprintf(stderr, " Client mode\n");
			break;
		case 'h':
			fprintf(stderr, "Usage: libwebsockets-test-fraggle "
					"[--port=<p>] [--ssl] "
					"[-d <log bitfield>] "
					"[--client]\n");
			exit(1);
		}
	}

	if (client) {
		server_port = CONTEXT_PORT_NO_LISTEN;
		if (optind >= argc) {
			fprintf(stderr, "Must give address of server\n");
			return 1;
		}
	}

	info.port = server_port;
	info.iface = iface;
	info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
	info.extensions = lws_get_internal_extensions();
#endif
	if (use_ssl) {
		info.ssl_cert_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem";
		info.ssl_private_key_filepath = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.key.pem";
	}
	info.gid = -1;
	info.uid = -1;
	info.options = opts;

	context = lws_create_context(&info);
	if (context == NULL) {
		fprintf(stderr, "libwebsocket init failed\n");
		return -1;
	}

	if (client) {
		address = argv[optind];
		fprintf(stderr, "Connecting to %s:%u\n", address, port);
		wsi = lws_client_connect(context, address,
						   port, use_ssl, "/", address,
				 "origin", protocols[PROTOCOL_FRAGGLE].name,
								  -1);
		if (wsi == NULL) {
			fprintf(stderr, "Client connect to server failed\n");
			goto bail;
		}
	}

	n = 0;
	while (!n && !terminate)
		n = lws_service(context, 50);

	fprintf(stderr, "Terminating...\n");

bail:
	lws_context_destroy(context);

	return 0;
}


text:
package main

import (
	"fmt"

	"github.com/piotrkowalczuk/pqt"
)

type generator struct{}

func (g *generator) PropertyType(c *pqt.Column, m int32) string {
	if c.Type == pqt.TypeSerialBig() {
		if m == 1 {
			return "int64"
		}
	}
	return ""
}

func (g *generator) WhereClause(c *pqt.Column) string {
	if c.Type == pqt.TypeSerialBig() {
		return fmt.Sprintf(`
// %s is an empty struct, ignore
`, c.Name)
	}
	return ""
}

func (g *generator) ScanClause(_ *pqt.Column) string {
	return ""
}
func (g *generator) SetClause(_ *pqt.Column) string {
	return ""
}

func (g *generator) Static(_ *pqt.Schema) string {
	return ""
}


text:
package org.eclairjs.nashorn.wrap;

import org.eclairjs.nashorn.Utils;

import java.util.HashMap;
import java.util.Map;

public class Tuple5 extends WrappedClass {
    static WrappedFunction  F_1 = new WrappedFunction () {
        @Override
        public Object call(Object thiz, Object... args) {
            return ((Tuple5)thiz)._1;
        }
    };
    static WrappedFunction F_2  = new  WrappedFunction () {
        @Override
        public Object call(Object thiz, Object... args) {
            return ((Tuple5)thiz)._2;
        }
    };
    static WrappedFunction F_3  = new  WrappedFunction () {
        @Override
        public Object call(Object thiz, Object... args) {
            return ((Tuple5)thiz)._3;
        }
    };
    static WrappedFunction F_4  = new  WrappedFunction () {
        @Override
        public Object call(Object thiz, Object... args) {
            return ((Tuple5)thiz)._4;
        }
    };
    static WrappedFunction F_5  = new  WrappedFunction () {
        @Override
        public Object call(Object thiz, Object... args) {
            return ((Tuple5)thiz)._5;
        }
    };
    static Map<String,WrappedFunction> functions = new HashMap<>();

    static {
        functions.put("_1",F_1);
        functions.put("_2",F_2);
        functions.put("_3",F_3);
        functions.put("_4",F_4);
        functions.put("_5",F_5);
    }

    Object _1;
    Object _2;
    Object _3;
    Object _4;
    Object _5;
    public Tuple5(scala.Tuple5 tuple5) {
        _1=Utils.javaToJs(tuple5._1(),null);
        _2=Utils.javaToJs(tuple5._2(),null);
        _3=Utils.javaToJs(tuple5._3(),null);
        _4=Utils.javaToJs(tuple5._4(),null);
        _5=Utils.javaToJs(tuple5._5(),null);
    }

    public Tuple5(Object _1, Object _2, Object _3, Object _4, Object _5)  {
        this._1=Utils.javaToJs(_1);
        this._2=Utils.javaToJs(_2);
        this._3=Utils.javaToJs(_3);
        this._4=Utils.javaToJs(_4);
        this._5=Utils.javaToJs(_5);
    }

    static public String getModuleName() {
        return "Tuple5";
    }

    public Object getJavaObject() {
        return new scala.Tuple5(
            Utils.jsToJava(_1),
            Utils.jsToJava(_2),
            Utils.jsToJava(_3),
            Utils.jsToJava(_4),
            Utils.jsToJava(_5)
        );
    }

    @Override
    public String toJSON() {
        return "{\"0\":" + Utils.JsonStringify(_1) + ",\"1\":" + Utils.JsonStringify(_2) +
                ",\"2\":" + Utils.JsonStringify(_3) + ",\"3\":" + Utils.JsonStringify(_4) + ",\"4\":" + Utils.JsonStringify(_5) + ",\"length\":5}" ;
    }

    @Override
    public String toString() {
        return "(" + _1 + "," + _2 + "," + _3 + "," + _4 + "," + _5 + ")" ;
    }

    public String getClassName() {return "Tuple5";}
    public  boolean checkInstance(Object other){ return other instanceof Tuple5;}

    // get the value of that named property
    @Override
    public Object getMember(String name) {
        switch (name) {
            case "_1": return F_1;
            case "_2": return F_2;
            case "_3": return F_3;
            case "_4": return F_4;
            case "_5": return F_5;
        }
        return super.getMember(name);
    }
    @Override
    public boolean hasMember(String name) {
        switch (name) {
            case "_1":
            case "_2":
            case "_3":
            case "_4":
            case "_5":
                return true;
        }
        return super.hasMember(name);
    }

}


text:
/*! \file scan.h
 *  \brief Scan operations (parallel prefix-sum) [cuda]
 */

#pragma once

namespace thrust
{
namespace detail
{
namespace device
{
namespace cuda
{

template<typename InputIterator,
         typename OutputIterator,
         typename AssociativeOperator>
  OutputIterator inclusive_scan(InputIterator first,
                                InputIterator last,
                                OutputIterator result,
                                AssociativeOperator binary_op);

template<typename InputIterator,
         typename OutputIterator,
         typename T,
         typename AssociativeOperator>
  OutputIterator exclusive_scan(InputIterator first,
                                InputIterator last,
                                OutputIterator result,
                                T init,
                                AssociativeOperator binary_op);

} // end namespace cuda
} // end namespace device
} // end namespace detail
} // end namespace thrust

#include "scan.inl"


text:
package net.sourceforge.pebble.web.action;

import net.sourceforge.pebble.Constants;
import net.sourceforge.pebble.domain.Blog;
import net.sourceforge.pebble.domain.StaticPage;
import net.sourceforge.pebble.service.StaticPageService;
import net.sourceforge.pebble.service.StaticPageServiceException;
import net.sourceforge.pebble.web.view.NotFoundView;
import net.sourceforge.pebble.web.view.View;
import net.sourceforge.pebble.web.view.impl.StaticPageFormView;
import net.sourceforge.pebble.web.view.impl.StaticPageLockedView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Edits an existing static page. This is called to populate a HTML
 * form containing the contents of the static page.
 *
 * @author    Simon Brown
 */
public class EditStaticPageAction extends SecureAction {

  /**
   * Peforms the processing associated with this action.
   *
   * @param request  the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    StaticPageService service = new StaticPageService();
    StaticPage staticPage = null;
    try {
      staticPage = service.getStaticPageById(blog, request.getParameter("page"));
    } catch (StaticPageServiceException e) {
      throw new ServletException(e);
    }

    if (staticPage == null) {
      return new NotFoundView();
    } else {
      getModel().put(Constants.STATIC_PAGE_KEY, staticPage);
      if (service.lock(staticPage)) {
        return new StaticPageFormView();
      } else {
        return new StaticPageLockedView();
      }
    }
  }

  /**
   * Gets a list of all roles that are allowed to access this action.
   *
   * @return  an array of Strings representing role names
   * @param request
   */
  public String[] getRoles(HttpServletRequest request) {
    return new String[]{Constants.BLOG_CONTRIBUTOR_ROLE};
  }

}


text:
package ariba.util.core;

/**
    @aribaapi private
*/
public interface MainThread
{
    public Thread mainThread ();
}


text:
<!DOCTYPE html>

  <meta charset="UTF-8">
  <link href="http://gmpg.org/xfn/11" rel="profile">

  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">

  <title>

      Виртуализация · My worklog

  </title>

  <link rel="stylesheet" href="/public/css/poole.css">
  <link rel="stylesheet" href="/public/css/syntax.css">

  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/public/apple-touch-icon-precomposed.png">
  <link rel="shortcut icon" href="/public/favicon.png">

  <link rel="alternate" type="application/atom+xml" title="My worklog" href="/atom.xml">

          My worklog
          GitHub
          Archive
          Tags

Виртуализация

  <time datetime="2014-11-07T11:52:05+06:00" class="post-date">07 Nov 2014</time>

Виртуализация, в разрезе технологии интеловских процессоров, позволяет делать ряд интересных вещей. Сам принцип такой - процессор входит в режим vm набором инструкций, после чего код гипервизора перемещается в ring -1, затем работа продолжается как обычно. Гипервизор, оставаясь резидентным в ring -1 может получать управление разными способами:

Периодически, перехватив прерывания или через preemption timer.

Синхронно через механизм vm-call-ов который реализуется самим гипервизором и используется модифицированной ОС или драйвером в ней, т.е. агентом в ring 0, который знает о гипервизоре.

Асинхронно по возникновению интересующих гипервизора событий от нормальной работы немодифицированного кода.

Последний механизм самый интересный. Код гипервизора может перехватывать ряд интересных для него событий, которые генерирует нормальная работа немодифицированного кода всех менее привелигерованных режимов. Когда эти события возникают, то процессор делает т.н. vmexit, т.е. возврат в ring -1 и передачу управления хендлеру гипервизора. Механизм похож на exception handler, но регистрация на интересующие исключения происходит по-другому. Что можно перехватывать - много чего, но вот одни из самых интересных вещей:

Обращения к физической памяти. В режиме виртуализации то что ОС в ring 0 видит как физическую память на самом деле виртуальные адреса смаппированные гипервизором. Ring 0 продолжает нормально работать с этой памятью как с физической, мапить ее на виртуальные адреса, но на самом деле трансляция в физический адрес проходит через дополнительную таблицу страниц гипервизора, у которого есть возможность при маппировании физической страницы указать флагами генерацию исключения и vmexit при доступе к этой странице на R/W/X. В результате можно перехватывать любые обращения гостевой ОС к интересующему диапазону адресов.

I/O адресное пространство. При инициализации гипервизор может задать битовую маску на весь диапазон I/O портов x86 (почти на весь - у интела баг, который не позволяет захватить два последних бита в маске). Эффект тот же что и с памятью - vmexit при попытке обращения к I/O порту. Это дает дополнительную возможность перехвата одного из способов обращения к PCI Configuration Space, о котором позже.

MSR - vmexit при попытке R/W на интересующий регистр.

Еще несколько дополнительных триггеров, включая обращения к XMM/FPU контексту, CPUID, GDT, LDT, IDT, CR регистры.

Все это позволяет гипервизору эмулировать отдельную песочницу для каждого из гостей,аллоцировать ресурсы и переключать выполнение между несколькими гостями, фильтровать и перенаправлять прерывания и т.д. без модификации самих гостей. А еще это позволяет перехватывать весь доступ гостя к ACPI, PCI и MSR, - т.е. всеми каналами управления переферийным железом и чипсетами, что открывает интересные возможности по фильтрации доступа к железу. Можно спрятать PCI устройство, можно нарисовать свое фейковое устройство и т.д. Это открывает дополнительные прикладные возможности виртуализации, помимо очевидной основной, в рамках одного гостя.

Например можно попытаться решить проблему с "богатым пребутом" - запустить линукс с возвратом в фирмварь без потери состояния железа, через жесткий ACPI и PCI фильтр и редирект запросов на допустимые устройства в драйвер фирмвари. В случае UEFI можно попытаться не делать выход из бут сервисов, а отобрать у фирмвари процессор на время, защитить ее память и запустить ядро линукса.

Но одна из самых интересных прикладных задач для меня это инструменты, точнее дебаггер с элементами гипервизора для бареметал. Типичный механизм брейкпоинтов и вочпоинтов подразумевает, что ты знаешь адрес, по которому должен сработать выход в дебаггер. В случае отлаживания и исследования неизвестного кода, например фирмвари, адреса заранее не известны, есть только теория что код обращается к железу / странице памяти / MSRу (например чтобы поменять GS_BASE ;)). В таких случаях нужно нечто более "декларативное", нужно сказать что-то типа "я не знаю где это происходит, но как только это произойдет, то я хочу об этом знать", что и позволяют в определенных пределах элементы гипервизора. Помимо отладки такой инструмент можно использовать для исследования чужого кода, в том числе вредоносного, играть с внедрением ошибок от устройств, эмулировать устройства на самом нижнем уровне для проверки устойчивости системы к ошибкам и поиска уязвимостей например.

Основной недостаток это конечно аппаратные требования. У интела нужную технологию поддерживает уже более менее вся линейка core i процессоров второго и последующих поколений. У AMD своя технология, отдельная от интела и я про нее мало знаю, кроме того что общий смысл тот же, а опкоды другие. У ARM-ов тоже недавно появился TrustZone, который по сути тот же ring -1.

        Please enable JavaScript to view the comments powered by Disqus.

          © <time datetime="2015-01-31T16:39:32+06:00">2015</time>. All rights reserved.