text:
from cob import route

from . import mymodels

from flask import jsonify

@route('/purge', methods=['POST'])
def purge():
    mymodels.Person.query.delete()
    mymodels.db.session.commit()
    return 'ok'

@route('/list_models')
def get_all_models():
    return jsonify([{'id': p.id} for p in mymodels.Person.query.all()])

@route('/add_model', methods=['POST'])
def add_model():
    mymodels.db.session.add(
        mymodels.Person())
    mymodels.db.session.commit()
    return 'ok'


text:
#ifndef __AVLTREE__
#define __AVLTREE__

#ifndef __MACTYPES__
#include <MacTypes.h>
#endif

#ifndef __MIXEDMODE__
#include <MixedMode.h>
#endif

/* The visit stage for AVLWalk() walkProcs */

#if PRAGMA_ONCE
#pragma once
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if PRAGMA_IMPORT
#pragma import on
#endif

#if PRAGMA_STRUCT_ALIGN
    #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
    #pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
    #pragma pack(2)
#endif

/*
 *  AVLTree
 *
 *  Discussion:
 *    Prototypes for routines which create, destroy, allow for
 *    insertion, deleting, and iteration of routines in an AVL balanced
 *    binary tree.
 *
 *    An AVL tree is a balanced, binary tree which is fairly fast for
 *    finds and acceptably fast for insertion and deletion.  The tree
 *    is kept balanced, so that the heights of any given node's left
 *    and right branches never differ by more than 1, which keeps
 *    performance from being too horribe in the degenerate case.
 *
 *
 *    Very loosely based on some public domain source code for doing
 *    avl trees and on the discussion in Sedgewick "Algorithms" book.
 */
typedef UInt16 AVLVisitStage;
enum {
  kAVLPreOrder                  = 0,
  kAVLInOrder                   = 1,
  kAVLPostOrder                 = 2
};

/* The order the tree is walked or disposed of. */
typedef UInt16 AVLOrder;
enum {
  kLeftToRight                  = 0,
  kRightToLeft                  = 1
};

/* The type of the node being passed to a callback proc. */
typedef UInt16 AVLNodeType;
enum {
  kAVLIsTree                    = 0,
  kAVLIsLeftBranch              = 1,
  kAVLIsRightBranch             = 2,
  kAVLIsLeaf                    = 3,
  kAVLNullNode                  = 4
};

enum {
  errItemAlreadyInTree          = -960,
  errNotValidTree               = -961,
  errItemNotFoundInTree         = -962,
  errCanNotInsertWhileWalkProcInProgress = -963,
  errTreeIsLocked               = -964
};

/*  The structure of a tree.  It's opaque; don't assume it's 36 bytes in size.*/
struct AVLTreeStruct {
  OSType              signature;
  unsigned long       privateStuff[8];
};
typedef struct AVLTreeStruct            AVLTreeStruct;
typedef AVLTreeStruct *                 AVLTreePtr;
/*
    Every tree must have a function which compares the data for two items and returns < 0, 0, or >0
    for the items - < 0 if the first item is 'before' the second item according to some criteria,
    == 0 if the two items are identical according to the criteria, or > 0 if the first item is
    'after' the second item according to the criteria.  The comparison function is also passed the
    node type, but most of the time this can be ignored.
*/
typedef CALLBACK_API( SInt32 , AVLCompareItemsProcPtr )(AVLTreePtr tree, const void *i1, const void *i2, AVLNodeType nd_typ);
/*
    Every tree must have a itemSizeProc; this routine gets passed a pointer to the item's data and
    returns the size of the data.  If a tree contains records of a fixed size, this function can
    just return sizeof( that-struct ); otherwise it should calculate the size of the item based on
    the data for the item.
*/
typedef CALLBACK_API( UInt32 , AVLItemSizeProcPtr )(AVLTreePtr tree, const void *itemPtr);
/*
    A tree may have an optional disposeItemProc, which gets called whenever an item is removed
    from the tree ( via AVLRemove() or when AVLDispose() deletes all of the items in the tree ).
    This might be useful if the nodes in the tree own 'resources'  ( like, open files ) which
    should be released before the item is removed.
*/
typedef CALLBACK_API( void , AVLDisposeItemProcPtr )(AVLTreePtr tree, const void *dataP);
/*
    The common way to iterate across all of the items in a tree is via AVLWalk(), which takes
    a walkProcPtr.  This function will get called for every item in the tree three times, as
    the tree is being walked across.  First, the walkProc will get called with visitStage ==
    kAVLPreOrder, at which point internally the node of the tree for the given data has just
    been reached.  Later, this function will get called with visitStage == kAVLInOrder, and
    lastly this function will get called with visitStage == kAVLPostOrder.
    The 'minimum' item in the tree will get called with visitStage == kInOrder first, followed
    by the 'next' item in the tree, up until the last item in the tree structure is called.
    In general, you'll only care about calls to this function when visitStage == kAVLInOrder.
*/
typedef CALLBACK_API( OSErr , AVLWalkProcPtr )(AVLTreePtr tree, const void *dataP, AVLVisitStage visitStage, AVLNodeType node, UInt32 level, SInt32 balance, void *refCon);
typedef STACK_UPP_TYPE(AVLCompareItemsProcPtr)                  AVLCompareItemsUPP;
typedef STACK_UPP_TYPE(AVLItemSizeProcPtr)                      AVLItemSizeUPP;
typedef STACK_UPP_TYPE(AVLDisposeItemProcPtr)                   AVLDisposeItemUPP;
typedef STACK_UPP_TYPE(AVLWalkProcPtr)                          AVLWalkUPP;
/*
 *  NewAVLCompareItemsUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( AVLCompareItemsUPP )
NewAVLCompareItemsUPP(AVLCompareItemsProcPtr userRoutine);
#if !OPAQUE_UPP_TYPES
  enum { uppAVLCompareItemsProcInfo = 0x00002FF0 };  /* pascal 4_bytes Func(4_bytes, 4_bytes, 4_bytes, 2_bytes) */
  #ifdef __cplusplus
    inline DEFINE_API_C(AVLCompareItemsUPP) NewAVLCompareItemsUPP(AVLCompareItemsProcPtr userRoutine) { return (AVLCompareItemsUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLCompareItemsProcInfo, GetCurrentArchitecture()); }
  #else
    #define NewAVLCompareItemsUPP(userRoutine) (AVLCompareItemsUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLCompareItemsProcInfo, GetCurrentArchitecture())
  #endif
#endif

/*
 *  NewAVLItemSizeUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( AVLItemSizeUPP )
NewAVLItemSizeUPP(AVLItemSizeProcPtr userRoutine);
#if !OPAQUE_UPP_TYPES
  enum { uppAVLItemSizeProcInfo = 0x000003F0 };  /* pascal 4_bytes Func(4_bytes, 4_bytes) */
  #ifdef __cplusplus
    inline DEFINE_API_C(AVLItemSizeUPP) NewAVLItemSizeUPP(AVLItemSizeProcPtr userRoutine) { return (AVLItemSizeUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLItemSizeProcInfo, GetCurrentArchitecture()); }
  #else
    #define NewAVLItemSizeUPP(userRoutine) (AVLItemSizeUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLItemSizeProcInfo, GetCurrentArchitecture())
  #endif
#endif

/*
 *  NewAVLDisposeItemUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( AVLDisposeItemUPP )
NewAVLDisposeItemUPP(AVLDisposeItemProcPtr userRoutine);
#if !OPAQUE_UPP_TYPES
  enum { uppAVLDisposeItemProcInfo = 0x000003C0 };  /* pascal no_return_value Func(4_bytes, 4_bytes) */
  #ifdef __cplusplus
    inline DEFINE_API_C(AVLDisposeItemUPP) NewAVLDisposeItemUPP(AVLDisposeItemProcPtr userRoutine) { return (AVLDisposeItemUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLDisposeItemProcInfo, GetCurrentArchitecture()); }
  #else
    #define NewAVLDisposeItemUPP(userRoutine) (AVLDisposeItemUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLDisposeItemProcInfo, GetCurrentArchitecture())
  #endif
#endif

/*
 *  NewAVLWalkUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( AVLWalkUPP )
NewAVLWalkUPP(AVLWalkProcPtr userRoutine);
#if !OPAQUE_UPP_TYPES
  enum { uppAVLWalkProcInfo = 0x000FEBE0 };  /* pascal 2_bytes Func(4_bytes, 4_bytes, 2_bytes, 2_bytes, 4_bytes, 4_bytes, 4_bytes) */
  #ifdef __cplusplus
    inline DEFINE_API_C(AVLWalkUPP) NewAVLWalkUPP(AVLWalkProcPtr userRoutine) { return (AVLWalkUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLWalkProcInfo, GetCurrentArchitecture()); }
  #else
    #define NewAVLWalkUPP(userRoutine) (AVLWalkUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAVLWalkProcInfo, GetCurrentArchitecture())
  #endif
#endif

/*
 *  DisposeAVLCompareItemsUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( void )
DisposeAVLCompareItemsUPP(AVLCompareItemsUPP userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(void) DisposeAVLCompareItemsUPP(AVLCompareItemsUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  #else
      #define DisposeAVLCompareItemsUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  #endif
#endif

/*
 *  DisposeAVLItemSizeUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( void )
DisposeAVLItemSizeUPP(AVLItemSizeUPP userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(void) DisposeAVLItemSizeUPP(AVLItemSizeUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  #else
      #define DisposeAVLItemSizeUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  #endif
#endif

/*
 *  DisposeAVLDisposeItemUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( void )
DisposeAVLDisposeItemUPP(AVLDisposeItemUPP userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(void) DisposeAVLDisposeItemUPP(AVLDisposeItemUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  #else
      #define DisposeAVLDisposeItemUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  #endif
#endif

/*
 *  DisposeAVLWalkUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( void )
DisposeAVLWalkUPP(AVLWalkUPP userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(void) DisposeAVLWalkUPP(AVLWalkUPP userUPP) { DisposeRoutineDescriptor((UniversalProcPtr)userUPP); }
  #else
      #define DisposeAVLWalkUPP(userUPP) DisposeRoutineDescriptor(userUPP)
  #endif
#endif

/*
 *  InvokeAVLCompareItemsUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( SInt32 )
InvokeAVLCompareItemsUPP(
  AVLTreePtr          tree,
  const void *        i1,
  const void *        i2,
  AVLNodeType         nd_typ,
  AVLCompareItemsUPP  userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(SInt32) InvokeAVLCompareItemsUPP(AVLTreePtr tree, const void * i1, const void * i2, AVLNodeType nd_typ, AVLCompareItemsUPP userUPP) { return (SInt32)CALL_FOUR_PARAMETER_UPP(userUPP, uppAVLCompareItemsProcInfo, tree, i1, i2, nd_typ); }
  #else
    #define InvokeAVLCompareItemsUPP(tree, i1, i2, nd_typ, userUPP) (SInt32)CALL_FOUR_PARAMETER_UPP((userUPP), uppAVLCompareItemsProcInfo, (tree), (i1), (i2), (nd_typ))
  #endif
#endif

/*
 *  InvokeAVLItemSizeUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( UInt32 )
InvokeAVLItemSizeUPP(
  AVLTreePtr      tree,
  const void *    itemPtr,
  AVLItemSizeUPP  userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(UInt32) InvokeAVLItemSizeUPP(AVLTreePtr tree, const void * itemPtr, AVLItemSizeUPP userUPP) { return (UInt32)CALL_TWO_PARAMETER_UPP(userUPP, uppAVLItemSizeProcInfo, tree, itemPtr); }
  #else
    #define InvokeAVLItemSizeUPP(tree, itemPtr, userUPP) (UInt32)CALL_TWO_PARAMETER_UPP((userUPP), uppAVLItemSizeProcInfo, (tree), (itemPtr))
  #endif
#endif

/*
 *  InvokeAVLDisposeItemUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( void )
InvokeAVLDisposeItemUPP(
  AVLTreePtr         tree,
  const void *       dataP,
  AVLDisposeItemUPP  userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(void) InvokeAVLDisposeItemUPP(AVLTreePtr tree, const void * dataP, AVLDisposeItemUPP userUPP) { CALL_TWO_PARAMETER_UPP(userUPP, uppAVLDisposeItemProcInfo, tree, dataP); }
  #else
    #define InvokeAVLDisposeItemUPP(tree, dataP, userUPP) CALL_TWO_PARAMETER_UPP((userUPP), uppAVLDisposeItemProcInfo, (tree), (dataP))
  #endif
#endif

/*
 *  InvokeAVLWalkUPP()
 *
 *  Availability:
 *    Non-Carbon CFM:   available as macro/inline
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API_C( OSErr )
InvokeAVLWalkUPP(
  AVLTreePtr     tree,
  const void *   dataP,
  AVLVisitStage  visitStage,
  AVLNodeType    node,
  UInt32         level,
  SInt32         balance,
  void *         refCon,
  AVLWalkUPP     userUPP);
#if !OPAQUE_UPP_TYPES
  #ifdef __cplusplus
      inline DEFINE_API_C(OSErr) InvokeAVLWalkUPP(AVLTreePtr tree, const void * dataP, AVLVisitStage visitStage, AVLNodeType node, UInt32 level, SInt32 balance, void * refCon, AVLWalkUPP userUPP) { return (OSErr)CALL_SEVEN_PARAMETER_UPP(userUPP, uppAVLWalkProcInfo, tree, dataP, visitStage, node, level, balance, refCon); }
  #else
    #define InvokeAVLWalkUPP(tree, dataP, visitStage, node, level, balance, refCon, userUPP) (OSErr)CALL_SEVEN_PARAMETER_UPP((userUPP), uppAVLWalkProcInfo, (tree), (dataP), (visitStage), (node), (level), (balance), (refCon))
  #endif
#endif

#if CALL_NOT_IN_CARBON || OLDROUTINENAMES
    /* support for pre-Carbon UPP routines: New...Proc and Call...Proc */
    #define NewAVLCompareItemsProc(userRoutine)                 NewAVLCompareItemsUPP(userRoutine)
    #define NewAVLItemSizeProc(userRoutine)                     NewAVLItemSizeUPP(userRoutine)
    #define NewAVLDisposeItemProc(userRoutine)                  NewAVLDisposeItemUPP(userRoutine)
    #define NewAVLWalkProc(userRoutine)                         NewAVLWalkUPP(userRoutine)
    #define CallAVLCompareItemsProc(userRoutine, tree, i1, i2, nd_typ) InvokeAVLCompareItemsUPP(tree, i1, i2, nd_typ, userRoutine)
    #define CallAVLItemSizeProc(userRoutine, tree, itemPtr)     InvokeAVLItemSizeUPP(tree, itemPtr, userRoutine)
    #define CallAVLDisposeItemProc(userRoutine, tree, dataP)    InvokeAVLDisposeItemUPP(tree, dataP, userRoutine)
    #define CallAVLWalkProc(userRoutine, tree, dataP, visitStage, node, level, balance, refCon) InvokeAVLWalkUPP(tree, dataP, visitStage, node, level, balance, refCon, userRoutine)
#endif /* CALL_NOT_IN_CARBON */

/*
    Create an AVL tree.  The compareItemsProc and the sizeItemProc are required; disposeItemProc is
    optional and can be nil.  The refCon is stored with the list, and is passed back to the
    compareItemsProc, sizeItemProc, and disposeItemsProc calls.  The allocation of the tree ( and all
    nodes later added to the list with AVLInsert ) will be created in what is the current zone at the
    time AVLInit() is called.  Always call AVLDispose() to dispose of a list created with AVLInit().
*/
/*
 *  AVLInit()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLInit(
  UInt32               flags,
  AVLCompareItemsUPP   compareItemsProc,
  AVLItemSizeUPP       sizeItemProc,
  AVLDisposeItemUPP    disposeItemProc,
  void *               refCon,
  AVLTreePtr *         tree)                                  THREEWORDINLINE(0x303C, 0x0C01, 0xAA80);

/*
    Dispose of an AVL tree.  This will dispose of each item in the tree in the order specified,
    call the tree's disposeProc proc for each item, and then dispose of the space allocated for
    the tree itself.
*/
/*
 *  AVLDispose()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLDispose(
  AVLTreePtr *  tree,
  AVLOrder      order)                                        THREEWORDINLINE(0x303C, 0x0302, 0xAA80);

/*
    Iterate across all of the items in the tree, in the order specified.  kLeftToRight is
    basically lowest-to-highest order, kRightToLeft is highest-to-lowest order.  For each
    node in the tree, it will call the walkProc with three messages ( at the appropriate
    time ).  First, with kAVLPreOrder when the walking gets to this node in the tree,
    before handling either the left or right subtree, secondly, with kAVLInOrder after
    handling one subtree but before handling the other, and lastly with kAVLPostOrder after
    handling both subtrees.  If you want to handle items in order, then only do something
    if the visit stage is kAVLInOrder.  You can only call AVLRemove() from inside a walkProc
    if visit stage is kAVLPostOrder ( because if you remove a node during the pre or in order
    stages you will corrupt the list ) OR if you return a non-zero result from the walkProc
    call which called AVLRemove() to immediately terminate the walkProc.  Do not call AVLInsert()
    to insert a node into the tree from inside a walkProc.
    The walkProc function gets called with the AVLTreePtr, a pointer to the data for the
    current node ( which you can change in place as long as you do not affect the order within
    the tree ), the visit stage, the type of the current node ( leaf node, right or left branch,
    or full tree ), the level within the tree ( the root is level 1 ), the balance for the
    current node, and the refCon passed to AVLWalk().  This refCon is different from the one passed
    into AVLInit(); use AVLGetRefCon() to get that refCon if you want it inside a walkProc.
    ( Most walkProcs will not care about the values for node type, level, or balance. )
*/
/*
 *  AVLWalk()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLWalk(
  AVLTreePtr   tree,
  AVLWalkUPP   walkProc,
  AVLOrder     order,
  void *       walkRefCon)                                    THREEWORDINLINE(0x303C, 0x0703, 0xAA80);

/*  Return  the number of items in the given tree.*/
/*
 *  AVLCount()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLCount(
  AVLTreePtr   tree,
  UInt32 *     count)                                         THREEWORDINLINE(0x303C, 0x0804, 0xAA80);

/*
    Return the one-based index-th item from the tree by putting it's data at dataPtr
    if dataPtr is non-nil, and it's size into *itemSize if itemSize is non-nil.
    If index is out of range, return errItemNotFoundInTree.  ( Internally, this does
    an AVLWalk(), so the tree can not be modified while this call is in progress ).
*/
/*
 *  AVLGetIndItem()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLGetIndItem(
  AVLTreePtr   tree,
  UInt32       index,
  void *       dataPtr,
  UInt32 *     itemSize)                                      THREEWORDINLINE(0x303C, 0x0805, 0xAA80);

/*
    Insert the given item into the tree.  This will call the tree's sizeItemProc
    to determine how big the item at data is, and then will make a copy of the
    item and insert it into the tree in the appropriate place.  If an item already
    exists in the tree with the same key ( so that the compareItemsUPP returns 0
    when asked to compare this item to an existing one ), then it will return
    errItemNotFoundInTree.
*/
/*
 *  AVLInsert()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLInsert(
  AVLTreePtr    tree,
  const void *  data)                                         THREEWORDINLINE(0x303C, 0x0406, 0xAA80);

/*
    Remove any item from the tree with the given key.  If dataPtr != nil, then
    copy the item's data to dataPtr before removing it from the tree.  Before
    removing the item, call the tree's disposeItemProc to let it release anything
    used by the data in the tree.  It is not necessary to fill in a complete
    record for key, only that the compareItemsProc return 0 when asked to compare
    the data at key with the node in the tree to be deleted.  If the item cannot
    be found in the tree, this will return errItemNotFoundInTree.
*/
/*
 *  AVLRemove()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLRemove(
  AVLTreePtr    tree,
  const void *  key,
  void *        dataPtr,
  UInt32 *      itemSize)                                     THREEWORDINLINE(0x303C, 0x0807, 0xAA80);

/*
    Find the item in the tree with the given key, and return it's data in
    dataPtr ( if dataPtr != nil ), and it's size in *itemSize ( if itemSize
    != nil ).  It is not necessary to fill in a complete record for key,
    only that the compareItemsProc return 0 when asked to compare the data
    at key with the node in the tree to be deleted.  If the item cannot
    be found in the tree, this will return errItemNotFoundInTree.
*/
/*
 *  AVLFind()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLFind(
  AVLTreePtr    tree,
  const void *  key,
  void *        dataPtr,
  UInt32 *      itemSize)                                     THREEWORDINLINE(0x303C, 0x0808, 0xAA80);

/*
    Get the refCon for the given tree ( set in AVLInit ) and return it.
    If the given tree is invalid, then return nil.
*/
/*
 *  AVLGetRefcon()
 *
 *  Availability:
 *    Non-Carbon CFM:   in InterfaceLib 9.0 and later
 *    CarbonLib:        in CarbonLib 1.0 and later
 *    Mac OS X:         in version 10.0 and later
 */
EXTERN_API( OSErr )
AVLGetRefcon(
  AVLTreePtr   tree,
  void **      refCon)                                        THREEWORDINLINE(0x303C, 0x0409, 0xAA80);

#if PRAGMA_STRUCT_ALIGN
    #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
    #pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
    #pragma pack()
#endif

#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif

#ifdef __cplusplus
}
#endif

#endif /* __AVLTREE__ */

redpajama_set_name: RedPajamaGithub


text:
[![Build Status][build_status]][build]
[![Build Status - Windows][build_status_win]][build_win]

SubHook is a super-simple hooking library for C and C++ that works on Windows,
Linux and macOS. It supports x86 only (32-bit and 64-bit).

Installation
------------

Easy method:

1. Copy the source and header files to your project and include
   [`subhook.c`](subhook.c) in your build.
2. On Windows only: Define `SUBHOOK_STATIC` before including `subhook.h`.

With CMake:

1. Copy the subhook repo to your project tree.
2. Call `add_subdirectory(path/to/subhook)` in your CMakeLists.txt.
3. Optional: configure how the library is built by setting these varaible prior
   to `add_subdirectory(...)`:

   * `SUBHOOK_STATIC` - Build as static library (`OFF` by default)
   * `SUBHOOK_INSTALL` - Enable installation and packaging of targets/files
     with CPack (`OFF` by default)
   * `SUBHOOK_TESTS` - Enable tests (`ON` by default)
   * `SUBHOOK_FORCE_32BIT` - Configure for compiling 32-bit binaries on 64-bit
     systems (default is `OFF`)

Use of CMake is not mandatory, the library can be built without it (no extra
build configuration is required).

Examples
--------

In the following examples `foo` is some function or a function pointer that
takes a single argument of type `int` and uses the same calling convention
as `my_foo` (depends on compiler).

### Basic usage

```c
#include <stdio.h>
#include <subhook.h>

subhook_t foo_hook;

void my_foo(int x) {
  /* Remove the hook so that you can call the original function. */
  subhook_remove(foo_hook);

  printf("foo(%d) called\n", x);
  foo(x);

  /* Install the hook back to intercept further calls. */
  subhook_install(foo_hook);
}

int main() {
  /* Create a hook that will redirect all foo() calls to to my_foo(). */
  foo_hook = subhook_new((void *)foo, (void *)my_foo, 0);

  /* Install it. */
  subhook_install(foo_hook);

  foo(123);

  /* Remove the hook and free memory when you're done. */
  subhook_remove(foo_hook);
  subhook_free(foo_hook);
}
```

### Trampolines

Using trampolines allows you to jump to the original code without removing
and re-installing hooks every time your function gets called.

```c
typedef void (*foo_func)(int x);

void my_foo(int x) {
  printf("foo(%d) called\n", x);

  /* Call foo() via trampoline. */
  ((foo_func)subhook_get_trampoline(foo_hook))(x);
}

int main() {
   /* Same code as in the previous example. */
}
```

Please note that subhook has a very simple length disassmebler engine (LDE)
that works only with most common prologue instructions like push, mov, call,
etc. When it encounters an unknown instruction subhook_get_trampoline() will
return NULL. You can delegate instruction decoding to a custom disassembler
of your choice via `subhook_set_disasm_handler()`.

### C++

```c++
#include <iostream>
#include <subhook.h>

subhook::Hook foo_hook;
subhook::Hook foo_hook_tr;

typedef void (*foo_func)(int x);

void my_foo(int x) {
  // ScopedHookRemove removes the specified hook and automatically re-installs
  // it when the object goes out of scope (thanks to C++ destructors).
  subhook::ScopedHookRemove remove(&foo_hook);

  std::cout << "foo(" << x << ") called" << std::endl;
  foo(x + 1);
}

void my_foo_tr(int x) {
  std::cout << "foo(" << x << ") called" << std::endl;

  // Call the original function via trampoline.
  ((foo_func)foo_hook_tr.GetTrampoline())(x + 1);
}

int main() {
  foo_hook.Install((void *)foo, (void *)my_foo);
  foo_hook_tr.Install((void *)foo, (void *)my_foo_tr);
}
```

Known issues
------------

* `subhook_get_trampoline()` may return NULL because only a small subset of
  x86 instructions is supported by the disassembler in this library (just
  common prologue instructions). As a workaround you can plug in a more
  advanced instruction length decoder using `subhook_set_disasm_handler()`.

* If a target function (the function you are hooking) is less than N bytes
  in length, for example if it's a short 2-byte jump to a nearby location
  (sometimes compilers generate code like this), then you will not be able
  to hook it.

  N is 5 by default: 1 byte for jmp opcode + 4 bytes for offset. But if you
  enable the use of 64-bit offsets in 64-bit mode N becomes 14 (see the
  definition of `subhook_jmp64`).

* Some systems protect executable code form being modified at runtime, which
  will not allow you to install hooks, or don't allow to mark heap-allocated
  memory as executable, which prevents the use of trampolines.

  For example, on Fedora you can have such problems because of SELinux (though
  you can disable it or exclude your files). On macOS Catalina the
  `mprotect()` call inside `subhook_new` will fail with "Permission denied"
  (see https://github.com/Zeex/subhook/issues/45).

License
-------

Licensed under the 2-clause BSD license.

[build]: https://travis-ci.org/Zeex/subhook
[build_status]: https://travis-ci.org/Zeex/subhook.svg?branch=master
[build_win]: https://ci.appveyor.com/project/Zeex/subhook/branch/master
[build_status_win]: https://ci.appveyor.com/api/projects/status/q5sp0p8ahuqfh8e4/branch/master?svg=true


text:
/*
 +----------------------------------------------------------------------+
 | PHP-OpenCV                                                           |
 +----------------------------------------------------------------------+
 | This source file is subject to version 2.0 of the Apache license,    |
 | that is bundled with this package in the file LICENSE, and is        |
 | available through the world-wide-web at the following url:           |
 | http://www.apache.org/licenses/LICENSE-2.0.html                      |
 | If you did not receive a copy of the Apache2.0 license and are unable|
 | to obtain it through the world-wide-web, please send a note to       |
 | hihozhou@gmail.com so we can mail you a copy immediately.            |
 +----------------------------------------------------------------------+
 | Author: HaiHao Zhou  <hihozhou@gmail.com>                            |
 +----------------------------------------------------------------------+
 */

#ifndef PHP_OPENCV_MAT_H
#define PHP_OPENCV_MAT_H

#include "../../../php_opencv.h"
#include <opencv2/core.hpp>

using namespace cv;

//todo Mat object noly unchar,need to support double,int,float

extern void opencv_mat_init(int module_number);

extern zend_class_entry *opencv_mat_ce;

#define Z_PHP_MAT_OBJ_P(zv)  get_mat_obj(Z_OBJ_P(zv))

typedef struct _opencv_mat_object{
    zend_object std;
    Mat *mat;
}opencv_mat_object;

/**
 * @param obj
 * @return
 */
static inline opencv_mat_object* get_mat_obj(zend_object *obj) {
    return (opencv_mat_object*)((char*)(obj) - XtOffsetOf(opencv_mat_object, std));
}

void opencv_mat_update_property_by_c_mat(zval *z,Mat *mat);

#endif //OPENCV_MAT_H


text:
package com.mana.innovative.dao;

import com.mana.innovative.constants.CardType;
import com.mana.innovative.constants.QuantityType;
import com.mana.innovative.constants.TestConstants;
import com.mana.innovative.constants.WeightedUnit;
import com.mana.innovative.domain.client.Gemstone;
import com.mana.innovative.domain.client.Item;
import com.mana.innovative.domain.client.ItemDiscount;
import com.mana.innovative.domain.client.ItemImage;
import com.mana.innovative.domain.client.Shop;
import com.mana.innovative.domain.client.WorkingHour;
import com.mana.innovative.domain.common.Address;
import com.mana.innovative.domain.common.CalendarEvent;
import com.mana.innovative.domain.common.Phone;
import com.mana.innovative.domain.common.SidebarType;
import com.mana.innovative.domain.common.Tab;
import com.mana.innovative.domain.consumer.Card;
import com.mana.innovative.domain.consumer.CreditCard;
import com.mana.innovative.domain.consumer.Customer;
import com.mana.innovative.domain.consumer.Preference;
import com.mana.innovative.domain.consumer.Privilege;
import com.mana.innovative.domain.consumer.User;
import com.mana.innovative.domain.consumer.UserRole;
import com.mana.innovative.utilities.date.DateCommons;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class TestDummyDomainObjectGenerator {

    /**
     * The constant logger.
     */
    private static final Logger logger = LoggerFactory.getLogger( TestDummyDomainObjectGenerator.class );

    /**
     * Gets test shop dTO object.
     *
     * @return the test shop dTO object
     */
    public static Shop getTestShopDomainObject( ) {

        Shop shop = new Shop( );
//        shop.setShopId( TestConstants.TEST_ID );
        shop.setShopOwnId( TestConstants.TEST_OWN_ID );
        shop.setShopDescription( TestConstants.TEST_DESCRIPTION );
        shop.setShopName( TestConstants.TEST_NAME );
        shop.setShopWebLink( TestConstants.TEST_WEB_LINK );

        // WorkingHour
        final List< WorkingHour > workingHours = new ArrayList<>( );
        workingHours.add( getTestWorkingHourDomainObject( ) );
        shop.setWorkingHours( workingHours );

        // Address
        shop.setAddress( getTestAddressDomainObject( ) );
        // Item
        List< Item > items = new ArrayList<>( );
        items.add( getTestItemDomainObject( ) );
        shop.setItems( items );

        return shop;
    }

    /**
     * Gets test working hour domain object.
     *
     * @return the test working hour domain object
     */
    public static WorkingHour getTestWorkingHourDomainObject( ) {

        WorkingHour workingHour = new WorkingHour( );
//        workingHour.setWorkingHourId( TestConstants.TEST_ID );
        workingHour.setHoliday( TestConstants.TEST_IS_HOLIDAY );
        workingHour.setWeekend( TestConstants.TEST_IS_WEEKEND );
        workingHour.setOffline( TestConstants.TEST_IS_CLOSED );

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat( TestConstants.TEST_TIME_FORMAT );
        Date time, today = new Date( );
        try {
            time = simpleDateFormat.parse( TestConstants.TEST_START_TIME );
            workingHour.setStartTime( time );
        } catch ( ParseException e ) {
            workingHour.setStartTime( today );
        }
        try {
            time = simpleDateFormat.parse( TestConstants.TEST_END_TIME );
            workingHour.setEndTime( time );
        } catch ( ParseException e ) {
            workingHour.setEndTime( today );
        }
        workingHour.setDay( TestConstants.TEST_DAY );

        return workingHour;
    }

    /**
     * Gets test item dTO object.
     *
     * @return the test item dTO object
     */
    public static Item getTestItemDomainObject( ) {

        final Item item = new Item( );
//        item.setItemId( TestConstants.TEST_ID );
        item.setItemName( TestConstants.TEST_VALUE );
        item.setItemPriceCurrency( TestConstants.TEST_PRICE_CURRENCY );
        item.setItemType( TestConstants.TEST_VALUE );
        item.setItemDescription( TestConstants.TEST_DESCRIPTION );
        item.setItemSubType( TestConstants.TEST_ITEM_TYPE );
        item.setBoughtFrom( TestConstants.TEST_BROUGHT_FROM );

        item.setItemPrice( ( double ) TestConstants.THREE );
        item.setWeight( TestConstants.TEST_WEIGHT );
        item.setQuantity( TestConstants.TEST_QUANTITY );

        item.setQuantityType( QuantityType.UNIT.toString( ) );
        item.setWeightedUnit( WeightedUnit.POUND.toString( ) );

        item.setImageCount( TestConstants.TEST_IMAGE_COUNT );

        List< ItemDiscount > itemDiscountList = new ArrayList<>( );

        itemDiscountList.add( getTestItemDiscountDomainObject( ) );
        item.setItemDiscountList( itemDiscountList );

        List< ItemImage > itemImageList = new ArrayList<>( );
        itemImageList.add( getTestItemImageDomainObject( null ) );
        item.setItemImageList( itemImageList );

        DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );

        try {
            item.setBoughtDate( dateFormat.parse( TestConstants.TEST_BOUGHT_DATE ) );
        } catch ( ParseException exception ) {
            logger.debug( "Date Parse Exception", exception );
        }

        return item;
    }

    /**
     * Gets test address dTO object.
     *
     * @return the test address dTO object
     */
    public static Address getTestAddressDomainObject( ) {

        final Address address = new Address( );
//        address.setAddressId( TestConstants.TEST_ID );
        address.setAddress1( TestConstants.TEST );
        address.setAddress2( TestConstants.TEST );
        address.setDistrict( TestConstants.TEST_DISTRICT );
        address.setCity( TestConstants.TEST_CITY );
        address.setState( TestConstants.TEST_STATE );
        address.setZipCode( TestConstants.TEST_ZIPCODE );

//        address.setLocation( new Location( ) );
        return address;
    }

    /**
     * Gets test address Domain ZERO ID object.
     *
     * @param address the address
     *
     * @return the test address Domain ZERO ID object
     */
    public static Address setTestAddressDomainZEROIDObject( final Address address ) {

        address.setAddressId( TestConstants.ZERO );
        return address;
    }

    /**
     * Gets test tab domain object.
     *
     * @return the test tab domain object
     */
    public static Tab getTestTabDomainObject( ) {
        return getNCreateTabDomainList( ).get( TestConstants.ZERO );

    }

    /**
     * Gets test user domain object.
     *
     * @return the test user domain object
     */
    public static User getTestUserDomainObject( ) {
        return getNCreateDomainUserList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test customer domain object.
     *
     * @return the test customer domain object
     */
    public static Customer getTestCustomerDomainObject( ) {
        return getNCreateDomainCustomerList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test card domain object.
     *
     * @return the test card domain object
     */
    public static Card getTestCardDomainObject( ) {
        return getNCreateDomainCardsList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test credit card domain object.
     *
     * @return the test credit card domain object
     */
    public static CreditCard getTestCreditCardDomainObject( ) {

        return getNCreateDomainCreditCardsList( ).get( TestConstants.ZERO );

    }

    /**
     * Gets test preference domain object.
     *
     * @return the test preference domain object
     */
    public static Preference getTestPreferenceDomainObject( ) {

        return getNCreateDomainPreferenceList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test phone domain object.
     *
     * @return the test phone domain object
     */
    public static Phone getTestPhoneDomainObject( ) {

        return getNCreateDomainPhoneList( ).get( TestConstants.ZERO );

    }

    /**
     * Gets test sidebar type domain object.
     *
     * @return the test sidebar type domain object
     */
    public static SidebarType getTestSidebarTypeDomainObject( ) {

        return getNCreateSidebarDomainList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test calendar event domain object.
     *
     * @return the test calendar event domain object
     */
    public static CalendarEvent getTestCalendarEventDomainObject( ) {

        return getNCreateDomainCalendarEventList( ).get( TestConstants.ZERO );

    }

    /**
     * Gets n create tab domain data.
     *
     * @return the n create tab domain data
     */
    public static List< Tab > getNCreateTabDomainList( ) {

        List< Tab > tabList = new ArrayList<>( );
        Tab tab;
        for ( int i = 0; i < 10; i++ ) {
            tab = new Tab( );
//            tab.setTabId( i );
            tab.setTabContent( "Content " + i );
            tab.setTabName( "name " + i );
            tab.setTabColor( "#00000 " + i );
            tab.setTabPosition( "top " + i );
            tabList.add( tab );
        }
        return tabList;
    }

    /**
     * Gets n create domain user data.
     *
     * @return the n create domain user data
     */
    private static List< User > getNCreateDomainUserList( ) {

        List< User > userList = new ArrayList<>( );
        User user;
//        Address address;
        for ( int i = 0; i < 10; i++ ) {
            user = new User( );

//            user.setUserId( i );
            user.setEmail( i + TestConstants.TEST_EMAIL );
            user.setPassword( TestConstants.TEST_PASS + i );
            user.setUserName( TestConstants.TEST_NAME + i );

            userList.add( user );
        }
        return userList;
    }

    /**
     * Gets n create domain customer data.
     *
     * @return the n create domain customer data
     */
    private static List< Customer > getNCreateDomainCustomerList( ) {

        List< Customer > customerList = new ArrayList<>( );
        Customer customer;
        for ( int i = 0; i < 10; i++ ) {
            customer = new Customer( );
//            customer.setUserId( i );
//           Set User Id
            customer.setEmail( i + TestConstants.TEST_EMAIL );
            customer.setPassword( TestConstants.TEST_PASS + i );
            customer.setUserName( TestConstants.TEST_NAME + i );
//          Set Customer Id
            customer.setFirstName( TestConstants.TEST_NAME + i );
            customer.setLastName( TestConstants.TEST_NAME + i );
            customer.setMiddleName( TestConstants.TEST_NAME + i );

            customer.setCards( getNCreateDomainCreditCardsList( ).subList( TestConstants.ZERO, TestConstants.ONE ) );
            customer.setPhones( getNCreateDomainPhoneList( ).subList( TestConstants.ZERO, TestConstants.ONE ) );
            customer.setPreferences( getNCreateDomainPreferenceList( ).subList( TestConstants.ZERO, TestConstants.ONE ) );

            List< Address > addressList = new ArrayList<>( );
            addressList.add( getTestAddressDomainObject( ) );
            customer.setShippingAddress( addressList );
            setTestAddressDomainZEROIDObject( customer.getShippingAddress( ).get( TestConstants.ZERO ) );
            customerList.add( customer );

        }
        return customerList;
    }

    /**
     * Gets n create domain cards list.
     *
     * @return the n create domain cards list
     */
    public static List< Card > getNCreateDomainCardsList( ) {

        List< Card > cardList = new ArrayList<>( );
        Card card;
        for ( int i = 0; i < 10; i++ ) {
            card = new Card( );
//            card.setCardId( i );

            card.setFirstName( TestConstants.TEST_NAME + i );
            card.setLastName( TestConstants.TEST_NAME + i );

            card.setIssueDate( TestConstants.TEST_ISSUE );

            if ( i % 2 == 0 ) {
                card.setCardHasCustomerPic( TestConstants.TEST_TRUE );
                card.setPictureLocation( TestConstants.TEST );
            } else {
                card.setCardHasCustomerPic( false );
                card.setPictureLocation( "" );
            }

            if ( i < 3 ) {
                card.setCardNumber( TestConstants.VALID_CC_NUMBER );
            } else if ( i >= 3 && i < 6 ) {
                card.setCardNumber( "556373653467325" + i );

            } else if ( i >= 6 && i < 8 ) {
                card.setCardNumber( "656373653467325" + i );

            } else {
                card.setCardNumber( "356373653467324" + i );
            }
            cardList.add( card );
        }
        return cardList;
    }

    /**
     * Gets n create domain cards data.
     *
     * @return the n create domain cards data
     */
    public static List< CreditCard > getNCreateDomainCreditCardsList( ) {

        List< CreditCard > creditCardList = new ArrayList<>( );
        CreditCard creditCard;
        for ( int i = 0; i < 10; i++ ) {
            creditCard = new CreditCard( );
//            creditCard.setCardId( i );

            creditCard.setFirstName( TestConstants.TEST_NAME + i );
            creditCard.setLastName( TestConstants.TEST_NAME + i );
            creditCard.setMiddleName( TestConstants.TEST_NAME + i );

            try {
                creditCard.setCreateOrModified( new SimpleDateFormat( TestConstants.TEST_DATE_FORMAT ).parse(
                        TestConstants.DEFAULT_DATE ) );
            } catch ( ParseException exception ) {
                logger.error( "Failed to create dummy creditCard createOrModified date", exception );
            }

            creditCard.setExpiryDate( TestConstants.TEST_EXPIRY );
            creditCard.setIssueDate( TestConstants.TEST_ISSUE );

            if ( i % 2 == 0 ) {
                creditCard.setCardHasCustomerPic( TestConstants.TEST_TRUE );
                creditCard.setPictureLocation( TestConstants.TEST );
            } else {
                creditCard.setCardHasCustomerPic( false );
                creditCard.setPictureLocation( "" );
            }

            if ( i < 3 ) {
                creditCard.setCardNumber( TestConstants.VALID_CC_NUMBER );
                creditCard.setCardType( CardType.Visa.toString( ) );
            } else if ( i >= 3 && i < 6 ) {
                creditCard.setCardNumber( "556373653467325" + i );
                creditCard.setCardType( CardType.MasterCard.toString( ) );

            } else if ( i >= 6 && i < 8 ) {
                creditCard.setCardNumber( "656373653467325" + i );
                creditCard.setCardType( CardType.Discover.toString( ) );

            } else {
                creditCard.setCardNumber( "356373653467324" + i );
                creditCard.setCardType( CardType.AmericanExpress.toString( ) );
            }

            creditCard.setCVV( TestConstants.TEST_CVV );
            creditCardList.add( creditCard );

        }
        return creditCardList;
    }

    /**
     * Gets n create domain phone data.
     *
     * @return the n create domain phone data
     */
    public static List< Phone > getNCreateDomainPhoneList( ) {

        List< Phone > phoneList = new ArrayList<>( );
        Phone phone;
        for ( int i = 0; i < 10; i++ ) {

            phone = new Phone( );

//            phone.setPhoneId( i );
            phone.setPhoneNumber( i + TestConstants.TEST_PH_NO );
            phone.setPhoneName( TestConstants.TEST_NAME );
            phone.setPhoneCarrier( TestConstants.TEST + i );

            try {
                phone.setBoughtDate( new SimpleDateFormat( TestConstants.TEST_DATE_FORMAT ).parse(
                        TestConstants.TEST_BOUGHT_DATE ) );
            } catch ( ParseException exception ) {
                logger.error( "Failed to create dummy phone boughtDate", exception );
            }
            phone.setPhoneModel( TestConstants.TEST + i );
            phone.setPhoneType( TestConstants.TEST + i );

            phoneList.add( phone );
        }
        return phoneList;
    }

    /**
     * Gets n create domain preference data.
     *
     * @return the n create domain preference data
     */
    public static List< Preference > getNCreateDomainPreferenceList( ) {

        List< Preference > preferenceList = new ArrayList<>( );
        Preference preference;
        for ( int i = 0; i < 10; i++ ) {
            preference = new Preference( );

//            preference.setPreferenceId( i );
            preference.setPreferenceName( TestConstants.TEST_NAME + i );
            preference.setIsPreferred( i % 2 == 0 );

            preferenceList.add( preference );
        }
        return preferenceList;
    }

    /**
     * Gets n create domain calendar event.
     *
     * @return the n create domain calendar event
     */
    public static List< CalendarEvent > getNCreateDomainCalendarEventList( ) {

        List< CalendarEvent > calendarEventList = new ArrayList<>( );
        CalendarEvent calendarEvent;
        for ( int i = 0; i < 10; i++ ) {

            calendarEvent = new CalendarEvent( );

//            calendarEvent.setCalendarEventId( i );
            calendarEvent.setName( TestConstants.TEST_NAME + i );
            calendarEvent.setOptional( TestConstants.TEST + i );
            calendarEvent.setEventName( TestConstants.TEST_NAME + i );
            calendarEvent.setEventDescription( TestConstants.TEST + i * 2 );
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat( TestConstants.TEST_DATE_FORMAT );
            try {
                calendarEvent.setEventStartDate( simpleDateFormat.parse(
                        TestConstants.DEFAULT_DATE ) );
                calendarEvent.setEventEndDate( simpleDateFormat.parse(
                        TestConstants.DEFAULT_DATE ) );
            } catch ( ParseException exception ) {
                logger.error( "Failed to parse date string " + TestConstants.TEST_DATE_FORMAT, exception );
            }
            calendarEventList.add( calendarEvent );
        }
        return calendarEventList;
    }

    /**
     * Gets n create sidebar domain list.
     *
     * @return the n create sidebar domain list
     */
    public static List< SidebarType > getNCreateSidebarDomainList( ) {

        List< SidebarType > sidebarTypeList = new ArrayList<>( );
        SidebarType sidebarType;

        for ( int i = 0; i < 10; i++ ) {
            sidebarType = new SidebarType( );

//            sidebarType.setSidebarTypeId( ( long ) i );
            sidebarType.setTypePriority( i * 100 + i );
            sidebarType.setSuccess( TestConstants.TEST_TRUE );

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat( TestConstants.TEST_DATE_FORMAT );
            try {
                sidebarType.setDueDate( simpleDateFormat.parse( TestConstants.DEFAULT_DATE ) );
            } catch ( Exception exception ) {
                logger.error( "Parse exception for date testing", exception );
            }
            sidebarType.setItemType( TestConstants.TEST_ITEM_TYPE );
            sidebarType.setSubject( TestConstants.TEST_SUBJECT );
            sidebarType.setGroupCount( i );
            sidebarType.setGroupPriority( TestConstants.ZERO );
            sidebarType.setGroupType( TestConstants.TEST );

            sidebarTypeList.add( sidebarType );
        }

        return sidebarTypeList;
    }

    /**
     * Gets test user role domain object.
     *
     * @return the test user role domain object
     */
    public static UserRole getTestUserRoleDomainObject( ) {

        UserRole userRole = new UserRole( );

//        userRole.setUserRoleId( TestConstants.ZERO );
        userRole.setUserRoleName( TestConstants.DEFAULT + TestConstants.ONE );
        userRole.setIsActive( TestConstants.TEST_TRUE );
        userRole.setIsExpired( TestConstants.TEST_FALSE );
        userRole.setIsLocked( TestConstants.TEST_FALSE );
        userRole.setPrivileges( getNCreatePrivilegeDomainList( ) );

        return userRole;
    }

    /**
     * Gets n create privilege domain list.
     *
     * @return the n create privilege domain list
     */
    public static List< Privilege > getNCreatePrivilegeDomainList( ) {

        List< Privilege > privilegeList = new ArrayList<>( );
        Privilege privilege;

        privilege = new Privilege( );
//        privilege.setPrivilegeId( 0 );
        privilege.setPrivilegeName( TestConstants.TEST_NAME );
        privilege.setAccessible( TestConstants.TEST_TRUE );
        privilege.setCreatedDate( new Date( ) );
        privilege.setUpdatedDate( new Date( ) );
        privilegeList.add( privilege );

        return privilegeList;
    }

    /**
     * Gets test privilege domain object.
     *
     * @return the test privilege domain object
     */
    public static Privilege getTestPrivilegeDomainObject( ) {

        return getNCreatePrivilegeDomainList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets test shop Domain ZERO ID object.
     *
     * @param itemDiscount the ItemDiscount
     *
     * @return the test shop Domain ZERO ID object
     */
    public static ItemDiscount setTestItemDiscountDomainZEROIDObject( final ItemDiscount itemDiscount ) {

        itemDiscount.setItemDiscountId( TestConstants.ZERO );
        return itemDiscount;
    }

    /**
     * Gets test item discount domain object.
     *
     * @return the test item discount domain object
     */
    public static ItemDiscount getTestItemDiscountDomainObject( ) {

        ItemDiscount itemDiscount = new ItemDiscount( );
        itemDiscount.setItemDiscountId( TestConstants.ZERO );
        itemDiscount.setDiscountPercent( TestConstants.DEFAULT_ITEM_DISCOUNT_PERCENT );
        itemDiscount.setDiscountType( TestConstants.DEFAULT_ITEM_DISCOUNT_TYPE );
        itemDiscount.setUserRole( TestConstants.DEFAULT_USER_ROLE_NAME );
        itemDiscount.setIsActive( TestConstants.DEFAULT_IS_ACTIVE );

        try {
            itemDiscount.setStartDate( DateCommons.getDateFromDateString( TestConstants.TEST_START_DATE, TestConstants.TEST_DATE_FORMAT ) );
            itemDiscount.setEndDate( DateCommons.getDateFromDateString( TestConstants.TEST_END_DATE, TestConstants.TEST_DATE_FORMAT ) );
        } catch ( Exception exception ) {
            logger.debug( "Date Parse Exception", exception );
        }
        return itemDiscount;
    }

    /**
     * Gets n create item discount domain list.
     *
     * @return the n create item discount domain list
     */
    public static List< ItemDiscount > getNCreateItemDiscountDomainList( ) {

        List< ItemDiscount > itemDiscountList = new ArrayList<>( );
        ItemDiscount itemDiscount;
        for ( int i = 1; i < 5; i++ ) {
            itemDiscount = new ItemDiscount( );
            itemDiscount.setItemDiscountId( i );
            itemDiscount.setDiscountPercent( TestConstants.DEFAULT_ITEM_DISCOUNT_PERCENT );
            itemDiscount.setDiscountType( TestConstants.DEFAULT_ITEM_DISCOUNT_TYPE + i );
            itemDiscount.setUserRole( TestConstants.DEFAULT_USER_ROLE_NAME );
            itemDiscount.setIsActive( i % 2 == 0 );

            DateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" );

            try {
                itemDiscount.setStartDate( dateFormat.parse( TestConstants.TEST_START_DATE ) );
                itemDiscount.setEndDate( dateFormat.parse( TestConstants.TEST_END_DATE ) );
            } catch ( ParseException exception ) {
                logger.debug( "Date Parse Exception", exception );
            }

            itemDiscountList.add( itemDiscount );
        }
        return itemDiscountList;
    }

    /**
     * Gets test item image domain object.
     *
     * @return the test item image domain object
     */
    public static ItemImage getTestItemImageDomainObject( Integer id ) {

        ItemImage itemImage = new ItemImage( );
        itemImage.setItemImageId( id == null ? TestConstants.MINUS_ONE : id );
        itemImage.setImageLocation( id == null || id == 0 ? TestConstants.DEFAULT : TestConstants.DEFAULT_IMAGE_LOCATION );
        itemImage.setImagePriority( id == null || id == 0 ? TestConstants.ZERO : TestConstants.DEFAULT_IMAGE_PRIORITY );
        itemImage.setImageHeight( id == null || id == 0 ? TestConstants.ZERO : TestConstants.DEFAULT_IMAGE_HEIGHT );
        itemImage.setImageWidth( id == null || id == 0 ? TestConstants.ZERO : TestConstants.DEFAULT_IMAGE_WIDTH );

        return itemImage;
    }

    /**
     * Gets n create item image domain list.
     *
     * @return the n create item image domain list
     */
    public static List< ItemImage > getNCreateItemImageDomainList( ) {
        List< ItemImage > itemImageList = new ArrayList<>( );
        ItemImage itemImage;
        for ( int i = 1; i < 5; i++ ) {
            itemImage = new ItemImage( );
            itemImage.setItemImageId( i );
            itemImage.setImageLocation( TestConstants.DEFAULT_IMAGE_LOCATION + i );
            itemImage.setImagePriority( TestConstants.DEFAULT_IMAGE_PRIORITY );
            itemImage.setImageHeight( TestConstants.DEFAULT_IMAGE_HEIGHT + i );
            itemImage.setImageWidth( TestConstants.DEFAULT_IMAGE_WIDTH + i );

            itemImageList.add( itemImage );
        }
        return itemImageList;
    }

    /**
     * Sets test item image domain Zero Id object.
     *
     * @param gemstoneDomain the item image domain
     *
     * @return the test item image domain Zero Id object
     */
    public static Gemstone setTestGemstoneDomainZEROIDObject( final Gemstone gemstoneDomain ) {
        gemstoneDomain.setGemstoneId( TestConstants.ZERO );
        return gemstoneDomain;
    }

    /**
     * Gets test gemstone dTO object.
     *
     * @return the test gemstone dTO object
     */
    public static Gemstone getTestGemstoneDomainObject( ) {
        return getNCreateGemstoneDomainList( ).get( TestConstants.ZERO );
    }

    /**
     * Gets n create gemstone dTO list.
     *
     * @return the created gemstone dTO list
     */
    public static List< Gemstone > getNCreateGemstoneDomainList( ) {
        List< Gemstone > gemstoneList = new ArrayList<>( );
        Gemstone gemstone;
        for ( int i = 1; i < 5; i++ ) {
            gemstone = new Gemstone( );
            gemstone.setGemstoneId( i );
            gemstone.setGemstoneName( TestConstants.DEFAULT_GEM_NAME + i );
            gemstone.setGemstoneDescription( TestConstants.DEFAULT_DESCRIPTION );

            gemstoneList.add( gemstone );
        }
        return gemstoneList;
    }
}


text:
import {
  TestBed,
  async,
  ComponentFixture,
  fakeAsync,
  tick,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
import { StoreModule } from '@ngrx/store';
import {
  HttpClientTestingModule,
  HttpTestingController,
} from '@angular/common/http/testing';

import { BookListComponent } from './book-list/book-list.component';
import { GoogleBooksService } from './book-list/books.service';
import { BookCollectionComponent } from './book-collection/book-collection.component';
import { AppComponent } from './app.component';
import { collectionReducer } from './state/collection.reducer';
import { booksReducer } from './state/books.reducer';

describe('AppComponent Integration Test', () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;
  let booksService: GoogleBooksService;
  let httpMock: HttpTestingController;

  beforeEach(async((done: any) => {
    TestBed.configureTestingModule({
      declarations: [AppComponent, BookListComponent, BookCollectionComponent],
      imports: [
        HttpClientTestingModule,
        StoreModule.forRoot({
          books: booksReducer,
          collection: collectionReducer,
        }),
      ],
      providers: [GoogleBooksService],
    }).compileComponents();

    booksService = TestBed.get(GoogleBooksService);
    httpMock = TestBed.get(HttpTestingController);

    fixture = TestBed.createComponent(AppComponent);
    component = fixture.debugElement.componentInstance;

    fixture.detectChanges();

    const req = httpMock.expectOne(
      'https://www.googleapis.com/books/v1/volumes?maxResults=5&orderBy=relevance&q=oliver%20sacks'
    );
    req.flush({
      items: [
        {
          id: 'firstId',
          volumeInfo: {
            title: 'First Title',
            authors: ['First Author'],
          },
        },
        {
          id: 'secondId',
          volumeInfo: {
            title: 'Second Title',
            authors: ['Second Author'],
          },
        },
      ],
    });

    fixture.detectChanges();
  }));

  afterEach(() => {
    httpMock.verify();
  });

  it('should create the component', () => {
    expect(component).toBeTruthy();
  });

  describe('buttons should work as expected', () => {
    it('should add to collection when add button is clicked and remove from collection when remove button is clicked', () => {
      const addButton = getBookList()[1].query(
        By.css('[data-test=add-button]')
      );

      click(addButton);

      expect(getBookTitle(getCollection()[0])).toBe('Second Title');

      const removeButton = getCollection()[0].query(
        By.css('[data-test=remove-button]')
      );

      click(removeButton);

      expect(getCollection().length).toBe(0);
    });
  });

  function getCollection() {
    return fixture.debugElement.queryAll(By.css('.book-collection .book-item'));
  }

  function getBookList() {
    return fixture.debugElement.queryAll(By.css('.book-list .book-item'));
  }

  function getBookTitle(element) {
    return element.query(By.css('p')).nativeElement.textContent;
  }

  function click(element) {
    const el: HTMLElement = element.nativeElement;
    el.click();
    fixture.detectChanges();
  }
});


text:
require 'spree_core'
require 'spree_line_item_discount/engine'


text:
<?php

declare(strict_types=1);

namespace Gpupo\Similarity;

use Gpupo\Similarity\Input\InputNumber;
use Gpupo\Similarity\Input\InputString;

class Similarity extends SimilarityAbstract implements SimilarInterface
{
    const MODE_STRING = 'text';

    const MODE_NUMBER = 'number';

    protected $mode;

    protected $expert;

    public function __toArray()
    {
        return  $this->getExpert()->__toArray();
    }

    public function setMode($mode)
    {
        $this->mode = $mode;
        $this->expert = null;

        return $this;
    }

    public function setValues($a, $b)
    {
        $input = new InputString($a, $b);
        $this->input = $input;

        $this->setMode(self::MODE_STRING);

        return $this;
    }

    public function setStopwords(array $list)
    {
        $this->getInput()->setStopwords($list);

        return $this;
    }

    public function setNumberValues($a, $b)
    {
        $input = new InputNumber($a, $b);
        $this->input = $input;

        $this->setMode(self::MODE_NUMBER);

        return $this;
    }

    public function hasSimilarity(): bool
    {
        return (bool) $this->getExpert()->hasSimilarity();
    }

    protected function getMode(): string
    {
        if (self::MODE_NUMBER === $this->mode) {
            return self::MODE_NUMBER;
        }

        return self::MODE_STRING;
    }

    protected function getExpert()
    {
        if (!$this->expert) {
            $this->expert = $this->factoryExpert($this->getMode());
        }

        return $this->expert;
    }
}


text:
from __future__ import absolute_import, unicode_literals

import copy
import itertools

import packaging.markers
import packaging.specifiers
import vistir
import vistir.misc

from ..internals.markers import get_without_extra
from ..internals.specifiers import cleanup_pyspecs, pyspec_from_markers

def dedup_markers(s):
    # TODO: Implement better logic.
    deduped = sorted(vistir.misc.dedup(s))
    return deduped

class MetaSet(object):
    """Representation of a "metadata set".

    This holds multiple metadata representaions. Each metadata representation
    includes a marker, and a specifier set of Python versions required.
    """
    def __init__(self):
        self.markerset = frozenset()
        self.pyspecset = packaging.specifiers.SpecifierSet()

    def __repr__(self):
        return "MetaSet(markerset={0!r}, pyspecset={1!r})".format(
            ",".join(sorted(self.markerset)), str(self.pyspecset),
        )

    def __str__(self):
        pyspecs = set()
        markerset = set()
        for m in self.markerset:
            marker_specs = pyspec_from_markers(packaging.markers.Marker(m))
            if marker_specs:
                pyspecs.add(marker_specs)
            else:
                markerset.add(m)
        if pyspecs:
            self.pyspecset._specs &= pyspecs
            self.markerset = frozenset(markerset)
        return " and ".join(dedup_markers(itertools.chain(
            # Make sure to always use the same quotes so we can dedup properly.
            (
                "{0}".format(ms) if " or " in ms else ms
                for ms in (str(m).replace('"', "'") for m in self.markerset)
            ),
            (
                "python_version {0[0]} '{0[1]}'".format(spec)
                for spec in cleanup_pyspecs(self.pyspecset)
            ),
        )))

    def __bool__(self):
        return bool(self.markerset or self.pyspecset)

    def __nonzero__(self):  # Python 2.
        return self.__bool__()

    def __or__(self, pair):
        marker, specset = pair
        markerset = set(self.markerset)
        if marker:
            marker_specs = pyspec_from_markers(marker)
            if not marker_specs:
                markerset.add(str(marker))
            else:
                specset._specs &= marker_specs
        metaset = MetaSet()
        metaset.markerset = frozenset(markerset)
        # TODO: Implement some logic to clean up dups like '3.0.*' and '3.0'.
        metaset.pyspecset &= self.pyspecset & specset
        return metaset

def _build_metasets(dependencies, pythons, key, trace, all_metasets):
    all_parent_metasets = []
    for route in trace:
        parent = route[-1]
        try:
            parent_metasets = all_metasets[parent]
        except KeyError:    # Parent not calculated yet. Wait for it.
            return
        all_parent_metasets.append((parent, parent_metasets))

    metaset_iters = []
    for parent, parent_metasets in all_parent_metasets:
        r = dependencies[parent][key]
        python = pythons[key]
        metaset = (
            get_without_extra(r.markers),
            packaging.specifiers.SpecifierSet(python),
        )
        metaset_iters.append(
            parent_metaset | metaset
            for parent_metaset in parent_metasets
        )
    return list(itertools.chain.from_iterable(metaset_iters))

def _calculate_metasets_mapping(dependencies, pythons, traces):
    all_metasets = {None: [MetaSet()]}

    del traces[None]
    while traces:
        new_metasets = {}
        for key, trace in traces.items():
            assert key not in all_metasets, key     # Sanity check for debug.
            metasets = _build_metasets(
                dependencies, pythons, key, trace, all_metasets,
            )
            if metasets is None:
                continue
            new_metasets[key] = metasets
        if not new_metasets:
            break   # No progress? Deadlocked. Give up.
        all_metasets.update(new_metasets)
        for key in new_metasets:
            del traces[key]

    return all_metasets

def _format_metasets(metasets):
    # If there is an unconditional route, this needs to be unconditional.
    if not metasets or not all(metasets):
        return None

    # This extra str(Marker()) call helps simplify the expression.
    return str(packaging.markers.Marker(" or ".join(
        "{0}".format(s) if " and " in s else s
        for s in dedup_markers(str(metaset) for metaset in metasets
        if metaset)
    )))

def set_metadata(candidates, traces, dependencies, pythons):
    """Add "metadata" to candidates based on the dependency tree.

    Metadata for a candidate includes markers and a specifier for Python
    version requirements.

    :param candidates: A key-candidate mapping. Candidates in the mapping will
        have their markers set.
    :param traces: A graph trace (produced by `traces.trace_graph`) providing
        information about dependency relationships between candidates.
    :param dependencies: A key-collection mapping containing what dependencies
        each candidate in `candidates` requested.
    :param pythons: A key-str mapping containing Requires-Python information
        of each candidate.

    Keys in mappings and entries in the trace are identifiers of a package, as
    implemented by the `identify` method of the resolver's provider.

    The candidates are modified in-place.
    """
    metasets_mapping = _calculate_metasets_mapping(
        dependencies, pythons, copy.deepcopy(traces),
    )
    for key, candidate in candidates.items():
        candidate.markers = _format_metasets(metasets_mapping[key])