text:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>clustertools package — clustertools 0.1.0 documentation</title>

    <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />

    <link rel="top" title="clustertools 0.1.0 documentation" href="../index.html" />

Navigation

          index

          modules |

clustertools 0.1.0 documentation »

clustertools package¶

Subpackages¶

clustertools.test package

Submodules

clustertools.test.test_config module

clustertools.test.test_datacube module

clustertools.test.test_environment module

clustertools.test.test_experiment module

clustertools.test.test_parser module

clustertools.test.test_states module

clustertools.test.test_storage module

clustertools.test.test_util module

clustertools.test.util_test module

Module contents

Submodules¶

clustertools.config module¶

Module config contains the configurable features

clustertools.config.get_ct_folder()[source]¶

clustertools.datacube module¶

class clustertools.datacube.Datacube(parameters_ls, results_ls, exp_name='')[source]¶

Bases: collections.abc.Mapping

parameterss : iterable of mappings param_name -> value
resultss : iterable of mappings metric_name -> value

name: str (default “”)

The experiment name

metadata: mapping str -> value

A dictionary containing, for each of the metadatum, the associated value

domain: mapping str -> iterable of values

A dictionary containing, for each domain name, the iterable of possible
values

parameters: iterable of str

The name of each axis (with correspind index)

metrics: iterable of str

The name of each metric. The metric is the last axis. Each index in that
axis correspond to a metric in the order of metrics

data: iterable

The raw data

hash: Hasher

The hasher to the data

shape: tuple (of size len(parameters)+1)

The shape of the result cube. The N-1 first axis are linked to the
parameters and the last one to the metrics

add_metadata(**kwargs)[source]¶

compute_data_hash()[source]¶

diagnose()[source]¶

full_parameters()[source]¶

in_domain()[source]¶

items()[source]¶

Yields pairs (params, metrics) in the order of this Result

iter_dimensions(*dimensions)[source]¶

iteritems()[source]¶

maximal_hypercube(metric=None)[source]¶

minimal_hypercube(metric=None)[source]¶

numpify(squeeze=False)[source]¶

numpyfy(squeeze=True)[source]¶

out_of_domain()[source]¶

reorder_parameters(*args)[source]¶

size()[source]¶

class clustertools.datacube.Hasher(metrics, domain, metadata=None)[source]¶

Bases: object

metrics: iterable of metric_name
domain: mapping param_name -> iterable of values (axis domain)
metadata: mapping param_name -> param_val

add_metadata(**kwargs)[source]¶

dehash(index)[source]¶

get_cons_args()[source]¶

hash(metric, params)[source]¶

metric: str

A metric name

params: mapping str -> value

A mapping from parameter names to values of their domain

classmethod sort_back(dictionary)[source]¶

clustertools.datacube.build_datacube(exp_name, storage_factory=<class 'clustertools.storage.PickleStorage'>, **default_meta)[source]¶

default_meta: mapping str -> str

The (potientially) missing metadata

clustertools.datacube.build_result_cube(exp_name)[source]¶

clustertools.environment module¶

class clustertools.environment.BashEnvironment(serializer=Serializer(), fail_fast=True)[source]¶

Bases: clustertools.environment.Environment

issue(lazy_computation)[source]¶

class clustertools.environment.Environment(fail_fast=True)[source]¶

Bases: object

The Environment controls how the computations of a given experiment
must be run. It is a stateless component

The Environment runs a experiment. To do so, it creates a Session.
The Session is the stateful component which is responsible for:

counting the number of expirement run

logging everything

enforcing the capacity constraint

A Session should not be created directly.
Finally, the Session issues the computation through the Environment.

create_session(experiment)[source]¶

issue(lazy_computation)[source]¶

Actually launch the lazy_computation

lazy_computation: lazyfied Computation

The computation to launch

Will throw an exception if an error occurred during the launching. If
no exception is raised, the launching is (apparently) fine

run(experiment, start=0, capacity=None)[source]¶

experiment
start
capacity

error_count: int >= 0

The number of computations that could not be launched

class clustertools.environment.FileSerializer[source]¶

Bases: clustertools.environment.Serializer

deserialize(serlialized)[source]¶

serialize(lazy_computation)[source]¶

class clustertools.environment.InSituEnvironment(fail_fast=True)[source]¶

Bases: clustertools.environment.Environment

issue(lazy_computation)[source]¶

class clustertools.environment.Serializer[source]¶

Bases: object

deserialize(serlialized)[source]¶

Return the object represented by the serialized string

deserialize_and_run(serialized)[source]¶

serialize(lazy_computation)[source]¶

Return a unserializable string

serialize_and_script(lazy_computation)[source]¶

Return a script to run the lazy_computation

class clustertools.environment.Session(parent_environment)[source]¶

Bases: object

A Session is responsible for managing stateful information about a
group of computations being run in a given environment

init(exp_len, storage)[source]¶

is_open()[source]¶

run(lazy_computation)[source]¶

lazy_computation

success: bool

Whether launching the lazy_computation was (apparently) a
success

class clustertools.environment.SlurmEnvironment(serializer=Serializer(), time='1:00:00', memory=4000, partition=None, n_proc=None, shell_script='#!/bin/bash', fail_fast=True, other_args=None)[source]¶

Bases: clustertools.environment.Environment

issue(lazy_computation)[source]¶

clustertools.experiment module¶

Module experiment is a set of functions and classes to build, run and
monitor experiments

Restriction¶

Experiment names should always elligible file names.

class clustertools.experiment.Computation(exp_name, comp_name, context='n/a', storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: object

A Computation is any computation that must be run as part of an
experiment on a given set of parameters

exp_name: str

The name of the experiment

comp_name: str

The name of the computation

context: str (optional)

Context information (can be the time/memory requirements, for instance)

storage_factory: callable str -> cls:Storage

A factory which takes as input the experiment name and returns
a cls:Storage instance

lazyfy(**parameters)[source]¶

run(**parameters)[source]¶

class clustertools.experiment.ConstrainedParameterSet(param_map_seq=None, filters_seq=None)[source]¶

Bases: clustertools.experiment.ParameterSet

add_constraints(**kwargs)[source]¶

Add the constraints. Constraints apply from this stage on, they are not
retroactive with respect to separators.

kwargs: mapping str -> callable(**kwargs)

a named predicate. It takes as input a detupled param tuple

add_separator(**kwargs)[source]¶

delete_constraints(*args)[source]¶

class clustertools.experiment.Experiment(exp_name, parameter_set, computation_factory, storage_factory=<class 'clustertools.storage.PickleStorage'>, user=None)[source]¶

Bases: object

classmethod name_computation(exp_name, index)[source]¶

storage¶

yield_computations(context='n/a', start=0, capacity=None)[source]¶

class clustertools.experiment.ParameterSet(param_map_seq=None)[source]¶

Bases: object

A ParameterSet is a structure yielding parameter tuples. A parameter tuple
pt is an ordered list of values such that pt[i] is an admissible value
for parameter i. For the sake of ambiguity, a parameter
tuple can be referred to as a multidimensional parameter, which can be
abbreviated to “parameter” (dropping the plural to raise the confusion
with single-dimension parameters).

A parameter is either a metadata, if it can only take one value, or a
variable, if it can take several values. The set of values a parameter can
take is referred as its domain.

To entertain confusion further, “parameter” can refer to the name
of the parameter, the value it takes, both or to the mapping between
the name and the domain. Enjoy!

Parameter tuples are generated as the cartesian product of the parameters
domain, ordered following the lexicographic order of the parameter names
and according the separator: all the tuples of the domains defined before
the separator must be yielded before enlarging the domains with was comes
after the separator.

The separator allows for two use cases:

Force an ordering on the computations (do more important stuff first)

Make more computation after the first round

param_map_seq: sequence of mapping str -> set, or None (default: None)

Each mapping defines one or several bindings of the type “parameter name
(i.e. the string)-domain (i.e. the set)”. The sequence represents
partial domains isolated by separators.

add_parameters(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
either a single domain element or a sequence of domain elements.
If the domain elements are sequences, use add_single_values
instead.

add_separator(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
domain element. This mapping represent the default value that he
absence of parameter represented before this separator.

add_single_values(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
domain element.

get_indices_with(**kwargs)[source]¶

Yields indices of parameter tuples containing the parameter-values given

kwargs: mapping str -> set

A mapping where each key is a parameter name and the set is the
domain of the parameter

class clustertools.experiment.PartialComputation(exp_name, comp_name, context='n/a', storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: clustertools.experiment.Computation

Expect the run method to be a generator

class clustertools.experiment.Result(*metric_names, **kwargs)[source]¶

Bases: dict

A result is a place holder for pairs metric=value

clustertools.parser module¶

class clustertools.parser.BaseParser(serializer_factory=<class 'clustertools.environment.Serializer'>, description='Clustertool launcher')[source]¶

Bases: object

get_parser()[source]¶

parse(args=None, namespace=None)[source]¶

class clustertools.parser.ClusterParser(serializer_factory=<class 'clustertools.environment.Serializer'>, description='Clustertool launcher')[source]¶

Bases: clustertools.parser.BaseParser

get_parser()[source]¶

parse(args=None, namespace=None)[source]¶

clustertools.parser.or_none(function)[source]¶

clustertools.parser.positive_int(string)[source]¶

clustertools.parser.time_string(string)[source]¶

Expecting “HH:MM:SS” format

clustertools.state module¶

Module notification manages the notification system.

Convention¶

A computaiton absent from the notification db is considered in launchable state.
This avoid a useless call to the notification db

Note¶

A running job aborted for uncatchable reasons will stay in running state
although it is not running any longer. Refresh the historic to get it right

class clustertools.state.AbortedState(exp_name, comp_name, exception)[source]¶

Bases: clustertools.state.State

classmethod from_(state, exception)[source]¶

get_name()[source]¶

class clustertools.state.CompletedState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

class clustertools.state.CriticalState(exp_name, comp_name, first_critical=False)[source]¶

Bases: clustertools.state.State

classmethod from_(state, first_critical=False)[source]¶

get_name()[source]¶

is_not_up()[source]¶

to_completed()[source]¶

to_partial()[source]¶

class clustertools.state.IncompleteState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

class clustertools.state.LaunchableState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

to_pending()[source]¶

exception clustertools.state.ManualInterruption[source]¶

Bases: Exception

class clustertools.state.Monitor(exp_name, user=None, storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: object

A class which monitors the computations of a given experiment

job_dict : mapping {comp_name -> state}
state_dict: mapping {state -> job_dict}

The number n of computations per experiment being usually low (a few
thousands at most), it is not necessary to be better than O(n) per
operations

abort(exception=ManualInterruption('Monitor interruption', ), from_state=<class 'clustertools.state.State'>, predicate=<function Monitor.<lambda>>)[source]¶

aborted_computations()[source]¶

aborted_to_launchable(predicate=<function Monitor.<lambda>>)[source]¶

computation_names(state_cls=<class 'clustertools.state.State'>)[source]¶

count_by_state()[source]¶

critical_computations()[source]¶

incomplete_computations()[source]¶

incomplete_to_launchable(predicate=<function Monitor.<lambda>>)[source]¶

launchable_computations()[source]¶

partition_by_state()[source]¶

refresh()[source]¶

reset(from_state=<class 'clustertools.state.State'>, predicate=<function Monitor.<lambda>>)[source]¶

to_launchable(comp_name)[source]¶

to_launchables(indices=None)[source]¶

unlaunchable_computations()[source]¶

class clustertools.state.PartialState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

is_not_up()[source]¶

to_completed()[source]¶

to_critical()[source]¶

to_incomplete()[source]¶

class clustertools.state.PendingState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

is_not_up()[source]¶

to_running()[source]¶

class clustertools.state.RunningState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

get_name()[source]¶

is_not_up()[source]¶

to_critical()[source]¶

class clustertools.state.State(exp_name, comp_name)[source]¶

Bases: object

State is which is a given computation

The State object contains a datetime. This is purely informative and is
not considered as an essential component of the object. As such, it is
not considered for repr or equailty

abort(exception)[source]¶

classmethod from_(state)[source]¶

get_name()[source]¶

is_not_up()[source]¶

Return the State corresponding to this State if it were
discovered it is actually neither waiting nor working

reset()[source]¶

class clustertools.state.WorkingState(exp_name, comp_name)[source]¶

Bases: clustertools.state.State

to_aborted(exception)[source]¶

to_launchable()[source]¶

clustertools.storage module¶

Module database contains helper function for manipulating the databases

class clustertools.storage.Architecture(ct_folder=None)[source]¶

Bases: object

An Architecture is responsible for the organization of the experiments
and logs on the file system.
By default, clustertools is located in a folder named ‘clustertools_data’
(aka ct_folder) in the user home directory. The ct_folder is structured as
followed:

clustertools_data
|- logs
|- exp_XXX
|   |- logs
|   |- $result$
|   |- $notifs$
|- exp_YYY

|...

where logs is a folder containing the main logs (not the ones corresponding
to the experiments).  exp_XXX is the folder related to experiment ‘XXX’.

erase_experiment(exp_name)[source]¶

get_basedir(exp_name)[source]¶

get_meta_log_file()[source]¶

load_experiment_names()[source]¶

class clustertools.storage.PickleStorage(experiment_name, architecture=Architecture(ct_folder='/Users/jmbegon/clustertools_data'))[source]¶

Bases: clustertools.storage.Storage

Databases are folders. Each record is an individual pickle file.
Implements a backup mechanism for results to prevent long writes from
being interrupted

init()[source]¶

load_states()[source]¶

restore_back_up(comp_name)[source]¶

update_state(state)[source]¶

class clustertools.storage.Storage(experiment_name, architecture=Architecture(ct_folder='/Users/jmbegon/clustertools_data'))[source]¶

Bases: object

A Storage objects manages two databases:
- “notifications” which contains the states of the computations
- “results” which contains the results of the computations
and two folders:
- “logs” which contains the logs of each computations
- “mess” which can be used to store other things

architecture¶

delete()[source]¶

exp_name¶

folder¶

get_last_log_file(comp_name)[source]¶

Return the most recent (ctime) matching file

get_log_folder()[source]¶

get_log_prefix(comp_name, suffix='')[source]¶

get_messy_path(fname=None)[source]¶

init()[source]¶

load_params_and_results(**default_meta)[source]¶

default_meta: mapping str -> str

The (potentially) missing metadata

(parameters_ls, results_ls)
parameters_ls: list of dicts (size: nb of computations)

parameters_ls[i] is the dictionary of parameters of the ith
computation. The dictionary is a mapping str (name of the
parameters) -> value of the parameter

result_ls: list of dicts (size: nb of computations)

result_ls[i] is the dictionary of metrics of the ith
computation. The dictionary is a mapping str (name of the
metric) -> value of the metric

load_result(comp_name)[source]¶

load_states()[source]¶

Return a list of state corresponding to self.exp_name

print_log(comp_name, last_lines=None, out=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]¶

purge_logs(comp_name=None)[source]¶

save_result(comp_name, parameters, result, context='n/a')[source]¶

update_state(state)[source]¶

Save the given state as current state and returns it

clustertools.util module¶

Module util is a set of misc. functions

clustertools.util.call_with(function, dictionary, *args, **kwargs)[source]¶

Call the given function with the given dictionary with the additional
supplied arguments
Parameters
———-
function : callable

The function to process

dictionary

 : dict
The dictionary to process

args

 : list
The list of positional arguments

kwargs

 : dict
The keyword arguments

The result of the function with the given sefely inputs

clustertools.util.deprecated(func)[source]¶

This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emmitted
when the function is used.

clustertools.util.escape(s)[source]¶

clustertools.util.hashlist(ls)[source]¶

clustertools.util.kw_intersect(function, dictionary, *args, **kwargs)[source]¶

Computes the intersection between the function’s parameters and
the given dictionary
Parameters
———-
function : callable

The function to process

dictionary

 : dict
The dictionary to process

args

 : list
The list of positional arguments

kwargs

 : dict
The keyword arguments

intersect_dict

 : dict
The intersection between the function’s parameters and the given
dictionary

clustertools.util.reorder(ls, indices, in_place=False)[source]¶

Module contents¶

clustertools¶

clustertools is a toolkit to run experiments on supercomputers.
It is built on top of clusterlib (https://github.com/clusterlib/clusterlib).

TODO
clustertools_db
clustertools_logs
notification system

File system¶

By default everything related to clustertools is located in a folder named
‘clustertools_data’ (aka ct_folder) in the user home directory. The ct_folder
is structured as followed:

clustertools_data
|- logs
|- exp_XXX
|   |- logs
|   |- $result$
|   |- $notifs$
|- exp_YYY

|...

where logs is a folder containing the main logs (not the one corresponding to
the experiments). exp_XXX is the folder related to experiment ‘XXX’.

Logging¶

This library uses logging for

Warning in experiment.run_experiment() (‘clustertools’)

By default, logging is disabled

class clustertools.Monitor(exp_name, user=None, storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: object

A class which monitors the computations of a given experiment

job_dict : mapping {comp_name -> state}
state_dict: mapping {state -> job_dict}

The number n of computations per experiment being usually low (a few
thousands at most), it is not necessary to be better than O(n) per
operations

abort(exception=ManualInterruption('Monitor interruption', ), from_state=<class 'clustertools.state.State'>, predicate=<function Monitor.<lambda>>)[source]¶

aborted_computations()[source]¶

aborted_to_launchable(predicate=<function Monitor.<lambda>>)[source]¶

computation_names(state_cls=<class 'clustertools.state.State'>)[source]¶

count_by_state()[source]¶

critical_computations()[source]¶

incomplete_computations()[source]¶

incomplete_to_launchable(predicate=<function Monitor.<lambda>>)[source]¶

launchable_computations()[source]¶

partition_by_state()[source]¶

refresh()[source]¶

reset(from_state=<class 'clustertools.state.State'>, predicate=<function Monitor.<lambda>>)[source]¶

to_launchable(comp_name)[source]¶

to_launchables(indices=None)[source]¶

unlaunchable_computations()[source]¶

class clustertools.Computation(exp_name, comp_name, context='n/a', storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: object

A Computation is any computation that must be run as part of an
experiment on a given set of parameters

exp_name: str

The name of the experiment

comp_name: str

The name of the computation

context: str (optional)

Context information (can be the time/memory requirements, for instance)

storage_factory: callable str -> cls:Storage

A factory which takes as input the experiment name and returns
a cls:Storage instance

lazyfy(**parameters)[source]¶

run(**parameters)[source]¶

class clustertools.PartialComputation(exp_name, comp_name, context='n/a', storage_factory=<class 'clustertools.storage.PickleStorage'>)[source]¶

Bases: clustertools.experiment.Computation

Expect the run method to be a generator

class clustertools.ParameterSet(param_map_seq=None)[source]¶

Bases: object

A ParameterSet is a structure yielding parameter tuples. A parameter tuple
pt is an ordered list of values such that pt[i] is an admissible value
for parameter i. For the sake of ambiguity, a parameter
tuple can be referred to as a multidimensional parameter, which can be
abbreviated to “parameter” (dropping the plural to raise the confusion
with single-dimension parameters).

A parameter is either a metadata, if it can only take one value, or a
variable, if it can take several values. The set of values a parameter can
take is referred as its domain.

To entertain confusion further, “parameter” can refer to the name
of the parameter, the value it takes, both or to the mapping between
the name and the domain. Enjoy!

Parameter tuples are generated as the cartesian product of the parameters
domain, ordered following the lexicographic order of the parameter names
and according the separator: all the tuples of the domains defined before
the separator must be yielded before enlarging the domains with was comes
after the separator.

The separator allows for two use cases:

Force an ordering on the computations (do more important stuff first)

Make more computation after the first round

param_map_seq: sequence of mapping str -> set, or None (default: None)

Each mapping defines one or several bindings of the type “parameter name
(i.e. the string)-domain (i.e. the set)”. The sequence represents
partial domains isolated by separators.

add_parameters(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
either a single domain element or a sequence of domain elements.
If the domain elements are sequences, use add_single_values
instead.

add_separator(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
domain element. This mapping represent the default value that he
absence of parameter represented before this separator.

add_single_values(**kwargs)[source]¶

kwargs: mapping str -> object

A mapping where each key is a parameter name and the object is
domain element.

get_indices_with(**kwargs)[source]¶

Yields indices of parameter tuples containing the parameter-values given

kwargs: mapping str -> set

A mapping where each key is a parameter name and the set is the
domain of the parameter

class clustertools.ConstrainedParameterSet(param_map_seq=None, filters_seq=None)[source]¶

Bases: clustertools.experiment.ParameterSet

add_constraints(**kwargs)[source]¶

Add the constraints. Constraints apply from this stage on, they are not
retroactive with respect to separators.

kwargs: mapping str -> callable(**kwargs)

a named predicate. It takes as input a detupled param tuple

add_separator(**kwargs)[source]¶

delete_constraints(*args)[source]¶

class clustertools.Result(*metric_names, **kwargs)[source]¶

Bases: dict

A result is a place holder for pairs metric=value

class clustertools.Experiment(exp_name, parameter_set, computation_factory, storage_factory=<class 'clustertools.storage.PickleStorage'>, user=None)[source]¶

Bases: object

classmethod name_computation(exp_name, index)[source]¶

storage¶

yield_computations(context='n/a', start=0, capacity=None)[source]¶

class clustertools.Serializer[source]¶

Bases: object

deserialize(serlialized)[source]¶

Return the object represented by the serialized string

deserialize_and_run(serialized)[source]¶

serialize(lazy_computation)[source]¶

Return a unserializable string

serialize_and_script(lazy_computation)[source]¶

Return a script to run the lazy_computation

clustertools.build_result_cube(exp_name)[source]¶

clustertools.build_datacube(exp_name, storage_factory=<class 'clustertools.storage.PickleStorage'>, **default_meta)[source]¶

default_meta: mapping str -> str

The (potientially) missing metadata

class clustertools.BaseParser(serializer_factory=<class 'clustertools.environment.Serializer'>, description='Clustertool launcher')[source]¶

Bases: object

get_parser()[source]¶

parse(args=None, namespace=None)[source]¶

class clustertools.ClusterParser(serializer_factory=<class 'clustertools.environment.Serializer'>, description='Clustertool launcher')[source]¶

Bases: clustertools.parser.BaseParser

get_parser()[source]¶

parse(args=None, namespace=None)[source]¶

clustertools.call_with(function, dictionary, *args, **kwargs)[source]¶

Call the given function with the given dictionary with the additional
supplied arguments
Parameters
———-
function : callable

The function to process

dictionary

 : dict
The dictionary to process

args

 : list
The list of positional arguments

kwargs

 : dict
The keyword arguments

The result of the function with the given sefely inputs

clustertools.set_stdout_logging(architecture=Architecture(ct_folder='/Users/jmbegon/clustertools_data'))[source]¶

Sets stdout as default logging facility

Table Of Contents

clustertools package

Subpackages

Submodules

clustertools.config module

clustertools.datacube module

clustertools.environment module

clustertools.experiment module

Restriction

clustertools.parser module

clustertools.state module

Convention

Note

clustertools.storage module

clustertools.util module

Module contents

clustertools

File system

Logging

This Page

Show Source

Quick search

    <form class="search" action="../search.html" method="get">

<input type="text" name="q" />

<input type="submit" value="Go" />

      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>

Navigation

          index

          modules |

clustertools 0.1.0 documentation »

        © Copyright 2018, Jean-Michel Begon.
      Created using Sphinx 1.4.6.


text:
package org.apache.camel.component.mongodb;

import java.util.ArrayList;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.CommandResult;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.WriteConcern;
import com.mongodb.WriteResult;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.TypeConverter;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * The MongoDb producer.
 */
public class MongoDbProducer extends DefaultProducer {
    private static final transient Logger LOG = LoggerFactory.getLogger(MongoDbProducer.class);
    private MongoDbEndpoint endpoint;

    public MongoDbProducer(MongoDbEndpoint endpoint) {
        super(endpoint);
        this.endpoint = endpoint;
    }

    public void process(Exchange exchange) throws Exception {
        MongoDbOperation operation = endpoint.getOperation();
        Object header = exchange.getIn().getHeader(MongoDbConstants.OPERATION_HEADER);
        if (header != null) {
            LOG.debug("Overriding default operation with operation specified on header: {}", header);
            try {
                if (header instanceof MongoDbOperation) {
                    operation = ObjectHelper.cast(MongoDbOperation.class, header);
                } else {
                    // evaluate as a String
                    operation = MongoDbOperation.valueOf(exchange.getIn().getHeader(MongoDbConstants.OPERATION_HEADER, String.class));
                }
            } catch (Exception e) {
                throw new CamelMongoDbException("Operation specified on header is not supported. Value: " + header, e);
            }
        }

        try {
            invokeOperation(operation, exchange);
        } catch (Exception e) {
            throw MongoDbComponent.wrapInCamelMongoDbException(e);
        }

    }

    /**
     * Entry method that selects the appropriate MongoDB operation and executes it
     * @param operation
     * @param exchange
     * @throws Exception
     */
    protected void invokeOperation(MongoDbOperation operation, Exchange exchange) throws Exception {
        switch (operation) {
        case count:
            doCount(exchange);
            break;

        case findOneByQuery:
            doFindOneByQuery(exchange);
            break;

        case findById:
            doFindById(exchange);
            break;

        case findAll:
            doFindAll(exchange);
            break;

        case insert:
            doInsert(exchange);
            break;

        case save:
            doSave(exchange);
            break;

        case update:
            doUpdate(exchange);
            break;

        case remove:
            doRemove(exchange);
            break;

        case getDbStats:
            doGetStats(exchange, 'D');
            break;

        case getColStats:
            doGetStats(exchange, 'C');
            break;

        default:
            throw new CamelMongoDbException("Operation not supported. Value: " + operation);
        }
    }

    // ----------- MongoDB operations ----------------

    protected void doGetStats(Exchange exchange, char c) {
        DBObject result = null;

        if (c == 'C') {
            result = calculateCollection(exchange).getStats();
        } else if (c == 'D') {
            // if it's a DB, also take into account the dynamicity option and the DB that is used
            result = calculateCollection(exchange).getDB().getStats();
        }

        exchange.getOut().setBody(result);
    }

    protected void doRemove(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        DBObject removeObj = exchange.getIn().getMandatoryBody(DBObject.class);

        WriteConcern wc = extractWriteConcern(exchange);
        WriteResult result = wc == null ? dbCol.remove(removeObj) : dbCol.remove(removeObj, wc);
        processWriteResult(result, exchange);

        Message out = exchange.getOut();
        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or
        // obtain the cached CommandResult
        out.setBody(result);
        out.setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getN());
    }

    @SuppressWarnings("unchecked")
    protected void doUpdate(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        List<DBObject> saveObj = exchange.getIn().getMandatoryBody((Class<List<DBObject>>) (Class<?>) List.class);
        if (saveObj.size() != 2) {
            throw new CamelMongoDbException("MongoDB operation = insert, failed because body is not a List of DBObject objects with size = 2");
        }

        DBObject updateCriteria = saveObj.get(0);
        DBObject objNew = saveObj.get(1);

        Boolean multi = exchange.getIn().getHeader(MongoDbConstants.MULTIUPDATE, Boolean.class);
        Boolean upsert = exchange.getIn().getHeader(MongoDbConstants.UPSERT, Boolean.class);

        WriteResult result;
        WriteConcern wc = extractWriteConcern(exchange);
        // In API 2.7, the default upsert and multi values of update(DBObject, DBObject) are false, false, so we unconditionally invoke the
        // full-signature method update(DBObject, DBObject, boolean, boolean). However, the default behaviour may change in the future,
        // so it's safer to be explicit at this level for full determinism
        if (multi == null && upsert == null) {
            // for update with no multi nor upsert but with specific WriteConcern there is no update signature without multi and upsert args,
            // so assume defaults
            result = wc == null ? dbCol.update(updateCriteria, objNew) : dbCol.update(updateCriteria, objNew, false, false, wc);
        } else {
            // we calculate the final boolean values so that if any of these parameters is null, it is resolved to false
            result = wc == null ? dbCol.update(updateCriteria, objNew, calculateBooleanValue(upsert), calculateBooleanValue(multi))
                    : dbCol.update(updateCriteria, objNew, calculateBooleanValue(upsert), calculateBooleanValue(multi), wc);
        }

        processWriteResult(result, exchange);
        Message out = exchange.getOut();
        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or
        // obtain the cached CommandResult
        out.setBody(result);
        out.setHeader(MongoDbConstants.RECORDS_AFFECTED, result.getN());
    }

    protected void doSave(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        DBObject saveObj = exchange.getIn().getMandatoryBody(DBObject.class);

        WriteConcern wc = extractWriteConcern(exchange);
        WriteResult result = wc == null ? dbCol.save(saveObj) : dbCol.save(saveObj, wc);
        processWriteResult(result, exchange);
        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or
        // obtain the cached CommandResult
        exchange.getOut().setBody(result);
    }

    protected void doFindById(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        Object o = exchange.getIn().getMandatoryBody();
        DBObject ret;

        DBObject fieldFilter = exchange.getIn().getHeader(MongoDbConstants.FIELDS_FILTER, DBObject.class);
        if (fieldFilter == null) {
            ret = dbCol.findOne(o);
        } else {
            ret = dbCol.findOne(o, fieldFilter);
        }

        Message out = exchange.getOut();
        out.setBody(ret);
        out.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);

    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    protected void doInsert(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        boolean singleInsert = true;
        Object insert = exchange.getIn().getBody(DBObject.class);
        // body could not be converted to DBObject, check to see if it's of type List<DBObject>
        if (insert == null) {
            insert = exchange.getIn().getBody(List.class);
            // if the body of type List was obtained, ensure that all items are of type DBObject and cast the List to List<DBObject>
            if (insert != null) {
                singleInsert = false;
                insert = attemptConvertToList((List) insert, exchange);
            } else {
                throw new CamelMongoDbException("MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject>");
            }
        }

        WriteResult result;
        WriteConcern wc = extractWriteConcern(exchange);
        if (singleInsert) {
            result = wc == null ? dbCol.insert((DBObject) insert) : dbCol.insert((DBObject) insert, wc);
        } else {
            result = wc == null ? dbCol.insert((List<DBObject>) insert) : dbCol.insert((List<DBObject>) insert, wc);
        }

        processWriteResult(result, exchange);

        // we always return the WriteResult, because whether the getLastError was called or not, the user will have the means to call it or
        // obtain the cached CommandResult
        exchange.getOut().setBody(result);
    }

    protected void doFindAll(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        // do not use getMandatoryBody, because if the body is empty we want to retrieve all objects in the collection
        DBObject query = null;
        // do not run around looking for a type converter unless there is a need for it
        if (exchange.getIn().getBody() != null) {
            query = exchange.getIn().getBody(DBObject.class);
        }
        DBObject fieldFilter = exchange.getIn().getHeader(MongoDbConstants.FIELDS_FILTER, DBObject.class);

        // get the batch size and number to skip
        Integer batchSize = exchange.getIn().getHeader(MongoDbConstants.BATCH_SIZE, Integer.class);
        Integer numToSkip = exchange.getIn().getHeader(MongoDbConstants.NUM_TO_SKIP, Integer.class);
        Integer limit = exchange.getIn().getHeader(MongoDbConstants.LIMIT, Integer.class);
        DBObject sortBy = exchange.getIn().getHeader(MongoDbConstants.SORT_BY, DBObject.class);
        DBCursor ret = null;
        try {
            if (query == null && fieldFilter == null) {
                ret = dbCol.find(new BasicDBObject());
            } else if (fieldFilter == null) {
                ret = dbCol.find(query);
            } else {
                ret = dbCol.find(query, fieldFilter);
            }

            if (sortBy != null) {
                ret.sort(sortBy);
            }

            if (batchSize != null) {
                ret.batchSize(batchSize.intValue());
            }

            if (numToSkip != null) {
                ret.skip(numToSkip.intValue());
            }

            if (limit != null) {
                ret.limit(limit.intValue());
            }

            Message out = exchange.getOut();
            out.setBody(ret.toArray());
            out.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret.count());
            out.setHeader(MongoDbConstants.RESULT_PAGE_SIZE, ret.size());

        } catch (Exception e) {
            // rethrow the exception
            throw e;
        } finally {
            // make sure the cursor is closed
            if (ret != null) {
                ret.close();
            }
        }

    }

    protected void doFindOneByQuery(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        DBObject o = exchange.getIn().getMandatoryBody(DBObject.class);
        DBObject ret;

        DBObject fieldFilter = exchange.getIn().getHeader(MongoDbConstants.FIELDS_FILTER, DBObject.class);
        if (fieldFilter == null) {
            ret = dbCol.findOne(o);
        } else {
            ret = dbCol.findOne(o, fieldFilter);
        }

        Message out = exchange.getOut();
        out.setBody(ret);
        out.setHeader(MongoDbConstants.RESULT_TOTAL_SIZE, ret == null ? 0 : 1);
    }

    protected void doCount(Exchange exchange) throws Exception {
        DBCollection dbCol = calculateCollection(exchange);
        Long answer = Long.valueOf(dbCol.count());
        exchange.getOut().setBody(answer);
    }

    // --------- Convenience methods -----------------------

    private DBCollection calculateCollection(Exchange exchange) {
        // dynamic calculation is an option. In most cases it won't be used and we should not penalise all users with running this
        // resolution logic on every Exchange if they won't be using this functionality at all
        if (!endpoint.isDynamicity()) {
            return endpoint.getDbCollection();
        }

        String dynamicDB = exchange.getIn().getHeader(MongoDbConstants.DATABASE, String.class);
        String dynamicCollection = exchange.getIn().getHeader(MongoDbConstants.COLLECTION, String.class);

        if (dynamicDB == null && dynamicCollection == null) {
            return endpoint.getDbCollection();
        }

        DB db = endpoint.getDb();
        DBCollection dbCol = null;

        if (dynamicDB != null) {
            db = endpoint.getMongoConnection().getDB(dynamicDB);
        }

        dbCol = dynamicCollection == null ? db.getCollection(endpoint.getCollection()) : db.getCollection(dynamicCollection);
        LOG.debug("Dynamic database and/or collection selected: {}->{}", dbCol.getDB().getName(), dbCol.getName());
        return dbCol;
    }

    private boolean calculateBooleanValue(Boolean b) {
        return b == null ? false : b.booleanValue();
    }

    private void processWriteResult(WriteResult result, Exchange exchange) {
        // if invokeGetLastError is set, or a WriteConcern is set which implicitly calls getLastError, then we have the chance to populate
        // the MONGODB_LAST_ERROR header, as well as setting an exception on the Exchange if one occurred at the MongoDB server
        if (endpoint.isInvokeGetLastError() || (endpoint.getWriteConcern() != null ? endpoint.getWriteConcern().callGetLastError() : false)) {
            CommandResult cr = result.getCachedLastError() == null ? result.getLastError() : result.getCachedLastError();
            exchange.getOut().setHeader(MongoDbConstants.LAST_ERROR, cr);
            if (!cr.ok()) {
                exchange.setException(MongoDbComponent.wrapInCamelMongoDbException(cr.getException()));
            }
        }
    }

    private WriteConcern extractWriteConcern(Exchange exchange) throws CamelMongoDbException {
        Object o = exchange.getIn().getHeader(MongoDbConstants.WRITECONCERN);

        if (o == null) {
            return null;
        } else if (o instanceof WriteConcern) {
            return ObjectHelper.cast(WriteConcern.class, o);
        } else if (o instanceof String) {
            WriteConcern answer = WriteConcern.valueOf(ObjectHelper.cast(String.class, o));
            if (answer == null) {
                throw new CamelMongoDbException("WriteConcern specified in the " + MongoDbConstants.WRITECONCERN
                        + " header, with value " + o + " could not be resolved to a WriteConcern type");
            }
        }

        // should never get here
        LOG.warn("A problem occurred while resolving the Exchange's Write Concern");
        return null;
    }

    @SuppressWarnings("rawtypes")
    private List<DBObject> attemptConvertToList(List insertList, Exchange exchange) throws CamelMongoDbException {
        List<DBObject> dbObjectList = new ArrayList<DBObject>(insertList.size());
        TypeConverter converter = exchange.getContext().getTypeConverter();
        for (Object item : insertList) {
            try {
                DBObject dbObject = converter.mandatoryConvertTo(DBObject.class, item);
                dbObjectList.add(dbObject);
            } catch (Exception e) {
                throw new CamelMongoDbException("MongoDB operation = insert, Assuming List variant of MongoDB insert operation, but List contains non-DBObject items", e);
            }
        }
        return dbObjectList;
    }

}

redpajama_set_name: RedPajamaGithub


text:
Command runs fake push server.

## Usage

Configuration is following 12-factor app methodology and is using ENV as config source.

### FCM/GCM server

```bash
#!/usr/bin/env bash

export APP_SERVICE="fcm"
export APP_APPS_FILE="data/fcm-apps.json"
export APP_INSTANCES_FILE="data/fcm-inst.json"
export APP_LOG_LEVEL="all"

./server
```

### APNS server

```bash
#!/usr/bin/env bash

export APP_SERVICE="apns"
export APP_APPS_FILE="data/apns-apps.json"
export APP_INSTANCES_FILE="data/apns-inst.json"
export APP_APNS_CERT_FILE="data/self-001-cert.pem"
export APP_APNS_KEY_FILE="data/self-001-key.pem"
export APP_LOG_LEVEL="all"

./server
```

#### certificate generation

Generation of the SSL certificates which are supporting Subject Alternative Names for local use (also IP) without disabling TLS/SSL security in client.

    TODO(szpakas): add support for ASN1 commonName field (2.5.4.3) for passing APNS environment (Apple Development IOS Push Services / Apple Production IOS Push Services / Apple Push Services).

openssl.cnf
```
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no

[req_distinguished_name]
# userID OID extension (0.9.2342.19200300.100.1.1) for passing bundleID for topic selection
userId = pl.example.prod
# As defined in 4.1.2.4 and appendix A of RFC 5280
countryName = PL
stateOrProvinceName = Silesia
localityName = Gliwice
organizationName = Nyota

[ v3_req ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:TRUE
subjectAltName = @alt_names

[alt_names]
DNS.1 = localhost
DNS.2 = *.push.local
IP.1 = 192.168.99.100
IP.2 = 127.0.0.1
```

generate.sh
```bash
#!/usr/bin/env bash

# Generation of the certificate with Subject Alternative Names (SAN).
# This allows using IPs.
#
# @see:
#  http://apetec.com/support/GenerateSAN-CSR.htm
#  http://pro-tips-dot-com.tumblr.com/post/65411476159/self-signed-ssl-certificates-with-multiple-hostnames

NO=`printf "%0*d\n" 3 $1`
BASE_CERT_NAME="self-${NO}"

openssl req -x509 -nodes -days 3650 \
    -newkey rsa:2048 \
    -config openssl.cnf \
    -keyout ${BASE_CERT_NAME}-key.pem \
    -out ${BASE_CERT_NAME}-cert.pem

# create pair
cat ${BASE_CERT_NAME}-cert.pem ${BASE_CERT_NAME}-key.pem > ${BASE_CERT_NAME}-pair.pem

# examine CERT
openssl x509 -in ${BASE_CERT_NAME}-cert.pem -noout -text
```

certificate example with UID set to bundleID

    Certificate:
        Data:
            Version: 3 (0x2)
            Serial Number:
                b6:f3:af:b7:3b:b1:b5:7e
            Signature Algorithm: sha1WithRSAEncryption
            Issuer: UID=pl.example.prod, C=PL, ST=Silesia, L=Gliwice, O=Nyota
            Validity
                Not Before: Jun  7 19:44:19 2016 GMT
                Not After : Jun  5 19:44:19 2026 GMT
            Subject: UID=pl.example.prod, C=PL, ST=Silesia, L=Gliwice, O=Nyota
            Subject Public Key Info:
            ...

## Middlewares

Both APNS and FCM handlers allow for use of middlewares.
Currently following middlewares are available:
- logging
- delay
- instrumentation

## Response Headers

There are extra response headers introduced which are outside of the APNS/FCM specifications.

- X-delayed-by-ms: number of milliseconds the response was delayed (set by DelayMiddleware)
- X-requests-total: number of requests served by server till its start regardless of request outcome

## Instrumentation

Instrumentation is based on [Prometheus](https://prometheus.io).

Metrics:
- push_requests_total:
-- type: CounterVec
-- desc: How many push requests were processed, partitioned by provider, status code and error reason.


text:
import Volvox from './volvox'
import Configuration from './configuration'
import ServiceInformation from './service-information'
import FrameworkProvider from './framework-provider'

import GuidGenerator from './util/guid-generator'
import RandomGenerator from './util/random-generator'
import ClusterProvider from './cluster-provider'

export default Volvox

export {
    Configuration,
    ServiceInformation,
    FrameworkProvider,
    ClusterProvider,
    GuidGenerator,
    RandomGenerator
}


text:
namespace url {
class Origin;
}  // namespace url

namespace mojo {

template <>
struct COMPONENT_EXPORT(NETWORK_CPP_SCHEMEFUL)
    StructTraits<network::mojom::SchemefulSiteDataView, net::SchemefulSite> {
  static const url::Origin& site_as_origin(const net::SchemefulSite& input) {
    return input.site_as_origin_;
  }

  static bool Read(network::mojom::SchemefulSiteDataView data,
                   net::SchemefulSite* out);
};

}  // namespace mojo

#endif  // SERVICES_NETWORK_PUBLIC_CPP_SCHEMEFUL_SITE_MOJOM_TRAITS_H_


text:
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-missing-import-lists #-}
{-# OPTIONS_GHC -fno-warn-implicit-prelude #-}
module Paths_isbn_verifier (
    version,
    getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,
    getDataFileName, getSysconfDir
  ) where

import qualified Control.Exception as Exception
import Data.Version (Version(..))
import System.Environment (getEnv)
import Prelude

#if defined(VERSION_base)

#if MIN_VERSION_base(4,0,0)
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#else
catchIO :: IO a -> (Exception.Exception -> IO a) -> IO a
#endif

#else
catchIO :: IO a -> (Exception.IOException -> IO a) -> IO a
#endif
catchIO = Exception.catch

version :: Version
version = Version [1,1,0,1] []
bindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath

bindir     = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/bin"
libdir     = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/lib/x86_64-osx-ghc-8.0.2/isbn-verifier-1.1.0.1-4knpVDKMCdN6yVDRTVYlC3"
dynlibdir  = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/lib/x86_64-osx-ghc-8.0.2"
datadir    = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/share/x86_64-osx-ghc-8.0.2/isbn-verifier-1.1.0.1"
libexecdir = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/libexec"
sysconfdir = "/Users/c19/Documents/projects/exercism/haskell/haskell/isbn-verifier/.stack-work/install/x86_64-osx/lts-9.11/8.0.2/etc"

getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath
getBinDir = catchIO (getEnv "isbn_verifier_bindir") (\_ -> return bindir)
getLibDir = catchIO (getEnv "isbn_verifier_libdir") (\_ -> return libdir)
getDynLibDir = catchIO (getEnv "isbn_verifier_dynlibdir") (\_ -> return dynlibdir)
getDataDir = catchIO (getEnv "isbn_verifier_datadir") (\_ -> return datadir)
getLibexecDir = catchIO (getEnv "isbn_verifier_libexecdir") (\_ -> return libexecdir)
getSysconfDir = catchIO (getEnv "isbn_verifier_sysconfdir") (\_ -> return sysconfdir)

getDataFileName :: FilePath -> IO FilePath
getDataFileName name = do
  dir <- getDataDir
  return (dir ++ "/" ++ name)


text:
adsApp.controller('ViewCategoriesController', function ($scope, $location, userDataService, adsDataService) {
    if (!userDataService.isUserAdmin()) {
        $location.url('/view/ads');
        notyTopCenter('alert', 'Access denied for this page', 2);
        return;
    }

    $scope.selectedPageNumber = 1;
    $scope.sortByWhat = null;

    $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), $scope.sortByWhat, $scope.selectedPageNumber);
    $scope.changeSort = changeSort;
    $scope.whichIconToShow = whichIconToShow;
    $scope.deleteCategory = deleteCategory;
    $scope.addNewCategoryPrompt = addNewCategoryPrompt;
    $scope.editCategoryPrompt = editCategoryPrompt;

    $scope.$watch('sortByWhat', function (newValue, oldValue) {
        if (newValue !== oldValue) {
            $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), newValue, $scope.selectedPageNumber);
        }
    });

    $scope.$watch('selectedPageNumber', function (newValue, oldValue) {
        if (newValue !== oldValue) {
            $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), $scope.sortByWhat, newValue);
        }
    });

    function changeSort(sortByWhat) {
        if (sortByWhat == $scope.sortByWhat) {
            $scope.sortByWhat = '-' + sortByWhat;
        } else {
            $scope.sortByWhat = sortByWhat;
        }
    }

    function whichIconToShow(element) {
        if (element == $scope.sortByWhat) {
            return 'glyphicon glyphicon-hand-up';
        } else if ('-' + element == $scope.sortByWhat) {
            return 'glyphicon glyphicon-hand-down';
        } else {
            return '';
        }
    }

    function deleteCategory(username) {
        function delCategory() {
            adsDataService.deleteCategory(username, userDataService.getCurrentUser()).$promise.then(function () {
                $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), $scope.sortByWhat, $scope.selectedPageNumber);
                notyTopCenter('success', 'Category successfully deleted ', 2);
            }, function () {
                notyTopCenter('error', 'There was a problem deleting this category', 2);
            })
        }

        notyConfirm('Are you sure you want to delete this category?', delCategory);
    }

    function addNewCategoryPrompt() {
        bootbox.prompt({
            title: "What name do you want for your new category?",
            callback: function(name) {
                if (name !== null) {
                    if (name == "") {
                        notyTopCenter('error', 'Name cannot be null', 2);
                    } else {
                        addNewCategory(name);
                    }
                }
            }
        });
    }

    function addNewCategory(name) {
        adsDataService.addCategory(name).$promise.then(function () {
            $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), $scope.sortByWhat, $scope.selectedPageNumber);
            notyTopCenter('success', 'Category successfully created ', 2);
        }, function () {
            notyTopCenter('error', 'There was a problem adding the category', 2);
        })
    }

    function editCategoryPrompt(categoryId, categoryName) {
        bootbox.prompt({
            title: "What new name do you want for this category?",
            value: categoryName,
            callback: function(name) {
                if (name !== null) {
                    if (name == "") {
                        notyTopCenter('error', 'Name cannot be null', 2);
                    } else {
                        editCategory(categoryId, name);
                    }
                }
            }
        });
    }

    function editCategory(categoryId, categoryName) {
        adsDataService.editCategory(categoryId, categoryName).$promise.then(function () {
            $scope.categories = adsDataService.getAllCategoriesAsAdmin(userDataService.getCurrentUser(), $scope.sortByWhat, $scope.selectedPageNumber);
            notyTopCenter('success', 'Category successfully edited ', 2);
        }, function () {
            notyTopCenter('error', 'There was a problem editing the category', 2);
        })
    }
});


text:
/*******************************************************************************

        Batch transpose interpolation for all locations of points
	with mirror and zero end condition

        Created by Se Young Chun, Jan 19, 2007, the University of Michigan

*******************************************************************************/

extern void 	BatchInterpolatedValue2DTranMirr (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
        		long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedValue2DTranMirrWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );

extern void 	BatchInterpolatedGradX2DTranMirr (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
                	long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedGradX2DTranMirrWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );

extern void 	BatchInterpolatedGradY2DTranMirr (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
                	long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedGradY2DTranMirrWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );

extern void 	BatchInterpolatedValue2DTranZero (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
        		long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedValue2DTranZeroWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );

extern void 	BatchInterpolatedGradX2DTranZero (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
                	long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedGradX2DTranZeroWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );

extern void 	BatchInterpolatedGradY2DTranZero (
  			float   *Bout,          /* output interpolated */
                	float   *Bcoeff,        /* input B-spline coeff array */
                	long    Width,          /* width of coeff array */
                	long    Height,         /* height of coeff array */
                	double  nx,             /* width of Bout */
                	double  offx,           /* offset of x direction */
                	double  mx,             /* magnif factor for x */
                	double  ny,             /* height of Bout */
                	double  offy,           /* offset of y direction */
                	double  my,             /* magnif factor for y */
                	long    SplineDegree    /* degree of spline model */
		);

extern void     BatchInterpolatedGradY2DTranZeroWarp (
  			float   *Bout,          /* output interpolated */
                        float   *Bcoeff,        /* input B-spline coeff array */
                        long    Width,          /* width of coeff array */
                        long    Height,         /* height of coeff array */
                        double  nx,             /* width of Bout */
                        double  offx,           /* offset of x direction */
                        double  mx,             /* magnif factor for x */
                        float   *WarpX,         /* deformed value in x direct */
                        double  ny,             /* height of Bout */
                        double  offy,           /* offset of y direction */
                        double  my,             /* magnif factor for y */
                        float   *WarpY,         /* deformed value in y direct */
                        long    SplineDegree    /* degree of spline model */
                );


text:
<!DOCTYPE html>

    <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="You can use an accordion-layout that takes advantage of Bootstrap styling. This is useful for an FAQ page.">
<meta name="keywords" content="special_layouts,  frequently asked questions, FAQ, question and answer, collapsible sections, expand, collapse">
<title>FAQ layout | Jekyll theme for documentation</title>
<link rel="stylesheet" href="css/syntax.css">

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

<link rel="stylesheet" href="css/modern-business.css">
<link rel="stylesheet" href="css/lavish-bootstrap.css">
<link rel="stylesheet" href="css/customstyles.css">
<link rel="stylesheet" href="css/theme-blue.css">

<link rel="shortcut icon" href="images/favicon.ico">

<link rel="alternate" type="application/rss+xml" title="" href="http://localhost:4000feed.xml">

            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                Toggle navigation

            </button>
              Jekyll Documentation Theme

News

                    Jekyll Resources

Github Repo

Jekyll Talk

Jekyll documentation

Jekyll on Stack Overflow

Jekyll on my blog

                    Products

Jekyll Documentation Theme

Product 1

Product 2

   Feedback

                        <input type="text" id="search-input" placeholder="search...">

Jekyll Doc Theme 6.0

        Overview

Get started

Introduction

Supported features

About the theme author

Support

        Release Notes

6.0 Release notes

5.0 Release notes

        Installation

About Ruby, Gems, Bundler, etc.

Install Jekyll on Mac

Install Jekyll on Windows

        Authoring

Pages

Posts

Lists

Conditional logic

Content reuse

Collections

WebStorm editor tips

Atom editor tips

        Navigation

Sidebar navigation

YAML tutorial in the context of Jekyll

Tags

Series

        Formatting

Tooltips

Alerts

Icons

Images

Code samples

Labels

Links

Navtabs

Tables

Syntax highlighting

Workflow maps

        Handling reviews

Commenting on files

        Publishing

Build arguments

Themes

Generating PDFs

Help APIs and UI tooltips

Search configuration

iTerm profiles

Pushing builds to server

Getting around the password prompts in SCP

Publishing on Github Pages

        Special layouts

Knowledge-base layout

Glossary layout

FAQ layout

Scroll layout

Shuffle layout

        Troubleshooting

Troubleshooting

        Tag archives

Tag archives overview

                Tag archive pages

Formatting pages

Navigation pages

Content types pages

Publishing pages

Special layout pages

Collaboration pages

Troubleshooting pages

FAQ layout

You can use an accordion-layout that takes advantage of Bootstrap styling. This is useful for an FAQ page.

     Edit me

If you want to use an FAQ format, use the syntax shown on the faq.html page. Rather than including code samples here (which are bulky with a lot of nested div tags), just look at the source in the mydoc_faq.html theme file.

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Curabitur eget leo at velit imperdiet varius. In eu ipsum vitae velit congue iaculis vitae at risus?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Aenean consequat lorem ut felis ullamcorper?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Curabitur eget leo at velit imperdiet varius. In eu ipsum vitae velit congue iaculis vitae at risus?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Aenean consequat lorem ut felis ullamcorper?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Lorem ipsum dolor sit amet, consectetur adipiscing elit?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Curabitur eget leo at velit imperdiet varius. In eu ipsum vitae velit congue iaculis vitae at risus?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

                                Aenean consequat lorem ut felis ullamcorper?

                                Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.

        Tags:

        special_layouts

               ©2017 Your company. All rights reserved.

Page last updated: November 30, 2015
 Site last generated: Feb 7, 2017


text:
""" The Pyjamas specific implementation of a menu manager.
"""

# Enthought library imports.
from enthought.traits.api import Unicode

# Local imports.
from enthought.pyface.action.action_manager import ActionManager
from enthought.pyface.action.action_manager_item import ActionManagerItem
from enthought.pyface.action.group import Group

# Pyjamas imports.
#from pyjamas import MenuBar, MenuItem

class MenuManager(ActionManager, ActionManagerItem):
    """ A menu manager realizes itself in a menu control.

        This could be a sub-menu or a context (popup) menu.
    """

    #### 'MenuManager' interface ##############################################

    # The menu manager's name (if the manager is a sub-menu, this is what its
    # label will be).
    name = Unicode

    ###########################################################################
    # 'MenuManager' interface.
    ###########################################################################

    def create_menu(self, parent, controller=None):
        """ Creates a menu representation of the manager. """

        # If a controller is required it can either be set as a trait on the
        # menu manager (the trait is part of the 'ActionManager' API), or
        # passed in here (if one is passed in here it takes precedence over the
        # trait).
        if controller is None:
            controller = self.controller

        return _Menu(self, parent, controller)

    ###########################################################################
    # 'ActionManagerItem' interface.
    ###########################################################################

    def add_to_menu(self, parent, menu, controller):
        """ Adds the item to a menu. """

        sub = self.create_menu(parent, controller)

        # fixme: Nasty hack to allow enabling/disabling of menus.
        sub._id = 0
#        sub._menu = menu

        menu.add_cascade( menu = sub, label = self.name )

        return

    def add_to_toolbar(self, parent, tool_bar, image_cache, controller):
        """ Adds the item to a tool bar. """

        raise ValueError("Cannot add a menu manager to a toolbar.")

class _Menu(object):#MenuBar):
    """ The toolkit-specific menu control. """

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __init__(self, manager, parent, controller):
        """ Creates a new tree. """

        # Base class constructor.
        MenuBar.__init__(self, vertical = True)

        # The parent of the menu.
        self._parent = parent

        # The manager that the menu is a view of.
        self._manager = manager

        # The controller.
        self._controller = controller

        # List of menu items
        self.menu_items = []

        # Create the menu structure.
        self.refresh()

        # Listen to the manager being updated.
        self._manager.on_trait_change(self.refresh, 'changed')
        self._manager.on_trait_change(self._on_enabled_changed, 'enabled')

        return

    ###########################################################################
    # '_Menu' interface.
    ###########################################################################

    def clear(self):
        """ Clears the items from the menu.
        """
        self.clearItems()

        for item in self.menu_items:
            item.dispose()

        self.menu_items = []

        return

    def is_empty(self):
        """ Is the menu empty?
        """
        return len( self.slaves() ) == 0

    def refresh(self):
        """ Ensures that the menu reflects the state of the manager.
        """
        self.clear()

        manager = self._manager
        parent  = self._parent

        previous_non_empty_group = None
        for group in manager.groups:
            previous_non_empty_group = self._add_group( parent, group,
                previous_non_empty_group )
        return

    def show(self, x, y):
        """ Show the menu at the specified location.
        """
#        self.post(x, y)
        return

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _on_enabled_changed(self, obj, trait_name, old, new):
        """ Dynamic trait change handler.
        """
        # fixme: Nasty hack to allow enabling/disabling of menus.
        #
        # We cannot currently (AFAIK) disable menus on the menu bar. Hence
        # we don't give them an '_id'...
        if hasattr(self, '_id'):
            self.setEnabled( new )
        return

    def _add_group(self, parent, group, previous_non_empty_group=None):
        """ Adds a group to a menu.
        """
        if len(group.items) > 0:
            # Is a separator required?
            if previous_non_empty_group is not None and group.separator:
                self.add_separator()

            # Create actions and sub-menus for each contribution item in
            # the group.
            for item in group.items:
                if isinstance(item, Group):
                    if len(item.items) > 0:
                        self._add_group(parent, item, previous_non_empty_group)

                        if previous_non_empty_group is not None \
                           and previous_non_empty_group.separator \
                           and item.separator:
                            self.add_separator()

                        previous_non_empty_group = item

                else:
                    item.add_to_menu(parent, self, self._controller)

            previous_non_empty_group = group

        return previous_non_empty_group

#### EOF ######################################################################


text:
/**
 * Schema plugin to add timestamps to document
 *
 * @param {mongoose.Schema} schema -
 * @param {Object} options - some options
 */
function timestampsPlugin(schema, options) {

    // Add the fields to the schema
    schema.add({
        createdAt: {
            type: Date,
            'default': Date.now
        },
        updatedAt: {
            type: Date,
            'default': Date.now
        }
    });

    // Define the pre save hook
    schema.pre('save', function (next) {
        this.updatedAt = new Date();
        next();
    });

    // Create an index on all the paths
    schema.path('createdAt').index(true);
    schema.path('updatedAt').index(true);
}

module.exports = timestampsPlugin;


text:
/* TEMPLATE GENERATED TESTCASE FILE
Filename: CWE762_Mismatched_Memory_Management_Routines__new_free_long_54c.cpp
Label Definition File: CWE762_Mismatched_Memory_Management_Routines__new_free.label.xml
Template File: sources-sinks-54c.tmpl.cpp
*/
/*
 * @description
 * CWE: 762 Mismatched Memory Management Routines
 * BadSource:  Allocate data using new
 * GoodSource: Allocate data using malloc()
 * Sinks:
 *    GoodSink: Deallocate data using delete
 *    BadSink : Deallocate data using free()
 * Flow Variant: 54 Data flow: data passed as an argument from one function through three others to a fifth; all five functions are in different source files
 *
 * */

#include "std_testcase.h"

namespace CWE762_Mismatched_Memory_Management_Routines__new_free_long_54
{

#ifndef OMITBAD

/* bad function declaration */
void badSink_d(long * data);

void badSink_c(long * data)
{
    badSink_d(data);
}

#endif /* OMITBAD */

#ifndef OMITGOOD

/* goodG2B uses the GoodSource with the BadSink */
void goodG2BSink_d(long * data);

void goodG2BSink_c(long * data)
{
    goodG2BSink_d(data);
}

/* goodB2G uses the BadSource with the GoodSink */
void goodB2GSink_d(long * data);

void goodB2GSink_c(long * data)
{
    goodB2GSink_d(data);
}

#endif /* OMITGOOD */

} /* close namespace */


text:
Inventory module
================

Gathers inventory information found in `/Library/Managed Installs/ApplicationInventory.plist`

The table provides the following information per 'item':

* id (int) Unique id
* serial_number (string) Serial Number
* name (string) Name
* version (string) Version
* bundleid (string) Bundle ID
* bundlename (string) Bundle Name
* path (string) Path


text:
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using SuperSocket.ClientEngine;

namespace WebSocket4Net
{
    public partial class WebSocket
    {
        private bool m_AllowUnstrustedCertificate;

        /// <summary>
        /// Gets or sets a value indicating whether [allow unstrusted certificate] when connect a secure websocket uri.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [allow unstrusted certificate]; otherwise, <c>false</c>.
        /// </value>
        public bool AllowUnstrustedCertificate
        {
            get { return m_AllowUnstrustedCertificate; }
            set
            {
                m_AllowUnstrustedCertificate = value;

                var client = Client as SslStreamTcpSession;

                if(client != null)
                {
                    client.AllowUnstrustedCertificate = m_AllowUnstrustedCertificate;
                }
            }
        }

        public WebSocket(string uri)
            : this(uri, string.Empty)
        {
        }

        public WebSocket(string uri, WebSocketVersion version)
            : this(uri, string.Empty, null, version)
        {

        }

        public WebSocket(string uri, string subProtocol)
            : this(uri, subProtocol, null, WebSocketVersion.None)
        {
        }

        public WebSocket(string uri, List<KeyValuePair<string, string>> cookies)
            : this(uri, string.Empty, cookies, WebSocketVersion.None)
        {
        }

        public WebSocket(string uri, string subProtocol, List<KeyValuePair<string, string>> cookies)
            : this(uri, subProtocol, cookies, WebSocketVersion.None)
        {

        }

        public WebSocket(string uri, string subProtocol, WebSocketVersion version)
            : this(uri, subProtocol, null, version)
        {

        }

        public WebSocket(string uri, string subProtocol, List<KeyValuePair<string, string>> cookies, WebSocketVersion version)
            : this(uri, subProtocol, cookies, new List<KeyValuePair<string, string>>(), null, version)
        {

        }

        public WebSocket(string uri, string subProtocol, List<KeyValuePair<string, string>> cookies, string userAgent, WebSocketVersion version)
            : this(uri, subProtocol, cookies, null, userAgent, version)
        {

        }

        public WebSocket(string uri, string subProtocol, List<KeyValuePair<string, string>> cookies, List<KeyValuePair<string, string>> customHeaderItems, string userAgent, WebSocketVersion version)
            : this(uri, subProtocol, cookies, customHeaderItems, userAgent, string.Empty, version)
        {

        }

        public WebSocket(string uri, string subProtocol, List<KeyValuePair<string, string>> cookies, List<KeyValuePair<string, string>> customHeaderItems, string userAgent, string origin, WebSocketVersion version)
        {
            Initialize(uri, subProtocol, cookies, customHeaderItems, userAgent, origin, version);
        }
    }
}


text:
package edu.umd.cs.psl.model.formula;

import java.util.ArrayList;

public class Conjunction extends AbstractBranchFormula {

	public Conjunction(Formula... f) {
		super(f);
	}

	@Override
	public Formula getDNF() {
		Formula[] components = new Formula[getNoFormulas()];
		ArrayList<Integer> disjunctions = new ArrayList<Integer>();
		int size = 1;
		for (int i = 0; i < components.length; i++) {
			components[i] = get(i).getDNF();
			if (components[i] instanceof Disjunction) {
				size *= ((Disjunction) components[i]).getNoFormulas();
				disjunctions.add(i);
			}
		}

		if (disjunctions.size() == 0)
			return new Conjunction(components);

		/* Distributes the conjunction operator over disjunctions */
		Formula[] dnfComponents = new Formula[size];
		Formula[] conjunctionComponents = new Formula[getNoFormulas()];
		int[] indices = new int[disjunctions.size()];
		for (int i = 0; i < size; i++) {
			/*
			 * First, increments a vector of indices corresponding to the
			 * current formula in each disjunction such that each combination
			 * of formulas will be selected once
			 */
			for (int j = 0; j < indices.length; j++) {
				indices[j]++;
				if (indices[j] == ((Disjunction) components[disjunctions.get(j)]).getNoFormulas())
					indices[j] = 0;
				else
					break;
			}

			/*
			 * Next, creates a conjunction from the selected formulas, finds
			 * its DNF, and adds it to the set of formulas that will be returned
			 * as a disjunction
			 */
			for (int j = 0; j < conjunctionComponents.length; j++) {
				if (components[j] instanceof Disjunction)
					conjunctionComponents[j] = ((Disjunction) components[j]).get(indices[j]);
				else
					conjunctionComponents[j] = components[j];
			}

			dnfComponents[i] = new Conjunction(conjunctionComponents).getDNF();
		}

		return new Disjunction(dnfComponents);
	}

	/**
	 * Collapses nested Conjunctions.
	 * <p>
	 * Stops descending where ever a Formula other than a Conjunction is.
	 *
	 * @return the flattened Conjunction
	 */
	public Conjunction flatten() {
		ArrayList<Formula> conj = new ArrayList<Formula>(getNoFormulas());
		for (Formula f : formulas) {
			if (f instanceof Conjunction) {
				Formula[] newFormulas = ((Conjunction) f).flatten().formulas;
				for (Formula newF : newFormulas)
					conj.add(newF);
			}
			else
				conj.add(f);
		}
		return new Conjunction((Formula[]) conj.toArray(new Formula[conj.size()]));
	}

	@Override
	protected String separatorString() {
		return "&";
	}

}


text:
(function(window, $){
  $(function(){
    var template = $("#playerTemplate").html();

    var loadData = function(playerName){
      $.ajax({
        url: 'https://neflaria.com/api/player.php',
        dataType: 'jsonp',
        data: { player: playerName },
        success: function(data){
          window.location.hash = $("#player").val();
          var templateData  = { player: data };

          $("#playerInfo").html(Mustache.render(template, templateData));
        }
      });
    }

    $("form").bind("submit", function(e){
      e.preventDefault();
      loadData($("#player").val());
    });

    if(window.location.hash){
      player = window.location.hash.substr(1,window.location.hash.length);

      $("#player").val(player);
      loadData(player);
    }
  });
})(window, jQuery);


text:
@interface ViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *heading;
@property (weak, nonatomic) IBOutlet UITextField *username;
@property (weak, nonatomic) IBOutlet UITextField *password;
@property (weak, nonatomic) IBOutlet UIButton *loginButton;

@property (weak, nonatomic) IBOutlet UIImageView *cloud1;
@property (weak, nonatomic) IBOutlet UIImageView *cloud2;
@property (weak, nonatomic) IBOutlet UIImageView *cloud3;
@property (weak, nonatomic) IBOutlet UIImageView *cloud4;
@end

@implementation ViewController{
    UIActivityIndicatorView *_spinner;
    UIImageView *_status;
    UILabel *_label;
    NSArray *_messages;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.loginButton.layer.cornerRadius = 8.0;
    self.loginButton.layer.masksToBounds = YES;

    _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    _spinner.frame = CGRectMake(-20.0, 6.0, 20.0, 20.0);
    [_spinner startAnimating];
    _spinner.alpha = 0.0;
    [self.loginButton addSubview:_spinner];

    _status = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner"]];
    _status.hidden = YES;
    _status.center = self.loginButton.center;
    [self.view addSubview:_status];

    _label = [[UILabel alloc] init];
    _label.frame = CGRectMake(0.0, 0.0, _status.frame.size.width, _status.frame.size.height);
    _label.font = [UIFont fontWithName:@"HelveticaNeue" size:18.0];
    _label.textColor = [UIColor colorWithRed:0.89 green:0.38 blue:0.0 alpha:1.0];
    _label.textAlignment = NSTextAlignmentCenter;
    [_status addSubview:_label];

    _messages = @[@"Connecting ...",@"Authorizing ...",@"Sending credentials ...",@"Failed"];

}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
//    CGFloat offset = self.view.bounds.size.width;

//    self.heading.center = CGPointMake(self.heading.center.x - offset, self.heading.center.y);
//    self.username.center = CGPointMake(self.username.center.x - offset, self.username.center.y);
//    self.password.center = CGPointMake(self.password.center.x - offset, self.password.center.y);

    self.cloud1.alpha = 0.0;
    self.cloud2.alpha = 0.0;
    self.cloud3.alpha = 0.0;
    self.cloud4.alpha = 0.0;

    self.loginButton.alpha = 0.0;

}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    CGFloat offset = self.view.bounds.size.width;
    self.heading.center = CGPointMake(self.heading.center.x - offset, self.heading.center.y);
    self.username.center = CGPointMake(self.username.center.x - offset, self.username.center.y);
    self.password.center = CGPointMake(self.password.center.x - offset, self.password.center.y);

    self.loginButton.center = CGPointMake(self.loginButton.center.x, self.loginButton.center.y + 30.0);

    [UIView animateWithDuration:0.5 animations:^{
        self.heading.center = CGPointMake(self.heading.center.x + offset, self.heading.center.y);
    }];

//    [UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationOptionTransitionNone animations:^{
//        self.username.center = CGPointMake(self.username.center.x + offset, self.username.center.y);
//    } completion:nil];
//
//    [UIView animateWithDuration:0.5 delay:0.4 options:UIViewAnimationOptionTransitionNone animations:^{
//        self.password.center = CGPointMake(self.password.center.x + offset, self.password.center.y);
//    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.3 usingSpringWithDamping:0.6 initialSpringVelocity:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
          self.username.center = CGPointMake(self.username.center.x + offset, self.username.center.y);
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.4 usingSpringWithDamping:0.6 initialSpringVelocity:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.password.center = CGPointMake(self.password.center.x + offset, self.password.center.y);
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.5 options:UIViewAnimationOptionTransitionNone animations:^{
        self.cloud1.alpha = 1.0;
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.7 options:UIViewAnimationOptionTransitionNone animations:^{
        self.cloud2.alpha = 1.0;
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.9 options:UIViewAnimationOptionTransitionNone animations:^{
        self.cloud3.alpha = 1.0;
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:1.1 options:UIViewAnimationOptionTransitionNone animations:^{
        self.cloud4.alpha = 1.0;
    } completion:nil];

    [UIView animateWithDuration:0.5 delay:0.5 usingSpringWithDamping:0.5 initialSpringVelocity:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.loginButton.center = CGPointMake(self.loginButton.center.x, self.loginButton.center.y - 30);
        self.loginButton.alpha = 1.0;
    } completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)login {

    [UIView animateWithDuration:1.5 delay:0.0 usingSpringWithDamping:0.2 initialSpringVelocity:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.loginButton.bounds = CGRectMake(0, 0, self.loginButton.bounds.size.width + 80, self.loginButton.bounds.size.height);
    } completion:nil];

    [UIView animateWithDuration:0.33 delay:0.0 usingSpringWithDamping:0.7 initialSpringVelocity:0.0 options:UIViewAnimationOptionTransitionNone animations:^{
        self.loginButton.center = CGPointMake(self.loginButton.center.x, self.loginButton.center.y + 60);
        self.loginButton.backgroundColor = [UIColor colorWithRed:0.85 green:0.83 blue:0.45 alpha:1.0];

        _spinner.center = CGPointMake(40.0, self.loginButton.frame.size.height / 2);
        _spinner.alpha = 1.0;
    } completion:nil];
}

#pragma UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    UITextField *nextField = (textField == self.username) ?  self.password : self.username;
    [nextField becomeFirstResponder];
    return YES;
}
@end


text:
Artifactory Repo Stats User Plugin
==================================

This plugin displays certain statistics about requested files via the REST API.
Given one or more file paths, this plugin will show the number of artifacts and
the combined filesize of those artifacts at each of those locations.

Parameters
----------

This plugin takes one parameter, called `paths`, which consists of a
comma-separated list of paths to show stats for. Each path is in the form
`repository-name/path/to/file`.

Executing
---------

To execute the plugin (as an example):

`curl -X POST -uadmin:password http://localhost:8088/artifactory/api/plugins/execute/repoStats?params=paths=libs-release-local/dir/path1,libs-release-local/dir/path2`

The response is a JSON object in the following form:
```JSON
{
    "stats": [
        {
            "repoPath": "libs-release-local/dir/path1",
            "count": 2,
            "size": "21 bytes"
        },
        {
            "repoPath": "libs-release-local/dir/path2",
            "count": 1,
            "size": "10 bytes"
        }
    ]
}
```