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

I'm Joshua Scott, I'm a programmer and database enthusiast. Ruby on Rails,
JavaScript, Redis, PostgreSQL are my day job, and I play with Elixir, Clojure,
Erlang, C, Graph Databases, Key/Value stores, Unity, hardware prototyping, and
anything else that captures my fancy.

I work at [Simpli.fi](http://www.simpli.fi), but my opinions are my own. We're
almost always looking for people who love to learn and are serious about
programming and scaling.

redpajama_set_name: RedPajamaGithub


text:
"""Unit tests for type-hint objects and decorators - Python 3 syntax specific.
"""

from __future__ import absolute_import

import unittest

import apache_beam as beam
from apache_beam import typehints

class MainInputTest(unittest.TestCase):

  def test_typed_dofn_method(self):
    # process annotations are recognized and take precedence over decorators.
    @typehints.with_input_types(typehints.Tuple[int, int])
    @typehints.with_output_types(int)
    class MyDoFn(beam.DoFn):
      def process(self, element: int) -> typehints.Tuple[str]:
        return tuple(str(element))

    result = [1, 2, 3] | beam.ParDo(MyDoFn())
    self.assertEqual(['1', '2', '3'], sorted(result))

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      ['a', 'b', 'c'] | beam.ParDo(MyDoFn())

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      [1, 2, 3] | (beam.ParDo(MyDoFn()) | 'again' >> beam.ParDo(MyDoFn()))

  def test_typed_dofn_instance(self):
    # Type hints applied to DoFn instance take precedence over decorators and
    # process annotations.
    @typehints.with_input_types(typehints.Tuple[int, int])
    @typehints.with_output_types(int)
    class MyDoFn(beam.DoFn):
      def process(self, element: typehints.Tuple[int, int]) -> \
          typehints.List[int]:
        return [str(element)]
    my_do_fn = MyDoFn().with_input_types(int).with_output_types(str)

    result = [1, 2, 3] | beam.ParDo(my_do_fn)
    self.assertEqual(['1', '2', '3'], sorted(result))

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      ['a', 'b', 'c'] | beam.ParDo(my_do_fn)

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      [1, 2, 3] | (beam.ParDo(my_do_fn) | 'again' >> beam.ParDo(my_do_fn))

  def test_typed_callable_instance(self):
    # Type hints applied to ParDo instance take precedence over callable
    # decorators and annotations.
    @typehints.with_input_types(typehints.Tuple[int, int])
    @typehints.with_output_types(int)
    def do_fn(element: typehints.Tuple[int, int]) -> typehints.Generator[int]:
      yield str(element)
    pardo = beam.ParDo(do_fn).with_input_types(int).with_output_types(str)

    result = [1, 2, 3] | pardo
    self.assertEqual(['1', '2', '3'], sorted(result))

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      ['a', 'b', 'c'] | pardo

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*int.*got.*str'):
      [1, 2, 3] | (pardo | 'again' >> pardo)

  @unittest.skip('BEAM-7981: Iterable in output type should not be removed.')
  def test_typed_callable_iterable_output(self):
    # TODO(BEAM-7981): Both Iterables get stripped in
    #   CallableWrapperDoFn.default_type_hints, but only one should.
    def do_fn(element: int) -> typehints.Iterable[typehints.Iterable[str]]:
      return [[str(element)] * 2]

    result = [1, 2] | beam.ParDo(do_fn)
    self.assertEqual([['1', '1'], ['2', '2']], sorted(result))

  def test_typed_dofn_method_not_iterable(self):
    class MyDoFn(beam.DoFn):
      def process(self, element: int) -> str:
        return str(element)

    with self.assertRaisesRegex(ValueError, r'str.*is not iterable'):
      [1, 2, 3] | beam.ParDo(MyDoFn())

  def test_typed_callable_not_iterable(self):
    def do_fn(element: typehints.Tuple[int, int]) -> int:
      return element[0]
    with self.assertRaisesRegex(ValueError, r'int.*is not iterable'):
      [1, 2, 3] | beam.ParDo(do_fn)

  def test_typed_dofn_kwonly(self):
    class MyDoFn(beam.DoFn):
      # TODO(BEAM-5878): A kwonly argument like
      #   timestamp=beam.DoFn.TimestampParam would not work here.
      def process(self, element: int, *, side_input: str) -> \
          typehints.Generator[typehints.Optional[int]]:
        yield str(element) if side_input else None
    my_do_fn = MyDoFn()

    result = [1, 2, 3] | beam.ParDo(my_do_fn, side_input='abc')
    self.assertEqual(['1', '2', '3'], sorted(result))

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*str.*got.*int.*side_input'):
      [1, 2, 3] | beam.ParDo(my_do_fn, side_input=1)

  def test_type_dofn_var_kwargs(self):
    class MyDoFn(beam.DoFn):
      def process(self, element: int, **side_inputs: typehints.Dict[str, str]) \
          -> typehints.Generator[typehints.Optional[int]]:
        yield str(element) if side_inputs else None
    my_do_fn = MyDoFn()

    result = [1, 2, 3] | beam.ParDo(my_do_fn, foo='abc', bar='def')
    self.assertEqual(['1', '2', '3'], sorted(result))

    with self.assertRaisesRegex(typehints.TypeCheckError,
                                r'requires.*str.*got.*int.*side_inputs'):
      [1, 2, 3] | beam.ParDo(my_do_fn, a=1)

class AnnotationsTest(unittest.TestCase):

  def test_pardo_dofn(self):
    class MyDoFn(beam.DoFn):
      def process(self, element: int) -> typehints.Generator[str]:
        yield str(element)

    th = beam.ParDo(MyDoFn()).get_type_hints()
    self.assertEqual(th.input_types, ((int,), {}))
    self.assertEqual(th.output_types, ((str,), {}))

  def test_pardo_dofn_not_iterable(self):
    class MyDoFn(beam.DoFn):
      def process(self, element: int) -> str:
        return str(element)

    with self.assertRaisesRegexp(ValueError, r'Return value not iterable'):
      _ = beam.ParDo(MyDoFn()).get_type_hints()

  def test_pardo_wrapper(self):
    def do_fn(element: int) -> typehints.Iterable[str]:
      return [str(element)]

    th = beam.ParDo(do_fn).get_type_hints()
    self.assertEqual(th.input_types, ((int,), {}))
    self.assertEqual(th.output_types, ((str,), {}))

  def test_pardo_wrapper_not_iterable(self):
    def do_fn(element: int) -> str:
      return str(element)

    with self.assertRaisesRegexp(ValueError, r'Return value not iterable'):
      _ = beam.ParDo(do_fn).get_type_hints()

  def test_flat_map_wrapper(self):
    def map_fn(element: int) -> typehints.Iterable[int]:
      return [element, element + 1]

    th = beam.FlatMap(map_fn).get_type_hints()
    self.assertEqual(th.input_types, ((int,), {}))
    self.assertEqual(th.output_types, ((int,), {}))

  def test_flat_map_tuple_wrapper(self):
    def tuple_map_fn(a: str, b: str, c: str) -> typehints.Iterable[str]:
      return [a, b, c]

    th = beam.FlatMapTuple(tuple_map_fn).get_type_hints()
    self.assertEqual(th.input_types, ((str, str, str), {}))
    self.assertEqual(th.output_types, ((str,), {}))

  def test_map_wrapper(self):
    def map_fn(unused_element: int) -> int:
      return 1

    th = beam.Map(map_fn).get_type_hints()
    self.assertEqual(th.input_types, ((int,), {}))
    self.assertEqual(th.output_types, ((int,), {}))

  def test_map_tuple(self):
    def tuple_map_fn(a: str, b: str, c: str) -> str:
      return a + b + c

    th = beam.MapTuple(tuple_map_fn).get_type_hints()
    self.assertEqual(th.input_types, ((str, str, str), {}))
    self.assertEqual(th.output_types, ((str,), {}))

  def test_filter_wrapper(self):
    def filter_fn(element: int) -> bool:
      return bool(element % 2)

    th = beam.Filter(filter_fn).get_type_hints()
    self.assertEqual(th.input_types, ((int,), {}))
    self.assertEqual(th.output_types, ((bool,), {}))

if __name__ == '__main__':
  unittest.main()


text:
.. _topics-leaks:

======================
Debugging memory leaks
======================

In Scrapy, objects such as Requests, Responses and Items have a finite
lifetime: they are created, used for a while, and finally destroyed.

From all those objects, the Request is probably the one with the longest
lifetime, as it stays waiting in the Scheduler queue until it's time to process
it. For more info see :ref:`topics-architecture`.

As these Scrapy objects have a (rather long) lifetime, there is always the risk
of accumulating them in memory without releasing them properly and thus causing
what is known as a "memory leak".

To help debugging memory leaks, Scrapy provides a built-in mechanism for
tracking objects references called :ref:`trackref <topics-leaks-trackrefs>`,
and you can also use a third-party library called :ref:`Guppy
<topics-leaks-guppy>` for more advanced memory debugging (see below for more
info). Both mechanisms must be used from the :ref:`Telnet Console
<topics-telnetconsole>`.

Common causes of memory leaks
=============================

It happens quite often (sometimes by accident, sometimes on purpose) that the
Scrapy developer passes objects referenced in Requests (for example, using the
:attr:`~scrapy.http.Request.meta` attribute or the request callback function)
and that effectively bounds the lifetime of those referenced objects to the
lifetime of the Request. This is, by far, the most common cause of memory leaks
in Scrapy projects, and a quite difficult one to debug for newcomers.

In big projects, the spiders are typically written by different people and some
of those spiders could be "leaking" and thus affecting the rest of the other
(well-written) spiders when they get to run concurrently, which, in turn,
affects the whole crawling process.

At the same time, it's hard to avoid the reasons that cause these leaks
without restricting the power of the framework, so we have decided not to
restrict the functionally but provide useful tools for debugging these leaks,
which quite often consist in an answer to the question: *which spider is leaking?*.

The leak could also come from a custom middleware, pipeline or extension that
you have written, if you are not releasing the (previously allocated) resources
properly. For example, if you're allocating resources on
:signal:`spider_opened` but not releasing them on :signal:`spider_closed`.

.. _topics-leaks-trackrefs:

Debugging memory leaks with ``trackref``
========================================

``trackref`` is a module provided by Scrapy to debug the most common cases of
memory leaks. It basically tracks the references to all live Requests,
Responses, Item and Selector objects.

You can enter the telnet console and inspect how many objects (of the classes
mentioned above) are currently alive using the ``prefs()`` function which is an
alias to the :func:`~scrapy.utils.trackref.print_live_refs` function::

    telnet localhost 6023

    >>> prefs()
    Live References

    ExampleSpider                       1   oldest: 15s ago
    HtmlResponse                       10   oldest: 1s ago
    XPathSelector                       2   oldest: 0s ago
    FormRequest                       878   oldest: 7s ago

As you can see, that report also shows the "age" of the oldest object in each
class.

If you do have leaks, chances are you can figure out which spider is leaking by
looking at the oldest request or response. You can get the oldest object of
each class using the :func:`~scrapy.utils.trackref.get_oldest` function like
this (from the telnet console).

Which objects are tracked?
--------------------------

The objects tracked by ``trackrefs`` are all from these classes (and all its
subclasses):

* ``scrapy.http.Request``
* ``scrapy.http.Response``
* ``scrapy.item.Item``
* ``scrapy.selector.XPathSelector``
* ``scrapy.spider.BaseSpider``
* ``scrapy.selector.document.Libxml2Document``

A real example
--------------

Let's see a concrete example of an hypothetical case of memory leaks.

Suppose we have some spider with a line similar to this one::

    return Request("http://www.somenastyspider.com/product.php?pid=%d" % product_id,
        callback=self.parse, meta={referer: response}")

That line is passing a response reference inside a request which effectively
ties the response lifetime to the requests' one, and that would definitely
cause memory leaks.

Let's see how we can discover which one is the nasty spider (without knowing it
a-priori, of course) by using the ``trackref`` tool.

After the crawler is running for a few minutes and we notice its memory usage
has grown a lot, we can enter its telnet console and check the live
references::

    >>> prefs()
    Live References

    SomenastySpider                     1   oldest: 15s ago
    HtmlResponse                     3890   oldest: 265s ago
    XPathSelector                       2   oldest: 0s ago
    Request                          3878   oldest: 250s ago

The fact that there are so many live responses (and that they're so old) is
definitely suspicious, as responses should have a relatively short lifetime
compared to Requests. So let's check the oldest response::

    >>> from scrapy.utils.trackref import get_oldest
    >>> r = get_oldest('HtmlResponse')
    >>> r.url
    'http://www.somenastyspider.com/product.php?pid=123'

There it is. By looking at the URL of the oldest response we can see it belongs
to the ``somenastyspider.com`` spider. We can now go and check the code of that
spider to discover the nasty line that is generating the leaks (passing
response references inside requests).

If you want to iterate over all objects, instead of getting the oldest one, you
can use the :func:`iter_all` function::

    >>> from scrapy.utils.trackref import iter_all
    >>> [r.url for r in iter_all('HtmlResponse')]
    ['http://www.somenastyspider.com/product.php?pid=123',
     'http://www.somenastyspider.com/product.php?pid=584',
    ...

Too many spiders?
-----------------

If your project has too many spiders, the output of ``prefs()`` can be
difficult to read. For this reason, that function has a ``ignore`` argument
which can be used to ignore a particular class (and all its subclases). For
example, using::

    >>> from scrapy.spider import BaseSpider
    >>> prefs(ignore=BaseSpider)

Won't show any live references to spiders.

.. module:: scrapy.utils.trackref
   :synopsis: Track references of live objects

scrapy.utils.trackref module
----------------------------

Here are the functions available in the :mod:`~scrapy.utils.trackref` module.

.. class:: object_ref

    Inherit from this class (instead of object) if you want to track live
    instances with the ``trackref`` module.

.. function:: print_live_refs(class_name, ignore=NoneType)

    Print a report of live references, grouped by class name.

    :param ignore: if given, all objects from the specified class (or tuple of
        classes) will be ignored.
    :type ignore: class or classes tuple

.. function:: get_oldest(class_name)

    Return the oldest object alive with the given class name, or ``None`` if
    none is found. Use :func:`print_live_refs` first to get a list of all
    tracked live objects per class name.

.. function:: iter_all(class_name)

    Return an iterator over all objects alive with the given class name, or
    ``None`` if none is found. Use :func:`print_live_refs` first to get a list
    of all tracked live objects per class name.

.. _topics-leaks-guppy:

Debugging memory leaks with Guppy
=================================

``trackref`` provides a very convenient mechanism for tracking down memory
leaks, but it only keeps track of the objects that are more likely to cause
memory leaks (Requests, Responses, Items, and Selectors). However, there are
other cases where the memory leaks could come from other (more or less obscure)
objects. If this is your case, and you can't find your leaks using ``trackref``,
you still have another resource: the `Guppy library`_.

.. _Guppy library: http://pypi.python.org/pypi/guppy

If you use ``setuptools``, you can install Guppy with the following command::

    easy_install guppy

.. _setuptools: http://pypi.python.org/pypi/setuptools

The telnet console also comes with a built-in shortcut (``hpy``) for accessing
Guppy heap objects. Here's an example to view all Python objects available in
the heap using Guppy::

    >>> x = hpy.heap()
    >>> x.bytype
    Partition of a set of 297033 objects. Total size = 52587824 bytes.
     Index  Count   %     Size   % Cumulative  % Type
         0  22307   8 16423880  31  16423880  31 dict
         1 122285  41 12441544  24  28865424  55 str
         2  68346  23  5966696  11  34832120  66 tuple
         3    227   0  5836528  11  40668648  77 unicode
         4   2461   1  2222272   4  42890920  82 type
         5  16870   6  2024400   4  44915320  85 function
         6  13949   5  1673880   3  46589200  89 types.CodeType
         7  13422   5  1653104   3  48242304  92 list
         8   3735   1  1173680   2  49415984  94 _sre.SRE_Pattern
         9   1209   0   456936   1  49872920  95 scrapy.http.headers.Headers
    <1676 more rows. Type e.g. '_.more' to view.>

You can see that most space is used by dicts. Then, if you want to see from
which attribute those dicts are referenced, you could do::

    >>> x.bytype[0].byvia
    Partition of a set of 22307 objects. Total size = 16423880 bytes.
     Index  Count   %     Size   % Cumulative  % Referred Via:
         0  10982  49  9416336  57   9416336  57 '.__dict__'
         1   1820   8  2681504  16  12097840  74 '.__dict__', '.func_globals'
         2   3097  14  1122904   7  13220744  80
         3    990   4   277200   2  13497944  82 "['cookies']"
         4    987   4   276360   2  13774304  84 "['cache']"
         5    985   4   275800   2  14050104  86 "['meta']"
         6    897   4   251160   2  14301264  87 '[2]'
         7      1   0   196888   1  14498152  88 "['moduleDict']", "['modules']"
         8    672   3   188160   1  14686312  89 "['cb_kwargs']"
         9     27   0   155016   1  14841328  90 '[1]'
    <333 more rows. Type e.g. '_.more' to view.>

As you can see, the Guppy module is very powerful but also requires some deep
knowledge about Python internals. For more info about Guppy, refer to the
`Guppy documentation`_.

.. _Guppy documentation: http://guppy-pe.sourceforge.net/

.. _topics-leaks-without-leaks:

Leaks without leaks
===================

Sometimes, you may notice that the memory usage of your Scrapy process will
only increase, but never decrease. Unfortunately, this could happen even
though neither Scrapy nor your project are leaking memory. This is due to a
(not so well) known problem of Python, which may not return released memory to
the operating system in some cases. For more information on this issue see:

* `Python Memory Management <http://evanjones.ca/python-memory.html>`_
* `Python Memory Management Part 2 <http://evanjones.ca/python-memory-part2.html>`_
* `Python Memory Management Part 3 <http://evanjones.ca/python-memory-part3.html>`_

The improvements proposed by Evan Jones, which are detailed in `this paper`_,
got merged in Python 2.5, but this only reduces the problem, it doesn't fix it
completely. To quote the paper:

    *Unfortunately, this patch can only free an arena if there are no more
    objects allocated in it anymore. This means that fragmentation is a large
    issue. An application could have many megabytes of free memory, scattered
    throughout all the arenas, but it will be unable to free any of it. This is
    a problem experienced by all memory allocators. The only way to solve it is
    to move to a compacting garbage collector, which is able to move objects in
    memory. This would require significant changes to the Python interpreter.*

This problem will be fixed in future Scrapy releases, where we plan to adopt a
new process model and run spiders in a pool of recyclable sub-processes.

.. _this paper: http://evanjones.ca/memoryallocator/


text:
#ifndef _VKTDRAWSHADERLAYERTESTS_HPP
#define _VKTDRAWSHADERLAYERTESTS_HPP
/*!
 * \file
 * \brief Use of gl_Layer in Vertex and Tessellation Shaders
 *        (part of VK_EXT_ShaderViewportIndexLayer)
 *//*--------------------------------------------------------------------*/

#include "tcuDefs.hpp"
#include "tcuTestCase.hpp"

namespace vkt
{
namespace Draw
{

tcu::TestCaseGroup*		createShaderLayerTests	(tcu::TestContext& testCtx);

} // Draw
} // vkt

#endif // _VKTDRAWSHADERLAYERTESTS_HPP


text:
<?xml version="1.0" encoding="UTF-8"?>
<imageIndex>
  <image>
    <originalFileName>IMG_3150 (Medium).JPG</originalFileName>
    <size>138021</size>
    <dateLastModified>Sat, 24 Jan 2015 06:08:10 GMT</dateLastModified>
    <width>768</width>
    <height>1152</height>
    <cachedImage>
      <fileName>d2pbjype.jpeg</fileName>
      <dateCreated>Sat, 24 Jan 2015 06:18:46 GMT</dateCreated>
      <dateLastAccessed>Thu, 19 Mar 2015 21:07:35 GMT</dateLastAccessed>
      <imageFormat>jpeg</imageFormat>
      <compression>90</compression>
      <width>67</width>
      <height>100</height>
      <bgColor>#FFFFFF</bgColor>
      <transparent>True</transparent>
      <border>0</border>
      <borderColor>#000000</borderColor>
      <constrain>True</constrain>
      <pad>False</pad>
    </cachedImage>
    <cachedImage>
      <fileName>w34npcfr.jpeg</fileName>
      <dateCreated>Sat, 24 Jan 2015 19:52:47 GMT</dateCreated>
      <dateLastAccessed>Tue, 17 Mar 2015 05:05:13 GMT</dateLastAccessed>
      <imageFormat>jpeg</imageFormat>
      <compression>90</compression>
      <width>400</width>
      <height>600</height>
      <bgColor>#FFFFFF</bgColor>
      <transparent>True</transparent>
      <border>0</border>
      <borderColor>#000000</borderColor>
      <constrain>True</constrain>
      <pad>False</pad>
    </cachedImage>
  </image>
</imageIndex>


text:
namespace chromeos {

namespace {

// Root CA certificates that are built into Chrome use this token name.
const char kRootCertificateTokenName[] = "Builtin Object Token";

string16 GetDisplayString(net::X509Certificate* cert, bool hardware_backed) {
  std::string org;
  if (!cert->subject().organization_names.empty())
    org = cert->subject().organization_names[0];
  if (org.empty())
    org = cert->subject().GetDisplayName();
  string16 issued_by = UTF8ToUTF16(
      x509_certificate_model::GetIssuerCommonName(cert->os_cert_handle(),
                                                  org));  // alternative text
  string16 issued_to = UTF8ToUTF16(
      x509_certificate_model::GetCertNameOrNickname(cert->os_cert_handle()));

  if (hardware_backed) {
    return l10n_util::GetStringFUTF16(
        IDS_CERT_MANAGER_HARDWARE_BACKED_KEY_FORMAT_LONG,
        issued_by,
        issued_to,
        l10n_util::GetStringUTF16(IDS_CERT_MANAGER_HARDWARE_BACKED));
  } else {
    return l10n_util::GetStringFUTF16(
        IDS_CERT_MANAGER_KEY_FORMAT_LONG,
        issued_by,
        issued_to);
  }
}

std::string CertToPEM(const net::X509Certificate& cert) {
  std::string pem_encoded_cert;
  if (!net::X509Certificate::GetPEMEncoded(cert.os_cert_handle(),
                                           &pem_encoded_cert)) {
    LOG(ERROR) << "Couldn't PEM-encode certificate";
    return std::string();
  }
  return pem_encoded_cert;
}

}  // namespace

class CertNameComparator {
 public:
  explicit CertNameComparator(icu::Collator* collator)
      : collator_(collator) {
  }

  bool operator()(const scoped_refptr<net::X509Certificate>& lhs,
                  const scoped_refptr<net::X509Certificate>& rhs) const {
    string16 lhs_name = GetDisplayString(lhs.get(), false);
    string16 rhs_name = GetDisplayString(rhs.get(), false);
    if (collator_ == NULL)
      return lhs_name < rhs_name;
    return base::i18n::CompareString16WithCollator(
        collator_, lhs_name, rhs_name) == UCOL_LESS;
  }

 private:
  icu::Collator* collator_;
};

static CertLibrary* g_cert_library = NULL;

// static
void CertLibrary::Initialize() {
  CHECK(!g_cert_library);
  g_cert_library = new CertLibrary();
}

// static
void CertLibrary::Shutdown() {
  CHECK(g_cert_library);
  delete g_cert_library;
  g_cert_library = NULL;
}

// static
CertLibrary* CertLibrary::Get() {
  CHECK(g_cert_library) << "CertLibrary::Get() called before Initialize()";
  return g_cert_library;
}

// static
bool CertLibrary::IsInitialized() {
  return g_cert_library;
}

CertLibrary::CertLibrary() {
  CertLoader::Get()->AddObserver(this);
}

CertLibrary::~CertLibrary() {
  CertLoader::Get()->RemoveObserver(this);
}

void CertLibrary::AddObserver(CertLibrary::Observer* observer) {
  observer_list_.AddObserver(observer);
}

void CertLibrary::RemoveObserver(CertLibrary::Observer* observer) {
  observer_list_.RemoveObserver(observer);
}

bool CertLibrary::CertificatesLoading() const {
  return CertLoader::Get()->CertificatesLoading();
}

bool CertLibrary::CertificatesLoaded() const {
  return CertLoader::Get()->certificates_loaded();
}

bool CertLibrary::IsHardwareBacked() const {
  return CertLoader::Get()->IsHardwareBacked();
}

int CertLibrary::NumCertificates(CertType type) const {
  const net::CertificateList& cert_list = GetCertificateListForType(type);
  return static_cast<int>(cert_list.size());
}

string16 CertLibrary::GetCertDisplayStringAt(CertType type, int index) const {
  net::X509Certificate* cert = GetCertificateAt(type, index);
  bool hardware_backed = IsCertHardwareBackedAt(type, index);
  return GetDisplayString(cert, hardware_backed);
}

std::string CertLibrary::GetCertPEMAt(CertType type, int index) const {
  return CertToPEM(*GetCertificateAt(type, index));
}

std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const {
  net::X509Certificate* cert = GetCertificateAt(type, index);
  return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle());
}

bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const {
  if (!CertLoader::Get()->IsHardwareBacked())
    return false;
  net::X509Certificate* cert = GetCertificateAt(type, index);
  std::string cert_token_name =
      x509_certificate_model::GetTokenName(cert->os_cert_handle());
  return cert_token_name ==
      CertLoader::Get()->tpm_token_name();
}

int CertLibrary::GetCertIndexByPEM(CertType type,
                                   const std::string& pem_encoded) const {
  int num_certs = NumCertificates(type);
  for (int index = 0; index < num_certs; ++index) {
    net::X509Certificate* cert = GetCertificateAt(type, index);
    if (CertToPEM(*cert) != pem_encoded)
      continue;
    return index;
  }
  return -1;
}

int CertLibrary::GetCertIndexByPkcs11Id(CertType type,
                                        const std::string& pkcs11_id) const {
  int num_certs = NumCertificates(type);
  for (int index = 0; index < num_certs; ++index) {
    net::X509Certificate* cert = GetCertificateAt(type, index);
    net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle();
    std::string id = x509_certificate_model::GetPkcs11Id(cert_handle);
    if (id == pkcs11_id)
      return index;
  }
  return -1;  // Not found.
}

void CertLibrary::OnCertificatesLoaded(const net::CertificateList& cert_list,
                                       bool initial_load) {
  CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
  VLOG(1) << "CertLibrary::OnCertificatesLoaded: " << cert_list.size();
  certs_.clear();
  user_certs_.clear();
  server_certs_.clear();
  server_ca_certs_.clear();

  // Add certificates to the appropriate list.
  for (net::CertificateList::const_iterator iter = cert_list.begin();
       iter != cert_list.end(); ++iter) {
    certs_.push_back(iter->get());
    net::X509Certificate::OSCertHandle cert_handle =
        iter->get()->os_cert_handle();
    net::CertType type = x509_certificate_model::GetType(cert_handle);
    switch (type) {
      case net::USER_CERT:
        user_certs_.push_back(iter->get());
        break;
      case net::SERVER_CERT:
        server_certs_.push_back(iter->get());
        break;
      case net::CA_CERT: {
        // Exclude root CA certificates that are built into Chrome.
        std::string token_name =
            x509_certificate_model::GetTokenName(cert_handle);
        if (token_name != kRootCertificateTokenName)
          server_ca_certs_.push_back(iter->get());
        break;
      }
      default:
        break;
    }
  }

  // Perform locale-sensitive sorting by certificate name.
  UErrorCode error = U_ZERO_ERROR;
  scoped_ptr<icu::Collator> collator(icu::Collator::createInstance(
      icu::Locale(g_browser_process->GetApplicationLocale().c_str()), error));
  if (U_FAILURE(error))
    collator.reset();
  CertNameComparator cert_name_comparator(collator.get());
  std::sort(certs_.begin(), certs_.end(), cert_name_comparator);
  std::sort(user_certs_.begin(), user_certs_.end(), cert_name_comparator);
  std::sort(server_certs_.begin(), server_certs_.end(), cert_name_comparator);
  std::sort(server_ca_certs_.begin(), server_ca_certs_.end(),
            cert_name_comparator);

  VLOG(1) << "certs_: " << certs_.size();
  VLOG(1) << "user_certs_: " << user_certs_.size();
  VLOG(1) << "server_certs_: " << server_certs_.size();
  VLOG(1) << "server_ca_certs_: " << server_ca_certs_.size();

  FOR_EACH_OBSERVER(CertLibrary::Observer, observer_list_,
                    OnCertificatesLoaded(initial_load));
}

net::X509Certificate* CertLibrary::GetCertificateAt(CertType type,
                                                    int index) const {
  const net::CertificateList& cert_list = GetCertificateListForType(type);
  DCHECK_GE(index, 0);
  DCHECK_LT(index, static_cast<int>(cert_list.size()));
  return cert_list[index].get();
}

const net::CertificateList& CertLibrary::GetCertificateListForType(
    CertType type) const {
  if (type == CERT_TYPE_USER)
    return user_certs_;
  if (type == CERT_TYPE_SERVER)
    return server_certs_;
  if (type == CERT_TYPE_SERVER_CA)
    return server_ca_certs_;
  DCHECK(type == CERT_TYPE_DEFAULT);
  return certs_;
}

}  // namespace chromeos


text:
require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  describe "#sample" do
    let(:vector) { Hamster::Vector.new(1..10) }

    it "returns a randomly chosen item" do
      chosen = 100.times.map { vector.sample }
      chosen.each { |item| vector.include?(item).should == true }
      vector.each { |item| chosen.include?(item).should == true }
    end
  end
end


text:
var application = {
	settings: function(){
		// capture the desktop
		global.app.settingsWindow = gui.Window.open('settings.html', {
			frame: true,
			toolbar: false,
			width: 400,
			height: 480,
			position: 'center'
		});
		global.app.settingsWindow.focus();
	},
	screenshot: function(){
		var d = new Date().getTime(),
			filename = 'temp/ss-' + d +'.png',
			vals = this.getProgram(filename);
		if(vals.program == false){
			return console.log('Bad OS');
		}
		// calculate coords

		// capture the desktop
		global.app.ss = vals;
		exec('"' + vals.program + '" ' + vals.opts.join(' '), function(){
			global.app.ssWindow = gui.Window.open('crop.html', {
				frame: false,
				toolbar: false,
				'always-on-top': true,
				transparent: true,
				resize: false
			});
			global.app.ssWindow.resizeTo(vals.coords.width, vals.coords.height);
			global.app.ssWindow.moveTo(vals.coords.x.start, vals.coords.y.start);
			global.app.ssWindow.focus();
		});
	},
	getCoords: function(){
		var coords ={
			x: {
				start: 0,
				stop: 0
			},
			y: {
				start: 0,
				stop: 0
			},
			width: 0,
			height: 0
		}
		_.each(global.app.screens, function(screen){
			// x
			if(screen.bounds.x < coords.x.start){ coords.x.start = screen.bounds.x }
			var x = screen.bounds.x + screen.bounds.width;
			if(x > coords.x.stop){
				coords.x.stop = x;
			}

			// y
			if(screen.bounds.y > coords.y.start){ coords.y.start = screen.bounds.y }
			var y = screen.bounds.y + screen.bounds.height;
			if(y > coords.y.stop){
				coords.y.stop = y;
			}
		});
		coords.width = coords.x.stop - coords.x.start;
		coords.height = coords.y.stop - coords.y.start;
		return coords;
	},
	getProgram: function(filename){
		var results = {
			filename: filename,
			coords: this.getCoords(),
			opts: [],
			program: false
		}
		switch(global.app.os){
			case "win32":
				results.program = "./libs/windows/screenshot.exe";
				results.opts.push('-o');
				results.opts.push('"' + filename + '"');
				results.opts.push('-rc');
				results.opts.push(results.coords.x.start);
				results.opts.push(results.coords.y.start);
				results.opts.push(results.coords.x.stop);
				results.opts.push(results.coords.y.stop);
			break;
		}
		return results;
	}
}


text:
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Navigation;

namespace MaterialDesignThemes.Wpf
{
    public enum ShadowDepth
    {
        Depth0,
        Depth1,
        Depth2,
        Depth3,
        Depth4,
        Depth5
    }

    internal class ShadowLocalInfo
    {
        public ShadowLocalInfo(double standardOpacity)
        {
            StandardOpacity = standardOpacity;
        }

        public double StandardOpacity { get; }
    }

    public static class ShadowAssist
    {
        public static readonly DependencyProperty ShadowDepthProperty = DependencyProperty.RegisterAttached(
            "ShadowDepth", typeof (ShadowDepth), typeof (ShadowAssist), new FrameworkPropertyMetadata(default(ShadowDepth), FrameworkPropertyMetadataOptions.AffectsRender));

        public static void SetShadowDepth(DependencyObject element, ShadowDepth value)
        {
            element.SetValue(ShadowDepthProperty, value);
        }

        public static ShadowDepth GetShadowDepth(DependencyObject element)
        {
            return (ShadowDepth) element.GetValue(ShadowDepthProperty);
        }

        private static readonly DependencyPropertyKey LocalInfoPropertyKey = DependencyProperty.RegisterAttachedReadOnly(
            "LocalInfo", typeof (ShadowLocalInfo), typeof (ShadowAssist), new PropertyMetadata(default(ShadowLocalInfo)));

        private static void SetLocalInfo(DependencyObject element, ShadowLocalInfo value)
        {
            element.SetValue(LocalInfoPropertyKey, value);
        }

        private static ShadowLocalInfo GetLocalInfo(DependencyObject element)
        {
            return (ShadowLocalInfo) element.GetValue(LocalInfoPropertyKey.DependencyProperty);
        }

        public static readonly DependencyProperty DarkenProperty = DependencyProperty.RegisterAttached(
            "Darken", typeof (bool), typeof (ShadowAssist), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.AffectsRender, DarkenPropertyChangedCallback));

        private static void DarkenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            var uiElement = dependencyObject as UIElement;
            var dropShadowEffect = uiElement?.Effect as DropShadowEffect;

            if (dropShadowEffect == null) return;

            if ((bool) dependencyPropertyChangedEventArgs.NewValue)
            {
                SetLocalInfo(dependencyObject, new ShadowLocalInfo(dropShadowEffect.Opacity));

                var doubleAnimation = new DoubleAnimation(1, new Duration(TimeSpan.FromMilliseconds(350)))
                {
                    FillBehavior = FillBehavior.HoldEnd
                };
                dropShadowEffect.BeginAnimation(DropShadowEffect.OpacityProperty, doubleAnimation);
            }
            else
            {
                var shadowLocalInfo = GetLocalInfo(dependencyObject);
                if (shadowLocalInfo == null) return;

                var doubleAnimation = new DoubleAnimation(shadowLocalInfo.StandardOpacity, new Duration(TimeSpan.FromMilliseconds(350)))
                {
                    FillBehavior = FillBehavior.HoldEnd
                };
                dropShadowEffect.BeginAnimation(DropShadowEffect.OpacityProperty, doubleAnimation);
            }
        }

        public static void SetDarken(DependencyObject element, bool value)
        {
            element.SetValue(DarkenProperty, value);
        }

        public static bool GetDarken(DependencyObject element)
        {
            return (bool) element.GetValue(DarkenProperty);
        }

        public static readonly DependencyProperty CacheModeProperty = DependencyProperty.RegisterAttached(
            "CacheMode", typeof(CacheMode), typeof(ShadowAssist), new FrameworkPropertyMetadata(new BitmapCache { EnableClearType = true, SnapsToDevicePixels = true }, FrameworkPropertyMetadataOptions.Inherits));

        public static void SetCacheMode(DependencyObject element, CacheMode value)
        {
            element.SetValue(CacheModeProperty, value);
        }

        public static CacheMode GetCacheMode(DependencyObject element)
        {
            return (CacheMode)element.GetValue(CacheModeProperty);
        }

    }
}


text:
var request = require("request");
var RX = require("rx");

module.exports = function(obj, interval){
  var interval = RX.Observable.interval(interval || 5000);
  var subject = new RX.BehaviorSubject(1);
  var req = RX.Observable.fromCallback(request);

  return RX.Observable.merge(subject, interval)
  .map(function(){
    return req(obj)
  })
  .flatMap(function(obs){
    return obs.catch(function(error){
      return Rx.Observable.return(error);
    });
  })
  .map(function(val){
    return val[2];
  })
  .publish()
  .refCount();
}


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

<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

001
016
017package net.jsign.pe;
018
019import java.io.IOException;
020import java.nio.ByteBuffer;
021import java.nio.ByteOrder;
022
023/**
024 * Entry of the data directory.
025 *
026 * @author Emmanuel Bourg
027 * @since 1.0
028 */
029public class DataDirectory {
030
031    private PEFile peFile;
032    private int index;
033
034    DataDirectory(PEFile peFile, int index) {
035        this.peFile = peFile;
036        this.index = index;
037    }
038
039    public long getVirtualAddress() {
040        return peFile.readDWord(peFile.getDataDirectoryOffset(), index * 8);
041    }
042
043    public int getSize() {
044        return (int) peFile.readDWord(peFile.getDataDirectoryOffset(), index * 8 + 4);
045    }
046
047    public boolean exists() {
048        return getVirtualAddress() != 0 && getSize() != 0;
049    }
050
051    /**
052     * Fill the data directory with zeros.
053     *
054     * @since 2.0
055     */
056    public void erase() {
057        peFile.write(getVirtualAddress(), new byte[getSize()]);
058    }
059
060    /**
061     * Tells if the data directory is at the end of the file.
062     *
063     * @return <code>true</code> if the data directory is at the end of the file, <code>false</code> otherwise
064     * @throws IOException if an I/O error occurs
065     * @since 2.0
066     */
067    public boolean isTrailing() throws IOException {
068        return getVirtualAddress() + getSize() == peFile.channel.size();
069    }
070
071    public void write(long virtualAddress, int size) {
072        ByteBuffer buffer = ByteBuffer.allocate(8);
073        buffer.order(ByteOrder.LITTLE_ENDIAN);
074        buffer.putInt((int) virtualAddress);
075        buffer.putInt(size);
076        peFile.write(peFile.getDataDirectoryOffset() + index * 8, buffer.array());
077    }
078}


text:
import fs from 'node:fs';
import table from 'text-table';
import tableify from '@kessler/tableify';
import tablemark from 'tablemark';

/**
 * Formats package information as json string.
 * @param dataAsArray - array of objects with information about dependencies / devdependencies in package.json
 * @param config - global configuration object
 * @returns dataAsArray formatted as json string
 */
function formatAsJsonString(dataAsArray, config) {
	return JSON.stringify(dataAsArray)
}

/**
 * Formats package information as table.
 * @param dataAsArray - array of objects with information about dependencies / devdependencies in package.json
 * @param config - global configuration object
 * @returns dataAsArray formatted as table string
 */
function formatAsTable(dataAsArray, config) {
	let data = arrayOfObjectsToArrayOfArrays(dataAsArray)
	let labels = []
	let lines = []

	// create a labels array and a lines array
	// the lines will be the same length as the label's
	for (let i = 0; i < config.fields.length; i++) {
		let label = config[config.fields[i]].label
		labels.push(label)
		lines.push('-'.repeat(label.length))
	}

	data.unshift(lines)
	data.unshift(labels)

	return table(data)
}

/**
 * Formats package information as csv string.
 * The names of the properties are used as column headers (if config.csvHeaders is true).
 * @param dataAsArray - array of objects with information about dependencies / devdependencies in package.json
 * @param config - global configuration object
 * @returns dataAsArray formatted as csv string
 */
function formatAsCsv(dataAsArray, config) {
	let data = arrayOfObjectsToArrayOfArrays(dataAsArray)
	let csv = []
	const delimiter = config.delimiter
	const escapeFields = config.escapeCsvFields

	if (config.csvHeaders) {
		let labels = []
		// create a labels array and a lines array
		for (let i = 0; i < config.fields.length; i++) {
			labels.push(config[config.fields[i]].label)
		}
		csv.push(labels.join(delimiter))
	}

	for (const element of data) {
		const validatedFields = element.map(fieldValue => {
			let validatedField = fieldValue
			if (fieldValue.includes(delimiter)) {
				console.warn(`Warning: field contains delimiter; value: "${fieldValue}"`)
				if (escapeFields) {
					validatedField = `"${fieldValue}"`
				}
			}
			return validatedField
		})

		csv.push(validatedFields.join(delimiter))
	}

	return csv.join('\n')
}

/**
 * Formats package information as html. The names of the properties are used as column headers.
 * To use the labels of the properties set in config as headers, the properties are renamed.
 * @param dataAsArray - array of objects with information about dependencies / devdependencies in package.json
 * @param config - global configuration object
 * @returns dataAsArray formatted as html
 */
function formatAsHTML(dataAsArray, config) {
	let rowsToBeDisplayed
	if (dataAsArray.length > 0) {
		rowsToBeDisplayed = dataAsArray.map(row => renameRowsProperties(row, config))
	} else {
		rowsToBeDisplayed = [ dataArrayWithEmptyRow(config) ]
	}

	return tableify.htmlDoc(rowsToBeDisplayed, config.html.tableify, fs.readFileSync(config.html.cssFile))
}

/**
 * Formats package information as a markdown table. The names of the properties are used as column headers.
 * @param dataAsArray - array of objects with information about dependencies / devdependencies in package.json
 * @param config - global configuration object
 * @returns dataAsArray formatted as a markdown table
 */
function formatAsMarkdown(dataAsArray, config) {
	// Respect the possibly overridden field names
	const dataAsArrayWithRenamedFields = dataAsArray.map(row => renameRowsProperties(row, config))

	return tablemark(dataAsArrayWithRenamedFields, config.tablemarkOptions);
  }

/**
 * Gets the formatter function for the style given.
 * Allowed styles: 'json', 'table', 'csc'.
 * Function signature: function(dataAsArray, config)
 * dataAsArray: array of objects with information about dependencies / devdependencies in package.json,
 * config: global configuration object
 * @param style - output style to be generated
 * @returns function to format the data; signature: function(dataAsArray, config)
 */
function getFormatter(style) {
	let formatter
	switch (style) {
		case 'json':
			formatter = formatAsJsonString
			break
		case 'table':
			formatter = formatAsTable
			break
		case 'csv':
			formatter = formatAsCsv
			break
		case 'html':
			formatter = formatAsHTML
			break
		case 'markdown':
			formatter = formatAsMarkdown
			break
		default:
			throw new Error('invalid output format in config')
	}

	return formatter
}

function arrayOfObjectsToArrayOfArrays(arrayOfObjects) {
	const arrayOfArrays = arrayOfObjects.map(objectElement => {
		let objectAsArray = Object.values(objectElement)
		return objectAsArray.map(arrayElement => !isNullOrUndefined(arrayElement) ? arrayElement : 'n/a')
	})
	return arrayOfArrays
}

function isNullOrUndefined(value) {
	return ((value === undefined) || (value === null))
}

/**
 * Rename the property of an object
 * @param {string} oldProp - old name of the property
 * @param {string} newProp - new name of the property
 * @param {object} anonymous - object with the property to be renamed
 * @returns {object} object with the renamed property
 */
function renameProp(oldProp, newProp, { [oldProp]: old, ...others }) {
  const newObject = {[newProp]:old, ...others}
  return newObject
}

/**
 * Rename each property of row with the value of its label from config
 * @param {object} row - object with data of one row to be displayed
 * @param {object} config - configuration object
 */
function renameRowsProperties(row, config) {
	let renamedRow = row
	for (let i = config.fields.length - 1; i >= 0; i--) {
		const fieldname = config.fields[i];
		renamedRow = renameProp(fieldname, config[fieldname].label, renamedRow)
	}
	return renamedRow
}

/**
 * Create an object with one property for every field listed in config.fields;
 * the properties value is always an empty space character
 * The order of the fields is inverse, as renameRowsProperties used in formatAsHTML
 * reverses the order of the fields in the object
 * @param {object} config - configuration object
 * @returns {object} dummy entry with one space as value
 */
function dataArrayWithEmptyRow(config) {
	let emptyRow = {}
	// create an array with 1 line of empty entries, to display empty table with header
	for (let i = config.fields.length - 1; i >= 0; i--) {
		let label = config[config.fields[i]].label
		emptyRow[label] = ' '
	}
	return emptyRow
}

export default getFormatter;


text:
@implementation APITransaction

- (instancetype)initWithBaseUrl:(NSString*)newBaseURL
{
    if (self = [super init])
    {
        self.baseURL = newBaseURL;
        params = @"";
        httpMethod = @"POST";
    }

    return self;
}

- (void)goWithSuccessHandler:(void (^)())successHandler errorHandler:(void (^)(NSString*))errorHandler
{
    self.successHandler = successHandler;
    self.errorHandler = errorHandler;

    NSString *contentType;
    NSData *data;
    if (jsonParams)
    {
        contentType = @"application/json";
        data = jsonParams;
    }
    else
    {
        contentType = @"application/x-www-form-urlencoded";
        data = [params dataUsingEncoding:NSUTF8StringEncoding];
    }

    if  ([data length] > BODY_SIZE_LIMIT)
    {
        self.errorHandler(@"Invalid message size");
    }
    else
    {
        NSURL *theURL = [NSURL URLWithString:self.baseURL];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:HTTP_TIMEOUT];
        [request setHTTPMethod:httpMethod];
        [request setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
        [request setValue:contentType forHTTPHeaderField:@"Content-Type"];
        [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[data length]] forHTTPHeaderField:@"Content-length"];
        [request setHTTPBody:data];
        connection = [NSURLConnection connectionWithRequest:request delegate:self];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSInteger httpStatus = ((NSHTTPURLResponse*)response).statusCode;

    if (401 == httpStatus)
    {
        self.errorMessage = @"API authentication error";
    }
    else if (httpStatus == 429)
    {
        self.errorMessage = @"API rate limit was exceeded";
    }
    else if (httpStatus == 503)
    {
        self.errorMessage = @"Server is down for maintenance";
    }
    else if (httpStatus >= 400)
    {
        self.errorMessage = [NSString stringWithFormat:@"Failed with server error %ld!", (long)httpStatus];
    }
    else
    {
        self.success = YES;
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    if (!self.receivedData)
    {
        self.receivedData = [NSMutableData dataWithData:data];
    }
    else
    {
        [self.receivedData appendData:data];
    }
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [self transactionComplete];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    if ((error.code == NSURLErrorUserCancelledAuthentication) || (error.code == NSURLErrorUserAuthenticationRequired))
    {
        self.errorMessage = @"API authentication error";
    }
    else if (error.code == NSURLErrorBadServerResponse)
    {
        self.errorMessage = @"Failed with status code 500";
    }
    else
    {
        self.errorMessage = @"Unable to reach server";
    }

    self.success = NO;

    [self transactionComplete];
}

- (void)transactionComplete
{
    // overridden by child classes

    if (self.success)
    {
        NSError *error;
        self.jsonResult = [NSJSONSerialization JSONObjectWithData:self.receivedData options:0 error:&error];

        if (error)
        {
            NSLog(@"------%@: error deserializing response: %@", [self class], [error localizedDescription]);
            self.errorMessage = @"Unexpected response from server";
            self.success = NO;
        }
    }
}

- (void)cancel
{
    abort = YES;
    [connection cancel];
}

@end


text:
OVC_EXTERN
OVCURLMatcher *OVCHTTPManagerCreateURLMatcher(id<OVCHTTPManager> httpManager) {
    return [[OVCURLMatcher alloc] initWithBasePath:httpManager.baseURL.path
                                modelClassesByPath:[[httpManager class] modelClassesByResourcePath]];
}

OVC_EXTERN
OVCURLMatcher * OVC__NULLABLE OVCHTTPManagerCreateResponseClassURLMatcher(id<OVCHTTPManager> httpManager) {
    OVCURLMatcher *responseClassMatcher = nil;

    NSDictionary OVCGenerics(NSString *, Class) *responseClassesByResourcePath = [[httpManager class]
                                                                                responseClassesByResourcePath];
    if (responseClassesByResourcePath) {
#if DEBUG
        // Check if all the classes used in responseClassesByResourcePath are subclasses of OVCResponse
        [responseClassesByResourcePath
         enumerateKeysAndObjectsUsingBlock:^(NSString *path, Class responseClass, BOOL *stop) {
             if (![responseClass isSubclassOfClass:[OVCResponse class]]) {
                 [NSException
                  raise:NSInternalInconsistencyException
                  format:@"%@ is not a subclass of %@",
                  NSStringFromClass(responseClass), NSStringFromClass([OVCResponse class])];
             }
         }];
#endif
        responseClassMatcher = [[OVCURLMatcher alloc] initWithBasePath:httpManager.baseURL.path
                                                    modelClassesByPath:responseClassesByResourcePath];
    }
    return responseClassMatcher;
}

OVC_EXTERN
OVCModelResponseSerializer *OVCHTTPManagerCreateModelResponseSerializer(id<OVCHTTPManager> httpManager) {
    return [OVCModelResponseSerializer serializerWithURLMatcher:OVCHTTPManagerCreateURLMatcher(httpManager)
                                        responseClassURLMatcher:OVCHTTPManagerCreateResponseClassURLMatcher(httpManager)
                                                  responseClass:[[httpManager class] responseClass]
                                                errorModelClass:[[httpManager class] errorModelClass]];
}


text:
package org.apache.nifi.processors.standard;

import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.Test;

public class TestValidateCsv {

    @Test
    public void testHeaderAndSplit() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "true");
        runner.setProperty(ValidateCsv.VALIDATION_STRATEGY, ValidateCsv.VALIDATE_LINES_INDIVIDUALLY);

        runner.setProperty(ValidateCsv.SCHEMA, "Null, ParseDate(\"dd/MM/yyyy\"), Optional(ParseDouble())");

        runner.enqueue("Name,Birthdate,Weight\nJohn,22/11/1954,63.2\nBob,01/03/2004,45.0");
        runner.run();

        runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
        runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63.2\nBob,01/03/2004,45.0");
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);

        runner.clearTransferState();

        runner.enqueue("Name,Birthdate,Weight\nJohn,22/11/1954,63a2\nBob,01/032004,45.0");
        runner.run();

        runner.assertTransferCount(ValidateCsv.REL_VALID, 0);
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
        runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/11/1954,63a2\nBob,01/032004,45.0");

        runner.clearTransferState();

        runner.enqueue("Name,Birthdate,Weight\nJohn,22/111954,63.2\nBob,01/03/2004,45.0");
        runner.run();

        runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
        runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("Name,Birthdate,Weight\nBob,01/03/2004,45.0");
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
        runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Name,Birthdate,Weight\nJohn,22/111954,63.2");
    }

    @Test
    public void testNullValues() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "true");
        runner.setProperty(ValidateCsv.VALIDATION_STRATEGY, ValidateCsv.VALIDATE_LINES_INDIVIDUALLY);

        runner.setProperty(ValidateCsv.SCHEMA, "Null, Null, Null");

        runner.enqueue("#Name,Birthdate,Weight\nJohn,\"\",63.2\nBob,,45.0");
        runner.run();

        runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
        runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("#Name,Birthdate,Weight\nJohn,,63.2\nBob,,45.0");
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 0);
    }

    @Test
    public void testUniqueWithSplit() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");
        runner.setProperty(ValidateCsv.VALIDATION_STRATEGY, ValidateCsv.VALIDATE_LINES_INDIVIDUALLY);

        runner.setProperty(ValidateCsv.SCHEMA, "Unique()");

        runner.enqueue("John\r\nBob\r\nBob\r\nJohn");
        runner.run();

        runner.assertTransferCount(ValidateCsv.REL_VALID, 1);
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);

        runner.getFlowFilesForRelationship(ValidateCsv.REL_VALID).get(0).assertContentEquals("John\r\nBob");
        runner.getFlowFilesForRelationship(ValidateCsv.REL_INVALID).get(0).assertContentEquals("Bob\r\nJohn");
    }

    @Test
    public void testValidDateOptionalDouble() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "Null, ParseDate(\"dd/MM/yyyy\"), Optional(ParseDouble())");

        runner.enqueue("John,22/11/1954,63.2\r\nBob,01/03/2004,45.0");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("John,22/111954,63.2\r\nBob,01/03/2004,45.0");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testIsIncludedIn() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "Null, ParseDate(\"dd/MM/yyyy\"), IsIncludedIn(\"male\", \"female\")");

        runner.enqueue("John,22/11/1954,male\r\nMarie,01/03/2004,female");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("John,22/111954,63.2\r\nBob,01/03/2004,45.0");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testBigDecimalBoolCharIntLong() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "true");

        runner.setProperty(ValidateCsv.SCHEMA, "ParseBigDecimal(), ParseBool(), ParseChar(), ParseInt(), ParseLong()");

        runner.enqueue("bigdecimal,bool,char,integer,long\r\n10.0001,true,c,1,92147483647");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("bigdecimal,bool,char,integer,long\r\n10.0001,true,c,92147483647,92147483647");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testEqualsNotNullStrNotNullOrEmpty() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "Equals(), NotNull(), StrNotNullOrEmpty()");

        runner.enqueue("test,test,test\r\ntest,test,test");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("test,test,test\r\ntset,test,test");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testStrlenStrMinMaxStrRegex() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "Strlen(4), StrMinMax(3,5), StrRegex(\"[a-z0-9\\._]+@[a-z0-9\\.]+\")");

        runner.enqueue("test,test,test@apache.org");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("test,test,testapache.org");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testDMinMaxForbidSubStrLMinMax() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "DMinMax(10,100),LMinMax(10,100),ForbidSubStr(\"test\", \"tset\")");

        runner.enqueue("50.001,50,hello");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("10,10,testapache.org");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testUnique() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "Unique(), UniqueHashCode()");

        runner.enqueue("1,2\r\n3,4");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("1,2\r\n1,4");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testRequire() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        int hashcode = "test".hashCode();
        runner.setProperty(ValidateCsv.SCHEMA, "RequireHashCode(" + hashcode + "), RequireSubStr(\"test\")");

        runner.enqueue("test,test");
        runner.run();
        runner.assertAllFlowFilesTransferred(ValidateCsv.REL_VALID, 1);

        runner.enqueue("tset,tset");
        runner.run();
        runner.assertTransferCount(ValidateCsv.REL_INVALID, 1);
    }

    @Test
    public void testValidate() {
        final TestRunner runner = TestRunners.newTestRunner(new ValidateCsv());
        runner.setProperty(ValidateCsv.DELIMITER_CHARACTER, ",");
        runner.setProperty(ValidateCsv.END_OF_LINE_CHARACTER, "\r\n");
        runner.setProperty(ValidateCsv.QUOTE_CHARACTER, "\"");
        runner.setProperty(ValidateCsv.HEADER, "false");

        runner.setProperty(ValidateCsv.SCHEMA, "RequireSubString(\"test\")");
        runner.assertNotValid();

        runner.setProperty(ValidateCsv.SCHEMA, "''");
        runner.assertNotValid();

        runner.setProperty(ValidateCsv.SCHEMA, "\"\"");
        runner.assertNotValid();
    }

}


text:
package com.github.siphon;

import java.io.DataInputStream;
import java.io.IOException;

public abstract class ConstantInfoFactory {
    public abstract ConstantInfo create(DataInputStream in) throws IOException;

    public abstract ConstantInfo.Type getType();
}


text:
class ComputerVisionDemoController < ApplicationController

  def index
    render layout: "basic"
  end

end


text:
layout: post
author: "Ted Hart"
title: Thoughts on an Advanced Bootcamp at Boulder
date: 2013-06-07
time: "09:00:00"
category: ["National Center for Atmospheric Research"]
---

  Alex Viana and myself recently wrapped up a bootcamp at the National Center for Atmosphere Research (NCAR) in Boulder, CO.
  It was a lesson in the advantages of being light on your feet when it comes to teaching for Software Carpentry.
  Our normal audience tends to be scientists with varying degrees of familiarity with the tools that we teach.
  This time we taught about 20 people all of whom were experience software engineers,
  some of whom had probably been programming longer than Alex or I had been alive.
  We had planned on starting the morning with some shell and then moving into Git.
  A quick survey of the room found that everyone was well versed in the shell
  so we abandoned that lesson all together and went straight to teaching Git.

  Here was where things got interesting.
  I thought we'd fly through our material because everyone was so experienced.
  Instead though it almost seemed that we moved more slowly because not only were we teaching Git,
  but also how git was different than SVN and CVS (other version control systems for the uninitiated).
  Later in the day we also got into a deep conversation about what types of workflow Git could be used for compared to SVN and CVS.

  We had a similar experience the next day teaching Python.
  Instead of just churning through it we spent a lot of our time talking about
  how Python was different than other languages the participants programmed in like Java.
  It turned out that teaching such an advanced crowd meant that we had a group that knew what questions to ask.
  Topics that we normally gloss over (what is an iterator anyway?) we had to really pick apart because of the knowledge in the room.

  As instructors there were two really important lessons for us.
  The first is never assume that you're the most knowledgeable person in the room.
  The corollary to that is that just because you aren't doesn't mean you don't have something to teach.
  We even had a couple of really skilled Python programmers
  who were happy to be there just to see how they could become better teachers.
  At first we were a bit intimidated by the depth of knowledge,
  but really it just forced us to up our game as instructors and I think we're better for it.

  The second lesson was that you can never forget that a bootcamp needs to be adaptable.
  Alex and I were challenged to create curriculum on the spot when we skipped over our 2 hours of the shell.
  We had to keep in mind that we were there to teach not just stand and deliver a canned lesson
  even if participants already knew it all.
  And that's the really great thing about Software Carpentry all around.
  All the instructors are creative and smart people who are dedicated to being good teachers
  and don't shy away from these kinds of unexpected challenges.
  The NCAR bootcamp was definitely my most challenging,
  but it also offered one of the best opportunities for growth as an instructor.


text:
namespace display {
class NativeDisplayDelegate;
}

namespace ui {
enum class DomCode;
enum class PlatformKeyboardHookTypes;

class CursorFactory;
class GpuPlatformSupportHost;
class ImeKeyEventDispatcher;
class InputMethod;
class InputController;
class KeyEvent;
class OverlayManagerOzone;
class PlatformClipboard;
class PlatformGLEGLUtility;
class PlatformGlobalShortcutListener;
class PlatformGlobalShortcutListenerDelegate;
class PlatformKeyboardHook;
class PlatformMenuUtils;
class PlatformScreen;
class PlatformUserInputMonitor;
class PlatformUtils;
class SurfaceFactoryOzone;
class SystemInputInjector;

struct PlatformWindowInitProperties;

// Base class for Ozone platform implementations.
//
// Ozone platforms must override this class and implement the virtual
// GetFooFactoryOzone() methods to provide implementations of the
// various ozone interfaces.
//
// The OzonePlatform subclass can own any state needed by the
// implementation that is shared between the various ozone interfaces,
// such as a connection to the windowing system.
//
// A platform is free to use different implementations of each
// interface depending on the context. You can, for example, create
// different objects depending on the underlying hardware, command
// line flags, or whatever is appropriate for the platform.
class COMPONENT_EXPORT(OZONE) OzonePlatform {
 public:
  OzonePlatform();

  OzonePlatform(const OzonePlatform&) = delete;
  OzonePlatform& operator=(const OzonePlatform&) = delete;

  virtual ~OzonePlatform();

  // Additional initialization params for the platform. Platforms must not
  // retain a reference to this structure.
  struct InitParams {
    // Setting this to true indicates that the platform implementation should
    // operate as a single process for platforms (i.e. drm) that are usually
    // split between a host and viz specific portion.
    bool single_process = false;

    // Setting this to true indicates the the platform can do additional
    // initialization for the GpuMemoryBuffer framework.
    bool enable_native_gpu_memory_buffers = false;

    // The direct VideoDecoder is disallowed on some particular SoC/platforms.
    // This flag is a reflection of whatever the ChromeOS command line builder
    // says. If false, overlay manager will not use synchronous pageflip
    // testing with real buffer.
    // TODO(fangzhoug): Some Chrome OS boards still use the legacy video
    // decoder. Remove this once ChromeOSVideoDecoder is on everywhere.
    bool allow_sync_and_real_buffer_page_flip_testing = false;
  };

  // Struct used to indicate platform properties.
  struct PlatformProperties {
    PlatformProperties();
    PlatformProperties(const PlatformProperties& other) = delete;
    PlatformProperties& operator=(const PlatformProperties& other) = delete;
    ~PlatformProperties();

    // Fuchsia only: set to true when the platforms requires |view_token| field
    // in PlatformWindowInitProperties when creating a window.
    bool needs_view_token = false;

    // Determines whether we should default to native decorations or the custom
    // frame based on the currently-running window manager.
    bool custom_frame_pref_default = false;

    // Determines the type of message pump that should be used for GPU main
    // thread.
    base::MessagePumpType message_pump_type_for_gpu =
        base::MessagePumpType::DEFAULT;

    // Determines the type of message pump that should be used for viz
    // compositor thread.
    base::MessagePumpType message_pump_type_for_viz_compositor =
        base::MessagePumpType::DEFAULT;

    // Determines if the platform supports vulkan swap chain.
    bool supports_vulkan_swap_chain = false;

    // Linux only: determines if the platform uses the external Vulkan image
    // factory.
    bool uses_external_vulkan_image_factory = false;

    // Linux only: determines if Skia can fall back to the X11 output device.
    bool skia_can_fall_back_to_x11 = false;

    // Wayland only: determines whether windows which are not top level ones
    // should be given parents explicitly.
    bool set_parent_for_non_top_level_windows = false;

    // If true, the platform shows and updates the drag image.
    bool platform_shows_drag_image = true;

    // Linux only, but see a TODO in BrowserDesktopWindowTreeHostLinux.
    // Determines whether the platform supports the global application menu.
    bool supports_global_application_menus = false;

    // Determines if the application modal dialogs should use the event blocker
    // to allow the only browser window receiving UI events.
    bool app_modal_dialogs_use_event_blocker = false;

    // Determines whether buffer formats should be fetched on GPU and passed
    // back via gpu extra info.
    bool fetch_buffer_formats_for_gmb_on_gpu = false;

#if BUILDFLAG(IS_LINUX)
    // TODO(crbug.com/1116701): add vaapi support for other Ozone platforms on
    // Linux. At the moment, VA-API Linux implementation supports only X11
    // backend. This implementation must be refactored to support Ozone
    // properly. As a temporary solution, VA-API on Linux checks if vaapi is
    // supported (which implicitly means that it is Ozone/X11).
    bool supports_vaapi = false;
#endif

    // Indicates that the platform allows client applications to manipulate
    // global screen coordinates. Wayland, for example, disallow it by design.
    bool supports_global_screen_coordinates = true;
  };

  // Groups platform properties that can only be known at run time.
  struct PlatformRuntimeProperties {
    // Values to override the value of the
    // supports_server_side_window_decorations property in tests.
    enum class SupportsSsdForTest {
      kNotSet,  // The property is not overridden.
      kYes,     // The platform should return true.
      kNo,      // The plafrorm should return false.
    };

    // Whether the underlying platform supports deferring compositing of buffers
    // via overlays. If overlays are not supported the promotion and validation
    // logic can be skipped.
    bool supports_overlays = false;
    // Indicates whether the platform supports server-side window decorations.
    bool supports_server_side_window_decorations = true;

    // For platforms that have optional support for server-side decorations,
    // this parameter allows setting the desired state in tests.  The platform
    // must have the appropriate logic in its GetPlatformRuntimeProperties()
    // method.
    static SupportsSsdForTest override_supports_ssd_for_test;

    // Wayland only: determines whether solid color overlays can be delegated
    // without a backing image via a wayland protocol.
    bool supports_non_backed_solid_color_buffers = false;

    // Indicates whether the platform supports native pixmaps.
    bool supports_native_pixmaps = false;

    // Wayland only: determines whether BufferQueue needs a background image to
    // be stacked below an AcceleratedWidget to make a widget opaque.
    bool needs_background_image = false;

    // Wayland only: determines whether clip rects can be delegated via the
    // wayland protocol.
    bool supports_clip_rect = false;
  };

  // Corresponds to chrome_browser_main_extra_parts.h.
  //
  // The browser process' initialization involves several steps -
  // PreEarlyInitialization, PostCreateMainMessageLoop, PostMainMessageLoopRun,
  // etc. In order to be consistent with that and allow platform specific
  // initialization steps, the OzonePlatform has three methods - one static
  // PreEarlyInitialization that is expected to do some early non-ui
  // initialization (like error handlers that X11 sets), and two non-static
  // methods - PostMainmessageLoopStart and PostMainMessageLoopRun. The latter
  // two are supposed to be called on a post start and a post-run of the
  // MessageLoop. Please note that this methods must be run on the browser' UI
  // thread.
  //
  // Creates OzonePlatform and does pre-early initialization (internally, sets
  // error handlers if supported so that we can print errors during the browser
  // process' start up).
  static void PreEarlyInitialization();
  // Sets error handlers if supported for the browser process after the message
  // loop started. It's required to call this so that we can exit cleanly if the
  // server can exit before we do.
  virtual void PostCreateMainMessageLoop(
      base::OnceCallback<void()> shutdown_cb);
  // Resets the error handlers if set.
  virtual void PostMainMessageLoopRun();

  // Initializes the subsystems/resources necessary for the UI process (e.g.
  // events) with additional properties to customize the ozone platform
  // implementation. Ozone will not retain InitParams after returning from
  // InitializeForUI.
  // Returns whether the initialisation completed successfully.  Should this
  // have returned false, the browser must stop the startup and exit because it
  // would not be able to work normally.
  static bool InitializeForUI(const InitParams& args);

  // Initializes the subsystems for rendering but with additional properties
  // provided by |args| as with InitalizeForUI.
  static void InitializeForGPU(const InitParams& args);

  static OzonePlatform* GetInstance();

  static bool IsInitialized();

  // Returns the current ozone platform name.
  // Some tests may skip based on the platform name.
  static std::string GetPlatformNameForTest();

  // Factory getters to override in subclasses. The returned objects will be
  // injected into the appropriate layer at startup. Subclasses should not
  // inject these objects themselves. Ownership is retained by OzonePlatform.
  virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() = 0;
  virtual ui::OverlayManagerOzone* GetOverlayManager() = 0;
  virtual ui::CursorFactory* GetCursorFactory() = 0;
  virtual ui::InputController* GetInputController() = 0;
  virtual ui::GpuPlatformSupportHost* GetGpuPlatformSupportHost() = 0;
  virtual std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() = 0;
  virtual std::unique_ptr<PlatformWindow> CreatePlatformWindow(
      PlatformWindowDelegate* delegate,
      PlatformWindowInitProperties properties) = 0;
  virtual std::unique_ptr<display::NativeDisplayDelegate>
  CreateNativeDisplayDelegate() = 0;
  // Creates a new PlatformScreen subclass from the factory subclass.
  virtual std::unique_ptr<PlatformScreen> CreateScreen() = 0;
  // This function must be called immediately after CreateScreen with the
  // `screen` that was returned from CreateScreen.  They are separated to avoid
  // observer recursion into display::Screen from inside CreateScreen.
  virtual void InitScreen(PlatformScreen* screen) = 0;
  virtual PlatformClipboard* GetPlatformClipboard();
  virtual std::unique_ptr<InputMethod> CreateInputMethod(
      ImeKeyEventDispatcher* ime_key_event_dispatcher,
      gfx::AcceleratedWidget widget) = 0;
  virtual PlatformGLEGLUtility* GetPlatformGLEGLUtility();
  virtual PlatformMenuUtils* GetPlatformMenuUtils();
  virtual PlatformUtils* GetPlatformUtils();
  virtual PlatformGlobalShortcutListener* GetPlatformGlobalShortcutListener(
      PlatformGlobalShortcutListenerDelegate* delegate);
  // Returns the keyboard hook that captures the specified keys.  See more in
  // ui::KeyboardHook.  However, unlike that interface, Ozone tries to register
  // the hook that it has created, and returns the one only if it was registered
  // successfully.
  // Handles creating both modifier and media keyboard hooks.  |dom_codes| and
  // |accelerated_widget| are only used if |type| is
  // PlatformKeyboardHookTypes::kModifier.
  virtual std::unique_ptr<PlatformKeyboardHook> CreateKeyboardHook(
      PlatformKeyboardHookTypes type,
      base::RepeatingCallback<void(KeyEvent* event)> callback,
      absl::optional<base::flat_set<DomCode>> dom_codes,
      gfx::AcceleratedWidget accelerated_widget);

  // Returns true if the specified buffer format is supported.
  virtual bool IsNativePixmapConfigSupported(gfx::BufferFormat format,
                                             gfx::BufferUsage usage) const;

  // Returns whether a custom frame should be used for windows.
  // The default behaviour is returning what is suggested by the
  // custom_frame_pref_default property of the platform: if the platform
  // suggests using the custom frame, likely it lacks native decorations.
  // See https://crbug.com/1212555
  virtual bool ShouldUseCustomFrame();

  // Returns a struct that contains configuration and requirements for the
  // current platform implementation. This can be called from either host or GPU
  // process at any time.
  virtual const PlatformProperties& GetPlatformProperties();

  // Returns runtime properties of the current platform implementation available
  // after either InitializeUI() or InitializeGPU() runs. Runtime properties for
  // UI and GPU may be different depending on availability of platform objects.
  virtual const PlatformRuntimeProperties& GetPlatformRuntimeProperties();

  // Ozone platform implementations may also choose to expose mojo interfaces to
  // internal functionality. Embedders wishing to take advantage of ozone mojo
  // implementations must invoke AddInterfaces with a valid mojo::BinderMap
  // pointer to export all Mojo interfaces defined within Ozone.
  //
  // Requests arriving before they can be immediately handled will be queued and
  // executed later.
  //
  // A default do-nothing implementation is provided to permit platform
  // implementations to opt out of implementing any Mojo interfaces.
  virtual void AddInterfaces(mojo::BinderMap* binders);

  // The GPU-specific portion of Ozone would typically run in a sandboxed
  // process for additional security. Some startup might need to wait until
  // after the sandbox has been configured.
  // When the GPU is in a separate process, the embedder should call this method
  // after it has configured (or failed to configure) the sandbox so that the
  // GPU-side setup is completed. If the GPU is in-process, there is no
  // sandboxing and the embedder should not call this method.
  // A default do-nothing implementation is provided to permit platform
  // implementations to ignore sandboxing and any associated launch ordering
  // issues.
  virtual void AfterSandboxEntry();

  // Creates a user input monitor.
  // The user input comes from I/O devices and must be handled on the IO thread.
  // |io_task_runner| must be bound to the IO thread so the implementation could
  // ensure that calls happen on the right thread.
  virtual std::unique_ptr<PlatformUserInputMonitor> GetPlatformUserInputMonitor(
      const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);

 protected:
  bool has_initialized_ui() const { return initialized_ui_; }
  bool has_initialized_gpu() const { return initialized_gpu_; }

  bool single_process() const { return single_process_; }

  static bool ShouldFailInitializeUIForTest();

 private:
  friend class OzonePlatformTest;

  // For platforms that may fail at the early stage of initialising, sets so
  // that they fail.
  // See https://crbug.com/1280138.
  static void SetFailInitializeUIForTest(bool fail);

  // Optional method for pre-early initialization. In case of X11, sets X11
  // error handlers so that errors can be caught if early initialization fails.
  virtual void PreEarlyInitialize();

  // Initialises the platform in the UI process.  Returns whether that completed
  // successfully, i. e., the startup process may proceed further.
  // The platform implementation must check all conditions critical for normal
  // operation, and return false if any of them are not met (e. g., the display
  // server is not available).
  virtual bool InitializeUI(const InitParams& params) = 0;
  virtual void InitializeGPU(const InitParams& params) = 0;

  bool initialized_ui_ = false;
  bool initialized_gpu_ = false;
  bool prearly_initialized_ = false;

  // This value is checked on multiple threads. Declaring it volatile makes
  // modifications to |single_process_| visible by other threads. Mutex is not
  // needed since it's set before other threads are started.
  volatile bool single_process_ = false;
};

}  // namespace ui

#endif  // UI_OZONE_PUBLIC_OZONE_PLATFORM_H_


text:
<?php

namespace Sdfcloud\Acl\Models;

/**
 * Eloquent model for permissions table.
 * Permission will be used by Eloquent permissions provider.
 */
class Permission extends \Illuminate\Database\Eloquent\Model{
    protected $table = 'permissions';

    protected $fillable = array('id', 'allowed', 'module', 'route', 'resource_id_required', 'name', 'group_id', 'created_at', 'updated_at');

    public $timestamps = true;
}


text:
using System;

namespace _15.ThreeEqualNumbers
{
    public class ThreeEqualNumbers
    {
        public static void Main(string[] args)
        {
            var firstNum = double.Parse(Console.ReadLine());
            var secondNum = double.Parse(Console.ReadLine());
            var thirdNum = double.Parse(Console.ReadLine());

            Console.WriteLine(firstNum == secondNum && secondNum == thirdNum ? "yes" : "no");
        }
    }
}


text:
module SimpleEditable
  class ApplicationController < ActionController::Base
    before_filter :simple_editable_authentication_method

    private

    def simple_editable_authentication_method
      SimpleEditable.authentication_method ? send(SimpleEditable.authentication_method) : true
    end
  end
end


text:
$category@: ads-analytics
formats:
  - websites
teaser:
  text: Provides a way to display and stick ad content at the bottom of the page.
---

# amp-sticky-ad

## Usage

Provides a way to display and stick ad content at the bottom of the page.

-   There can be only one `<amp-sticky-ad>` in an AMP document. The `<amp-sticky-ad>` should only have one direct child: `<amp-ad>`. **Note**: Make sure you include any required scripts for the `<amp-ad>` component.
-   The sticky ad appears at the bottom of a page.
-   The sticky ad introduces a full-width blank container and then fills the sticky ad based on the width and height of the `<amp-ad>`.
-   The height of the sticky-ad is whatever its child needs up to its max-height.
-   The max-height of the sticky-ad is 100px, if the height exceeds 100px then the height would be 100px and overflow content will be hidden.
-   The width of the sticky-ad is set to 100% using CSS and cannot be overridden.
-   The opacity of the sticky-ad is set to 1 using CSS and cannot be overridden.
-   The background color of the sticky-ad can be customized to match the page style. However, any semi-transparent or transparent background will not be allowed and will be changed to a non-transparent color.
-   When scrolled to the bottom of the page, the viewport is automatically padded with the additional height of the sticky ad, so that no content is ever hidden.
-   When in landscape mode, the sticky ad is center-aligned.
-   The sticky ad can be dismissed and removed by a close button.
-   If no ad is filled, the sticky ad container will collapse and will no longer be visible.

Example:

```html
<amp-sticky-ad layout="nodisplay">
  <amp-ad
    width="320"
    height="50"
    type="doubleclick"
    data-slot="/35096353/amptesting/formats/sticky"
  >
  </amp-ad>
</amp-sticky-ad>
```

## Attributes

### layout (required)

Must be set to `nodisplay`.

## Styling

The `amp-sticky-ad` component can be styled with standard CSS.

-   The sticky ad container style can be set through the `amp-sticky-ad` CSS class.
-   The close button style can be set through the `amp-sticky-ad-close-button` CSS class.
-   The padding bar between the ad and the close button style can be set through the `amp-sticky-ad-top-padding` CSS class.

## Validation

See [amp-sticky-ad rules](https://github.com/ampproject/amphtml/blob/main/extensions/amp-sticky-ad/validator-amp-sticky-ad.protoascii) in the AMP validator specification.


text:
from __future__ import division, print_function
import numpy as np
from itertools import permutations  # necessary in LinTable

class Table(object):

    def __init__(self, n, nu, nd):

        self.nu = nu
        self.nd = nd
        self.n = n

        if nu > n or nd > n:
            self.Jdu, self.Nu, self.basisu = (['1'], 1, [])
            self.Jdv, self.Nd, self.basisd = (['1'], 1, [])
        else:
            self.Juv, self.Nu, self.basisu = states(self.n, self.nu)
            self.Jdv, self.Nd, self.basisd = states(self.n, self.nd)

    @property
    def Js(self):
        """get J indices"""
        return {'u': self.Juv, 'd': self.Jdv}

    @property
    def Ns(self):
        """Get the Ns"""
        return (self.Nu, self.Nd)

    @property
    def ns(self):
        return (self.nu, self.nd)

    @property
    def ne(self):
        return self.nu + self.nd

def states(n, nu):
    """
    Create all many-body spin states

    Parameters
    ----------
    n : int
        number of sites
    nu : int
        number of on spin-specie
    """
    x = [0]*(n-nu) + [1]*nu

    states = np.array(unique_permutations(x), dtype=int)

    N = states.shape[0]
    Jv = bi2de(states)

    return (Jv, N, states)

def state2index(states, Juv, Jdv=None):
    """
    Parameters
    ----------
    states : ndarray
        states to index
    Juv : list
        indexes of the spin-up subspace
    Jdv : list
        index of the spin-down subspace
    """

    Nu = Juv.shape[0]
    Ju = {J: i for i, J in enumerate(Juv)}

    if Jdv is None:
        if len(states.shape) < 2:
            states = np.array([states])
        Js = np.array([Ju[i] for i in bi2de(states)])
    else:
        # Nd = Jdv.shape[0]
        Jd = {J: i for i, J in enumerate(Jdv)}

        n = states.shape[1]/2

        Ius = bi2de(states[:, 1:n])
        Ids = bi2de(states[:, n+1:])

        Js = np.array([Jd[i] for i in Ids])*Nu + np.array([Ju[i] for i in Ius])

    return Js

def index2state(Is, n, Juv, Jdv=None):
    """
    Returns state with a given index

    Parameters
    ----------
    Is : ndarray
        list of indices
    n : int
        number of sites
    Juv : ndarray
        Lin table of spin-up states
    Jdv : ndarray
        Lin table for spin-down states
    """
    Nu = Juv.shape[0]

    if Jdv is None:
        Ius = np.mod(Is, Nu)
        states_up = de2bi(Juv[Ius], n)
        return states_up
    else:
        # Nd = Jdv.shape[0]
        Ius = np.mod(Is, Nu)
        Ids = np.floor(Is/Nu).astype(int)

        states_up = de2bi(Juv[Ius], n)
        states_down = de2bi(Jdv[Ids], n)

        return (states_up, states_down)

def unique_permutations(elements):
    """
    Get all unique permutations of a list of elements

    Parameters
    ----------
    elements : list
        a list containing the elements
    """
    n = len(elements)
    uniques = list(set(elements))
    nu = len(uniques)

    if not elements:
        return []
    elif n == 1 or nu == 1:
        return [elements]
    elif n == nu:
        ps = permutations(elements)
        return [list(p) for p in ps]
    else:
        pu = []
        # collect the results
        for i in np.arange(nu):
            # copy elements into v
            v = list(elements)
            # first instance of unique element
            ind = elements.index(uniques[i])
            # remove this element
            del v[ind]
            # extend the result
            pu.extend([[uniques[i]] + perm for perm in unique_permutations(v)])

    return pu

def bi2de(binaries):
    """
    Parameters
    ----------
    binaries : ndarray
        Here one row is one binary number.
    """
    n = binaries.shape[0]
    if len(binaries.shape) > 1:
        n = binaries.shape[1]
    decimals = np.dot(binaries, np.power(2, np.arange(n-1, -1, -1)))

    # print('d: {0}'.format(decimals))

    # if (decimals.size == 1):
        # return [decimals]

    return decimals

def de2bi(decimals, n=None):
    """
    Parameters
    ----------
    decimals : ndarray
        vector of decimals
    n : int
        number of binary digits
    """
    decimals = np.array(decimals)
    try:
        nd = np.ceil(np.log2(np.max(decimals)))
    except RuntimeWarning:
        print('{0}:{1}'.format(decimals, n))
    if n is None or n < nd:
        n = nd
    return np.remainder(np.floor(np.outer(decimals, np.power(2., np.arange(1-n,1)))), 2).astype(int)


text:
/*  RESTfulBlogApp
    Description: A Blog app that uses RESTful conventions and Semantic UI
    Includes: express, ejs, body-parser, and mongoose
*/

// Initialize -----------------------------------------

var express             = require("express"),
    app                 = express(),
    bodyParser          = require("body-parser"),
    methodOverride      = require("method-override"),
    expressSanitizer    = require("express-sanitizer"),
    mongoose            = require("mongoose"),
    faker               = require("faker");

app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended: true}));
app.use(methodOverride("_method"));
app.use(expressSanitizer());

// Configure Database ---------------------------------
// Uncomment below to create new database

mongoose.connect("mongodb://localhost/restful_blog_app");

var blogSchema = new mongoose.Schema({
    title: String,
    image: String,
    body: String,
    created: {type: Date, default: Date.now}
});

var Blog = mongoose.model("Blog", blogSchema);

//test blog create
// Blog.create(
//     {
//         title: faker.company.bs(),
//         image: "https://images.unsplash.com/1/macbook-air-iphone-moleskin.jpg?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=1c5452ddcce72bc6525838ab1b5596d5",
//         body: faker.lorem.paragraphs(),
//     }, function(err, blog) {
//         if(err) {
//             console.log(err);
//         } else {
//             console.log("You created a blog: ");
//             console.log(blog);
//         }
//     }
// );

// Blog.create(
//     {
//         title: faker.company.bs(),
//         image: "https://images.unsplash.com/20/cambridge.JPG?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&s=a70c43ac171a47312d3714b3e59aaaee",
//         body: faker.lorem.paragraphs(),
//     }, function(err, blog) {
//         if(err) {
//             console.log(err);
//         } else {
//             console.log("You created a blog: ");
//             console.log(blog);
//         }
//     }
// );

// Routes ---------------------------------------------

// Root ("/") route
app.get("/", function(req, res){
    res.redirect("/blogs");
});

// Index ("/blogs") route
app.get("/blogs", function(req, res){
    Blog.find({}, function(err, blogs){
        if(err){
            console.log(err);
        } else {
            res.render("index", {blogs: blogs});
        }
    });
});

// New ("/blogs/new") route
app.get("/blogs/new", function(req, res) {
    res.render("new");
});

// Create ("/blogs") route
app.post("/blogs", function(req, res) {
    //create blog
    //sanitize blog.body
    req.body.blog.body = req.sanitize(req.body.blog.body);
    Blog.create(req.body.blog, function(err, newBlog) {
        if(err){
            console.log(err);
            res.render("new");
        } else {
            res.redirect("/blogs")
        }
    });
    //redirect
});

// Show ("/blogs/:id") route
app.get("/blogs/:id", function(req, res) {
    Blog.findById(req.params.id, function(err, foundBlog) {
        if(err){
            res.redirect("/blogs");
        } else {
            res.render("show", {blog: foundBlog});
        }
    });
});

// Edit ("blogs/:id/edit") route
app.get("/blogs/:id/edit", function(req, res) {
    //find the form
    Blog.findById(req.params.id, function(err, foundBlog) {
        if(err){
            res.redirect("/blogs");
        } else {
            res.render("edit", {blog: foundBlog});
        }
    });
});

// Update ("blogs/:id") route
app.put("/blogs/:id", function(req, res) {
    req.body.blog.body = req.sanitize(req.body.blog.body);
    Blog.findByIdAndUpdate(req.params.id, req.body.blog, function(err, updatedBlog){
       if(err){
           res.redirect("/blogs");
       } else {
           res.redirect("/blogs/" + req.params.id);
       }
    });
});

// Delete ("blogs/:id") route
app.delete("/blogs/:id", function(req, res) {
   Blog.findByIdAndRemove(req.params.id, function(err){
       if(err){
           res.redirect("/blogs");
       } else {
           res.redirect("/blogs");
       }
   });
});

// 404 route
app.get("*", function(req, res) {
    res.send("You're a shinning star! But, unfortunately, your page cannot be found.");
});

// Listen ---------------------------------------------
app.listen(process.env.PORT, process.env.IP, function(){
    console.log("The server is running! Better go catch it!");
});


text:
var express         = require('express'),
    exphbs          = require('express-handlebars'),
    path            = require('path'),
    favicon         = require('serve-favicon'),
    logger          = require('morgan'),
    cookieParser    = require('cookie-parser'),
    bodyParser      = require('body-parser'),
    debug           = require('debug')('Ghost-Updater-Azure'),

    config          = require('./config'),
    updater         = require('./updater'),
    backup          = require('./updater/backup');

var app = express(), errorHandlers;

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.set('port', process.env.PORT || 3000);

app.use(favicon(__dirname + '/public/images/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(__dirname + '/public'));
app.get('/nw', function (req, res) {
    res.json({ isNodeWebkit: config.standalone });
});
app.use('/updater', updater);
app.use('/backup', backup);

app.get('/', function (req, res) {
    res.render('index');
});

errorHandlers = require('./updater/errors')(app);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

module.exports = app;


text: This is a bigger game based on exercise 45 of learn python the hard way