text:
#ifndef AV1_COMMON_ENTROPYMODE_H_
#define AV1_COMMON_ENTROPYMODE_H_

#include "av1/common/entropy.h"
#include "av1/common/entropymv.h"
#include "av1/common/filter.h"
#include "av1/common/seg_common.h"
#include "aom_dsp/aom_filter.h"

#if CONFIG_PVQ
#include "av1/common/pvq.h"
#include "av1/common/pvq_state.h"
#include "av1/common/generic_code.h"
#endif  // CONFIG_PVQ

#ifdef __cplusplus
extern "C" {
#endif

#define BLOCK_SIZE_GROUPS 4

#define TX_SIZE_CONTEXTS 2

#define INTER_OFFSET(mode) ((mode)-NEARESTMV)
#if CONFIG_EXT_INTER
#define INTER_COMPOUND_OFFSET(mode) ((mode)-NEAREST_NEARESTMV)
#endif  // CONFIG_EXT_INTER

#if CONFIG_PALETTE
// Number of possible contexts for a color index.
// As can be seen from av1_get_palette_color_index_context(), the possible
// contexts are (2,0,0), (2,2,1), (3,2,0), (4,1,0), (5,0,0). These are mapped to
// a value from 0 to 4 using 'palette_color_index_context_lookup' table.
#define PALETTE_COLOR_INDEX_CONTEXTS 5

// Maximum number of colors in a palette.
#define PALETTE_MAX_SIZE 8
// Minimum number of colors in a palette.
#define PALETTE_MIN_SIZE 2

// Palette mode is available for block sizes >= 8x8.
#define PALETTE_BLOCK_SIZES (BLOCK_LARGEST - BLOCK_8X8 + 1)

// Palette Y mode context for a block is determined by number of neighboring
// blocks (top and/or left) using a palette for Y plane. So, possible Y mode'
// context values are:
// 0 if neither left nor top block uses palette for Y plane,
// 1 if exactly one of left or top block uses palette for Y plane, and
// 2 if both left and top blocks use palette for Y plane.
#define PALETTE_Y_MODE_CONTEXTS 3

// Palette UV mode context for a block is determined by whether this block uses
// palette for the Y plane. So, possible values are:
// 0 if this block doesn't use palette for Y plane.
// 1 if this block uses palette for Y plane (i.e. Y palette size > 0).
#define PALETTE_UV_MODE_CONTEXTS 2

#define PALETTE_MAX_BLOCK_SIZE (64 * 64)
#endif  // CONFIG_PALETTE

struct AV1Common;

typedef struct {
  const int16_t *scan;
  const int16_t *iscan;
  const int16_t *neighbors;
} SCAN_ORDER;

struct seg_counts {
  unsigned int tree_total[MAX_SEGMENTS];
  unsigned int tree_mispred[MAX_SEGMENTS];
  unsigned int pred[PREDICTION_PROBS][2];
};

typedef struct frame_contexts {
  aom_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
  aom_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
#if CONFIG_EXT_PARTITION_TYPES
  aom_prob partition_prob[PARTITION_CONTEXTS][EXT_PARTITION_TYPES - 1];
#else
  aom_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
#endif
  av1_coeff_probs_model coef_probs[TX_SIZES][PLANE_TYPES];
#if CONFIG_NEW_TOKENSET
  coeff_cdf_model coef_tail_cdfs[TX_SIZES][PLANE_TYPES];
  coeff_cdf_model coef_head_cdfs[TX_SIZES][PLANE_TYPES];
  aom_prob blockzero_probs[TX_SIZES][PLANE_TYPES][REF_TYPES][BLOCKZ_CONTEXTS];
#elif CONFIG_EC_MULTISYMBOL
  coeff_cdf_model coef_cdfs[TX_SIZES][PLANE_TYPES];
#endif  // CONFIG_NEW_TOKENSET
  aom_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
                                 [SWITCHABLE_FILTERS - 1];
#if CONFIG_ADAPT_SCAN
// TODO(angiebird): try aom_prob
#if CONFIG_CB4X4
  uint32_t non_zero_prob_2x2[TX_TYPES][4];
#endif
  uint32_t non_zero_prob_4X4[TX_TYPES][16];
  uint32_t non_zero_prob_8X8[TX_TYPES][64];
  uint32_t non_zero_prob_16X16[TX_TYPES][256];
  uint32_t non_zero_prob_32X32[TX_TYPES][1024];

  uint32_t non_zero_prob_4X8[TX_TYPES][32];
  uint32_t non_zero_prob_8X4[TX_TYPES][32];
  uint32_t non_zero_prob_16X8[TX_TYPES][128];
  uint32_t non_zero_prob_8X16[TX_TYPES][128];
  uint32_t non_zero_prob_32X16[TX_TYPES][512];
  uint32_t non_zero_prob_16X32[TX_TYPES][512];

#if CONFIG_CB4X4
  DECLARE_ALIGNED(16, int16_t, scan_2x2[TX_TYPES][4]);
#endif
  DECLARE_ALIGNED(16, int16_t, scan_4X4[TX_TYPES][16]);
  DECLARE_ALIGNED(16, int16_t, scan_8X8[TX_TYPES][64]);
  DECLARE_ALIGNED(16, int16_t, scan_16X16[TX_TYPES][256]);
  DECLARE_ALIGNED(16, int16_t, scan_32X32[TX_TYPES][1024]);

  DECLARE_ALIGNED(16, int16_t, scan_4X8[TX_TYPES][32]);
  DECLARE_ALIGNED(16, int16_t, scan_8X4[TX_TYPES][32]);
  DECLARE_ALIGNED(16, int16_t, scan_8X16[TX_TYPES][128]);
  DECLARE_ALIGNED(16, int16_t, scan_16X8[TX_TYPES][128]);
  DECLARE_ALIGNED(16, int16_t, scan_16X32[TX_TYPES][512]);
  DECLARE_ALIGNED(16, int16_t, scan_32X16[TX_TYPES][512]);

#if CONFIG_CB4X4
  DECLARE_ALIGNED(16, int16_t, iscan_2x2[TX_TYPES][4]);
#endif
  DECLARE_ALIGNED(16, int16_t, iscan_4X4[TX_TYPES][16]);
  DECLARE_ALIGNED(16, int16_t, iscan_8X8[TX_TYPES][64]);
  DECLARE_ALIGNED(16, int16_t, iscan_16X16[TX_TYPES][256]);
  DECLARE_ALIGNED(16, int16_t, iscan_32X32[TX_TYPES][1024]);

  DECLARE_ALIGNED(16, int16_t, iscan_4X8[TX_TYPES][32]);
  DECLARE_ALIGNED(16, int16_t, iscan_8X4[TX_TYPES][32]);
  DECLARE_ALIGNED(16, int16_t, iscan_8X16[TX_TYPES][128]);
  DECLARE_ALIGNED(16, int16_t, iscan_16X8[TX_TYPES][128]);
  DECLARE_ALIGNED(16, int16_t, iscan_16X32[TX_TYPES][512]);
  DECLARE_ALIGNED(16, int16_t, iscan_32X16[TX_TYPES][512]);

#if CONFIG_CB4X4
  int16_t nb_2x2[TX_TYPES][(4 + 1) * 2];
#endif
  int16_t nb_4X4[TX_TYPES][(16 + 1) * 2];
  int16_t nb_8X8[TX_TYPES][(64 + 1) * 2];
  int16_t nb_16X16[TX_TYPES][(256 + 1) * 2];
  int16_t nb_32X32[TX_TYPES][(1024 + 1) * 2];

  int16_t nb_4X8[TX_TYPES][(32 + 1) * 2];
  int16_t nb_8X4[TX_TYPES][(32 + 1) * 2];
  int16_t nb_8X16[TX_TYPES][(128 + 1) * 2];
  int16_t nb_16X8[TX_TYPES][(128 + 1) * 2];
  int16_t nb_16X32[TX_TYPES][(512 + 1) * 2];
  int16_t nb_32X16[TX_TYPES][(512 + 1) * 2];

  SCAN_ORDER sc[TX_SIZES_ALL][TX_TYPES];
#endif  // CONFIG_ADAPT_SCAN

#if CONFIG_LV_MAP
  aom_prob txb_skip[TX_SIZES][TXB_SKIP_CONTEXTS];
  aom_prob nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS];
  aom_prob eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS];
  aom_prob dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS];
  aom_prob coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS]
                     [COEFF_BASE_CONTEXTS];
  aom_prob coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS];
#endif

#if CONFIG_REF_MV
  aom_prob newmv_prob[NEWMV_MODE_CONTEXTS];
  aom_prob zeromv_prob[ZEROMV_MODE_CONTEXTS];
  aom_prob refmv_prob[REFMV_MODE_CONTEXTS];
  aom_prob drl_prob[DRL_MODE_CONTEXTS];

#if CONFIG_EXT_INTER
  aom_prob new2mv_prob;
#endif  // CONFIG_EXT_INTER
#endif  // CONFIG_REF_MV

  aom_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
#if CONFIG_EXT_INTER
  aom_prob inter_compound_mode_probs[INTER_MODE_CONTEXTS]
                                    [INTER_COMPOUND_MODES - 1];
  aom_prob compound_type_prob[BLOCK_SIZES][COMPOUND_TYPES - 1];
  aom_prob interintra_prob[BLOCK_SIZE_GROUPS];
  aom_prob interintra_mode_prob[BLOCK_SIZE_GROUPS][INTERINTRA_MODES - 1];
  aom_prob wedge_interintra_prob[BLOCK_SIZES];
#endif  // CONFIG_EXT_INTER
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
  aom_prob motion_mode_prob[BLOCK_SIZES][MOTION_MODES - 1];
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
  aom_prob obmc_prob[BLOCK_SIZES];
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
  aom_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
  aom_prob comp_inter_prob[COMP_INTER_CONTEXTS];
  aom_prob single_ref_prob[REF_CONTEXTS][SINGLE_REFS - 1];
#if CONFIG_EXT_REFS
  aom_prob comp_ref_prob[REF_CONTEXTS][FWD_REFS - 1];
  aom_prob comp_bwdref_prob[REF_CONTEXTS][BWD_REFS - 1];
#else
  aom_prob comp_ref_prob[REF_CONTEXTS][COMP_REFS - 1];
#endif  // CONFIG_EXT_REFS
  aom_prob tx_size_probs[MAX_TX_DEPTH][TX_SIZE_CONTEXTS][MAX_TX_DEPTH];
#if CONFIG_VAR_TX
  aom_prob txfm_partition_prob[TXFM_PARTITION_CONTEXTS];
#endif
  aom_prob skip_probs[SKIP_CONTEXTS];
#if CONFIG_REF_MV
  nmv_context nmvc[NMV_CONTEXTS];
#else
  nmv_context nmvc;
#endif
  int initialized;
#if CONFIG_EXT_TX
  aom_prob inter_ext_tx_prob[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES - 1];
  aom_prob intra_ext_tx_prob[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
                            [TX_TYPES - 1];
#else
  aom_prob intra_ext_tx_prob[EXT_TX_SIZES][TX_TYPES][TX_TYPES - 1];
  aom_prob inter_ext_tx_prob[EXT_TX_SIZES][TX_TYPES - 1];
#endif  // CONFIG_EXT_TX
#if CONFIG_SUPERTX
  aom_prob supertx_prob[PARTITION_SUPERTX_CONTEXTS][TX_SIZES];
#endif  // CONFIG_SUPERTX
  struct segmentation_probs seg;
#if CONFIG_EXT_INTRA
#if CONFIG_INTRA_INTERP
  aom_prob intra_filter_probs[INTRA_FILTERS + 1][INTRA_FILTERS - 1];
#endif  // CONFIG_INTRA_INTERP
#endif  // CONFIG_EXT_INTRA
#if CONFIG_FILTER_INTRA
  aom_prob filter_intra_probs[PLANE_TYPES];
#endif  // CONFIG_FILTER_INTRA
#if CONFIG_GLOBAL_MOTION
  aom_prob global_motion_types_prob[GLOBAL_TRANS_TYPES - 1];
#endif  // CONFIG_GLOBAL_MOTION
#if CONFIG_LOOP_RESTORATION
  aom_prob switchable_restore_prob[RESTORE_SWITCHABLE_TYPES - 1];
#endif  // CONFIG_LOOP_RESTORATION
#if CONFIG_EC_MULTISYMBOL
  aom_cdf_prob y_mode_cdf[BLOCK_SIZE_GROUPS][CDF_SIZE(INTRA_MODES)];
  aom_cdf_prob uv_mode_cdf[INTRA_MODES][CDF_SIZE(INTRA_MODES)];
#if CONFIG_EXT_PARTITION_TYPES
  aom_cdf_prob partition_cdf[PARTITION_CONTEXTS][CDF_SIZE(EXT_PARTITION_TYPES)];
#else
  aom_cdf_prob partition_cdf[PARTITION_CONTEXTS][CDF_SIZE(PARTITION_TYPES)];
#endif
  aom_cdf_prob switchable_interp_cdf[SWITCHABLE_FILTER_CONTEXTS]
                                    [CDF_SIZE(SWITCHABLE_FILTERS)];
  aom_cdf_prob inter_mode_cdf[INTER_MODE_CONTEXTS][CDF_SIZE(INTER_MODES)];
  /* Keep track of kf_y_cdf here, as this makes handling
     multiple copies for adaptation in tiles easier */
  aom_cdf_prob kf_y_cdf[INTRA_MODES][INTRA_MODES][CDF_SIZE(INTRA_MODES)];
  aom_cdf_prob tx_size_cdf[MAX_TX_DEPTH][TX_SIZE_CONTEXTS]
                          [CDF_SIZE(MAX_TX_DEPTH + 1)];
#if CONFIG_DELTA_Q
  aom_cdf_prob delta_q_cdf[CDF_SIZE(DELTA_Q_PROBS + 1)];
#endif  // CONFIG_DELTA_Q
#if CONFIG_EXT_TX
  aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
                               [CDF_SIZE(TX_TYPES)];
  aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SETS_INTER][EXT_TX_SIZES]
                               [CDF_SIZE(TX_TYPES)];
#else
  aom_cdf_prob intra_ext_tx_cdf[EXT_TX_SIZES][TX_TYPES][CDF_SIZE(TX_TYPES)];
  aom_cdf_prob inter_ext_tx_cdf[EXT_TX_SIZES][CDF_SIZE(TX_TYPES)];
#endif  // CONFIG_EXT_TX
#if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
  aom_cdf_prob intra_filter_cdf[INTRA_FILTERS + 1][CDF_SIZE(INTRA_FILTERS)];
#endif  // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
#endif  // CONFIG_EC_MULTISYMBOL
#if CONFIG_DELTA_Q
  aom_prob delta_q_prob[DELTA_Q_PROBS];
#endif
#if CONFIG_PVQ
  // TODO(any): If PVQ is enabled, most of coefficient related cdf,
  // such as coef_cdfs[], coef_tail_cdfs[], and coef_heaf_cdfs[] can be removed.
  od_adapt_ctx pvq_context;
#endif  // CONFIG_PVQ
} FRAME_CONTEXT;

typedef struct FRAME_COUNTS {
  // Note: This structure should only contain 'unsigned int' fields, or
  // aggregates built solely from 'unsigned int' fields/elements
  unsigned int kf_y_mode[INTRA_MODES][INTRA_MODES][INTRA_MODES];
  unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
  unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
#if CONFIG_EXT_PARTITION_TYPES
  unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES];
#else
  unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
#endif
  av1_coeff_count_model coef[TX_SIZES][PLANE_TYPES];
  unsigned int eob_branch[TX_SIZES][PLANE_TYPES][REF_TYPES][COEF_BANDS]
                         [COEFF_CONTEXTS];
  unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS]
                                [SWITCHABLE_FILTERS];
#if CONFIG_ADAPT_SCAN
#if CONFIG_CB4X4
  unsigned int non_zero_count_2x2[TX_TYPES][4];
#endif  // CONFIG_CB4X4
  unsigned int non_zero_count_4X4[TX_TYPES][16];
  unsigned int non_zero_count_8X8[TX_TYPES][64];
  unsigned int non_zero_count_16X16[TX_TYPES][256];
  unsigned int non_zero_count_32X32[TX_TYPES][1024];

  unsigned int non_zero_count_4x8[TX_TYPES][32];
  unsigned int non_zero_count_8x4[TX_TYPES][32];
  unsigned int non_zero_count_8x16[TX_TYPES][128];
  unsigned int non_zero_count_16x8[TX_TYPES][128];
  unsigned int non_zero_count_16x32[TX_TYPES][512];
  unsigned int non_zero_count_32x16[TX_TYPES][512];

  unsigned int txb_count[TX_SIZES_ALL][TX_TYPES];
#endif  // CONFIG_ADAPT_SCAN

#if CONFIG_LV_MAP
  unsigned int txb_skip[TX_SIZES][TXB_SKIP_CONTEXTS][2];
  unsigned int nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS][2];
  unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2];
  unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2];
  unsigned int coeff_base[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS]
                         [COEFF_BASE_CONTEXTS][2];
  unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS][2];
#endif  // CONFIG_LV_MAP

#if CONFIG_EC_MULTISYMBOL
  av1_blockz_count_model blockz_count[TX_SIZES][PLANE_TYPES];
#endif

#if CONFIG_REF_MV
  unsigned int newmv_mode[NEWMV_MODE_CONTEXTS][2];
  unsigned int zeromv_mode[ZEROMV_MODE_CONTEXTS][2];
  unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2];
  unsigned int drl_mode[DRL_MODE_CONTEXTS][2];
#if CONFIG_EXT_INTER
  unsigned int new2mv_mode[2];
#endif  // CONFIG_EXT_INTER
#endif

  unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
#if CONFIG_EXT_INTER
  unsigned int inter_compound_mode[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES];
  unsigned int interintra[BLOCK_SIZE_GROUPS][2];
  unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
  unsigned int wedge_interintra[BLOCK_SIZES][2];
  unsigned int compound_interinter[BLOCK_SIZES][COMPOUND_TYPES];
#endif  // CONFIG_EXT_INTER
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
  unsigned int motion_mode[BLOCK_SIZES][MOTION_MODES];
#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
  unsigned int obmc[BLOCK_SIZES][2];
#endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
  unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
  unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
  unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2];
#if CONFIG_EXT_REFS
  unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2];
  unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2];
#else
  unsigned int comp_ref[REF_CONTEXTS][COMP_REFS - 1][2];
#endif  // CONFIG_EXT_REFS
  // TODO(any): tx_size_totals is only used by the encoder to decide whether
  // to use forward updates for the coeff probs, and as such it does not really
  // belong into this structure.
  unsigned int tx_size_totals[TX_SIZES];
  unsigned int tx_size[MAX_TX_DEPTH][TX_SIZE_CONTEXTS][TX_SIZES];
#if CONFIG_VAR_TX
  unsigned int txfm_partition[TXFM_PARTITION_CONTEXTS][2];
#endif
  unsigned int skip[SKIP_CONTEXTS][2];
#if CONFIG_REF_MV
  nmv_context_counts mv[NMV_CONTEXTS];
#else
  nmv_context_counts mv;
#endif
#if CONFIG_DELTA_Q
  unsigned int delta_q[DELTA_Q_PROBS][2];
#endif
#if CONFIG_EXT_TX
#if CONFIG_RECT_TX
  unsigned int tx_size_implied[TX_SIZES][TX_SIZES];
#endif  // CONFIG_RECT_TX
  unsigned int inter_ext_tx[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
  unsigned int intra_ext_tx[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
                           [TX_TYPES];
#else
  unsigned int intra_ext_tx[EXT_TX_SIZES][TX_TYPES][TX_TYPES];
  unsigned int inter_ext_tx[EXT_TX_SIZES][TX_TYPES];
#endif  // CONFIG_EXT_TX
#if CONFIG_SUPERTX
  unsigned int supertx[PARTITION_SUPERTX_CONTEXTS][TX_SIZES][2];
  unsigned int supertx_size[TX_SIZES];
#endif  // CONFIG_SUPERTX
  struct seg_counts seg;
#if CONFIG_EXT_INTRA
#if CONFIG_INTRA_INTERP
  unsigned int intra_filter[INTRA_FILTERS + 1][INTRA_FILTERS];
#endif  // CONFIG_INTRA_INTERP
#endif  // CONFIG_EXT_INTRA
#if CONFIG_FILTER_INTRA
  unsigned int filter_intra[PLANE_TYPES][2];
#endif  // CONFIG_FILTER_INTRA
} FRAME_COUNTS;

// Default probabilities for signaling Intra mode for Y plane -- used only for
// intra-only frames. ('default_if_y_probs' is used for inter frames).
// Contexts used: Intra mode (Y plane) of 'above' and 'left' blocks.
extern const aom_prob av1_kf_y_mode_prob[INTRA_MODES][INTRA_MODES]
                                        [INTRA_MODES - 1];
#if CONFIG_EC_MULTISYMBOL
// CDF version of 'av1_kf_y_mode_prob'.
extern const aom_cdf_prob av1_kf_y_mode_cdf[INTRA_MODES][INTRA_MODES]
                                           [CDF_SIZE(INTRA_MODES)];
#endif

#if CONFIG_PALETTE
extern const aom_prob av1_default_palette_y_mode_prob[PALETTE_BLOCK_SIZES]
                                                     [PALETTE_Y_MODE_CONTEXTS];
extern const aom_prob
    av1_default_palette_uv_mode_prob[PALETTE_UV_MODE_CONTEXTS];
extern const aom_prob av1_default_palette_y_size_prob[PALETTE_BLOCK_SIZES]
                                                     [PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_uv_size_prob[PALETTE_BLOCK_SIZES]
                                                      [PALETTE_SIZES - 1];
extern const aom_prob av1_default_palette_y_color_index_prob
    [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
extern const aom_prob av1_default_palette_uv_color_index_prob
    [PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS][PALETTE_COLORS - 1];
#endif  // CONFIG_PALETTE

extern const aom_tree_index av1_intra_mode_tree[TREE_SIZE(INTRA_MODES)];
extern const aom_tree_index av1_inter_mode_tree[TREE_SIZE(INTER_MODES)];
#if CONFIG_EC_MULTISYMBOL
extern int av1_intra_mode_ind[INTRA_MODES];
extern int av1_intra_mode_inv[INTRA_MODES];
extern int av1_inter_mode_ind[INTER_MODES];
extern int av1_inter_mode_inv[INTER_MODES];
#if CONFIG_EXT_TX
extern int av1_ext_tx_intra_ind[EXT_TX_SETS_INTRA][TX_TYPES];
extern int av1_ext_tx_intra_inv[EXT_TX_SETS_INTRA][TX_TYPES];
extern int av1_ext_tx_inter_ind[EXT_TX_SETS_INTER][TX_TYPES];
extern int av1_ext_tx_inter_inv[EXT_TX_SETS_INTER][TX_TYPES];
#endif
#endif

#if CONFIG_EXT_INTER
extern const aom_tree_index
    av1_interintra_mode_tree[TREE_SIZE(INTERINTRA_MODES)];
extern const aom_tree_index
    av1_inter_compound_mode_tree[TREE_SIZE(INTER_COMPOUND_MODES)];
extern const aom_tree_index av1_compound_type_tree[TREE_SIZE(COMPOUND_TYPES)];
#endif  // CONFIG_EXT_INTER
extern const aom_tree_index av1_partition_tree[TREE_SIZE(PARTITION_TYPES)];
#if CONFIG_EXT_PARTITION_TYPES
extern const aom_tree_index
    av1_ext_partition_tree[TREE_SIZE(EXT_PARTITION_TYPES)];
#endif
extern const aom_tree_index
    av1_switchable_interp_tree[TREE_SIZE(SWITCHABLE_FILTERS)];
#if CONFIG_PALETTE
extern const aom_tree_index av1_palette_size_tree[TREE_SIZE(PALETTE_SIZES)];
extern const aom_tree_index
    av1_palette_color_index_tree[PALETTE_SIZES][TREE_SIZE(PALETTE_COLORS)];
#endif  // CONFIG_PALETTE
extern const aom_tree_index av1_tx_size_tree[MAX_TX_DEPTH][TREE_SIZE(TX_SIZES)];
#if CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
extern const aom_tree_index av1_intra_filter_tree[TREE_SIZE(INTRA_FILTERS)];
#endif  // CONFIG_EXT_INTRA && CONFIG_INTRA_INTERP
#if CONFIG_EXT_TX
extern const aom_tree_index av1_ext_tx_inter_tree[EXT_TX_SETS_INTER]
                                                 [TREE_SIZE(TX_TYPES)];
extern const aom_tree_index av1_ext_tx_intra_tree[EXT_TX_SETS_INTRA]
                                                 [TREE_SIZE(TX_TYPES)];
#else
extern const aom_tree_index av1_ext_tx_tree[TREE_SIZE(TX_TYPES)];
#endif  // CONFIG_EXT_TX
#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
extern const aom_tree_index av1_motion_mode_tree[TREE_SIZE(MOTION_MODES)];
#endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION

#if CONFIG_LOOP_RESTORATION
#define RESTORE_NONE_SGRPROJ_PROB 64
#define RESTORE_NONE_BILATERAL_PROB 16
#define RESTORE_NONE_WIENER_PROB 64
#define RESTORE_NONE_DOMAINTXFMRF_PROB 64
extern const aom_tree_index
    av1_switchable_restore_tree[TREE_SIZE(RESTORE_SWITCHABLE_TYPES)];
#endif  // CONFIG_LOOP_RESTORATION
#if CONFIG_EC_MULTISYMBOL
extern int av1_switchable_interp_ind[SWITCHABLE_FILTERS];
extern int av1_switchable_interp_inv[SWITCHABLE_FILTERS];

void av1_set_mode_cdfs(struct AV1Common *cm);
#endif

void av1_setup_past_independence(struct AV1Common *cm);

void av1_adapt_intra_frame_probs(struct AV1Common *cm);
void av1_adapt_inter_frame_probs(struct AV1Common *cm);
#if CONFIG_EC_MULTISYMBOL && !CONFIG_EXT_TX
extern int av1_ext_tx_ind[TX_TYPES];
extern int av1_ext_tx_inv[TX_TYPES];
#endif

static INLINE int av1_ceil_log2(int n) {
  int i = 1, p = 2;
  while (p < n) {
    i++;
    p = p << 1;
  }
  return i;
}

#if CONFIG_PALETTE
// Returns the context for palette color index at row 'r' and column 'c',
// along with the 'color_order' of neighbors and the 'color_idx'.
// The 'color_map' is a 2D array with the given 'stride'.
int av1_get_palette_color_index_context(const uint8_t *color_map, int stride,
                                        int r, int c, int palette_size,
                                        uint8_t *color_order, int *color_idx);
#endif  // CONFIG_PALETTE

#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // AV1_COMMON_ENTROPYMODE_H_


text:
<!DOCTYPE html>

        <meta charset="utf-8">
        <title>Palladio-based standalone example</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link type="text/css" href="../bower_components/palladio/palladio.css" rel="stylesheet" />
        <link type="text/css" href="css/standalone.css" rel="stylesheet" />

        <link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">

redpajama_set_name: RedPajamaGithub


text:
package cmdparser4j.envelopes;

import cmdparser4j.IntegerType;

public interface IIntegerTypeEnvelope {
	void add(String primaryName, IntegerType type);
	int get(String primaryName, int index, int defaultValue);
}


text:
/*
Personal modifications :
- Added #pragma once
- Qualified XMFLOAT3 with DirectX namespace inside LoadMTL function
*/
#pragma once

//--------------------------------------------------------------------------------------
// File: WaveFrontReader.h
//
// Code for loading basic mesh data from a WaveFront OBJ file
//
// http://en.wikipedia.org/wiki/Wavefront_.obj_file
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkID=324981
//--------------------------------------------------------------------------------------

#include <windows.h>

#include <algorithm>
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>

#pragma warning(push)
#pragma warning(disable : 4005)
#include <stdint.h>
#pragma warning(pop)

#include <directxmath.h>
#include <directxcollision.h>

template<class index_t>
class WaveFrontReader {
public:
	typedef index_t index_t;

	struct Vertex {
		DirectX::XMFLOAT3 position;
		DirectX::XMFLOAT3 normal;
		DirectX::XMFLOAT2 textureCoordinate;
	};

	WaveFrontReader() : hasNormals(false), hasTexcoords(false) {}

	HRESULT Load(_In_z_ const wchar_t* szFileName, bool ccw = true) {
		Clear();

		static const size_t MAX_POLY = 64;

		using namespace DirectX;

		std::wifstream InFile(szFileName);
		if (!InFile)
			return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);

		WCHAR fname[_MAX_FNAME];
		_wsplitpath_s(szFileName, nullptr, 0, nullptr, 0, fname, _MAX_FNAME, nullptr, 0);

		name = fname;

		std::vector<XMFLOAT3>   positions;
		std::vector<XMFLOAT3>   normals;
		std::vector<XMFLOAT2>   texCoords;

		VertexCache  vertexCache;

		Material defmat;

		wcscpy_s(defmat.strName, L"default");
		materials.push_back(defmat);

		uint32_t curSubset = 0;

		WCHAR strCommand[256] = { 0 };
		WCHAR strMaterialFilename[MAX_PATH] = { 0 };
		for (;; ) {
			InFile >> strCommand;
			if (!InFile)
				break;

			if (*strCommand == L'#') {
				// Comment
			} else if (0 == wcscmp(strCommand, L"o")) {
				// Object name ignored
			} else if (0 == wcscmp(strCommand, L"g")) {
				// Group name ignored
			} else if (0 == wcscmp(strCommand, L"s")) {
				// Smoothing group ignored
			} else if (0 == wcscmp(strCommand, L"v")) {
				// Vertex Position
				float x, y, z;
				InFile >> x >> y >> z;
				positions.push_back(XMFLOAT3(x, y, z));
			} else if (0 == wcscmp(strCommand, L"vt")) {
				// Vertex TexCoord
				float u, v;
				InFile >> u >> v;
				texCoords.push_back(XMFLOAT2(u, v));

				hasTexcoords = true;
			} else if (0 == wcscmp(strCommand, L"vn")) {
				// Vertex Normal
				float x, y, z;
				InFile >> x >> y >> z;
				normals.push_back(XMFLOAT3(x, y, z));

				hasNormals = true;
			} else if (0 == wcscmp(strCommand, L"f")) {
				// Face
				UINT iPosition, iTexCoord, iNormal;
				Vertex vertex;

				DWORD faceIndex[MAX_POLY];
				size_t iFace = 0;
				for (;;) {
					if (iFace >= MAX_POLY) {
						// Too many polygon verts for the reader
						return E_FAIL;
					}

					memset(&vertex, 0, sizeof(vertex));

					// OBJ format uses 1-based arrays
					InFile >> iPosition;
					if (iPosition > positions.size())
						return E_FAIL;

					vertex.position = positions[iPosition - 1];

					if ('/' == InFile.peek()) {
						InFile.ignore();

						if ('/' != InFile.peek()) {
							// Optional texture coordinate
							InFile >> iTexCoord;
							if (iTexCoord > texCoords.size())
								return E_FAIL;

							vertex.textureCoordinate = texCoords[iTexCoord - 1];
						}

						if ('/' == InFile.peek()) {
							InFile.ignore();

							// Optional vertex normal
							InFile >> iNormal;
							if (iNormal > normals.size())
								return E_FAIL;

							vertex.normal = normals[iNormal - 1];
						}
					}

					// If a duplicate vertex doesn't exist, add this vertex to the Vertices
					// list. Store the index in the Indices array. The Vertices and Indices
					// lists will eventually become the Vertex Buffer and Index Buffer for
					// the mesh.
					DWORD index = AddVertex(iPosition, &vertex, vertexCache);
					if (index == (DWORD)-1)
						return E_OUTOFMEMORY;

#pragma warning( suppress : 4127 )
					if (sizeof(index_t) == 2 && (index >= 0xFFFF)) {
						// Too many indices for 16-bit IB!
						return E_FAIL;
					} else if (sizeof(index_t) == 4 && (index >= 0xFFFFFFFF)) {
						// Too many indices for 32-bit IB!
						return E_FAIL;
					}

					faceIndex[iFace] = index;
					++iFace;

					// Check for more face data or end of the face statement
					bool faceEnd = false;
					for (;;) {
						wchar_t p = InFile.peek();

						if ('\n' == p || !InFile) {
							faceEnd = true;
							break;
						} else if (isdigit(p))
							break;

						InFile.ignore();
					}

					if (faceEnd)
						break;
				}

				if (iFace < 3) {
					// Need at least 3 points to form a triangle
					return E_FAIL;
				}

				// Convert polygons to triangles
				DWORD i0 = faceIndex[0];
				DWORD i1 = faceIndex[1];

				for (size_t j = 2; j < iFace; ++j) {
					DWORD index = faceIndex[j];
					indices.push_back(static_cast<index_t>(i0));
					if (ccw) {
						indices.push_back(static_cast<index_t>(i1));
						indices.push_back(static_cast<index_t>(index));
					} else {
						indices.push_back(static_cast<index_t>(index));
						indices.push_back(static_cast<index_t>(i1));
					}

					attributes.push_back(curSubset);

					i1 = index;
				}

				assert(attributes.size() * 3 == indices.size());
			} else if (0 == wcscmp(strCommand, L"mtllib")) {
				// Material library
				InFile >> strMaterialFilename;
			} else if (0 == wcscmp(strCommand, L"usemtl")) {
				// Material
				WCHAR strName[MAX_PATH] = { 0 };
				InFile >> strName;

				bool bFound = false;
				uint32_t count = 0;
				for (auto it = materials.cbegin(); it != materials.cend(); ++it, ++count) {
					if (0 == wcscmp(it->strName, strName)) {
						bFound = true;
						curSubset = count;
						break;
					}
				}

				if (!bFound) {
					Material mat;
					curSubset = static_cast<uint32_t>(materials.size());
					wcscpy_s(mat.strName, MAX_PATH - 1, strName);
					materials.push_back(mat);
				}
			} else {
#ifdef _DEBUG
				// Unimplemented or unrecognized command
				OutputDebugStringW(strCommand);
#endif
			}

			InFile.ignore(1000, '\n');
		}

		// Cleanup
		InFile.close();

		BoundingBox::CreateFromPoints(bounds, positions.size(), &positions.front(), sizeof(XMFLOAT3));

		// If an associated material file was found, read that in as well.
		if (*strMaterialFilename) {
			WCHAR ext[_MAX_EXT];
			_wsplitpath_s(strMaterialFilename, nullptr, 0, nullptr, 0, fname, _MAX_FNAME, ext, _MAX_EXT);

			WCHAR drive[_MAX_DRIVE];
			WCHAR dir[_MAX_DIR];
			_wsplitpath_s(szFileName, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);

			WCHAR szPath[MAX_PATH];
			_wmakepath_s(szPath, MAX_PATH, drive, dir, fname, ext);

			HRESULT hr = LoadMTL(szPath);
			if (FAILED(hr))
				return hr;
		}

		return S_OK;
	}

	HRESULT LoadMTL(_In_z_ const wchar_t* szFileName) {
		// Assumes MTL is in CWD along with OBJ
		std::wifstream InFile(szFileName);
		if (!InFile)
			return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);

		auto curMaterial = materials.end();

		WCHAR strCommand[256] = { 0 };
		for (;; ) {
			InFile >> strCommand;
			if (!InFile)
				break;

			if (0 == wcscmp(strCommand, L"newmtl")) {
				// Switching active materials
				WCHAR strName[MAX_PATH] = { 0 };
				InFile >> strName;

				curMaterial = materials.end();
				for (auto it = materials.begin(); it != materials.end(); ++it) {
					if (0 == wcscmp(it->strName, strName)) {
						curMaterial = it;
						break;
					}
				}
			}

			// The rest of the commands rely on an active material
			if (curMaterial == materials.end())
				continue;

			if (0 == wcscmp(strCommand, L"#")) {
				// Comment
			} else if (0 == wcscmp(strCommand, L"Ka")) {
				// Ambient color
				float r, g, b;
				InFile >> r >> g >> b;
				curMaterial->vAmbient = DirectX::XMFLOAT3(r, g, b);
			} else if (0 == wcscmp(strCommand, L"Kd")) {
				// Diffuse color
				float r, g, b;
				InFile >> r >> g >> b;
				curMaterial->vDiffuse = DirectX::XMFLOAT3(r, g, b);
			} else if (0 == wcscmp(strCommand, L"Ks")) {
				// Specular color
				float r, g, b;
				InFile >> r >> g >> b;
				curMaterial->vSpecular = DirectX::XMFLOAT3(r, g, b);
			} else if (0 == wcscmp(strCommand, L"d") ||
					  0 == wcscmp(strCommand, L"Tr")) {
				// Alpha
				InFile >> curMaterial->fAlpha;
			} else if (0 == wcscmp(strCommand, L"Ns")) {
				// Shininess
				int nShininess;
				InFile >> nShininess;
				curMaterial->nShininess = nShininess;
			} else if (0 == wcscmp(strCommand, L"illum")) {
				// Specular on/off
				int illumination;
				InFile >> illumination;
				curMaterial->bSpecular = (illumination == 2);
			} else if (0 == wcscmp(strCommand, L"map_Kd")) {
				// Texture
				InFile >> curMaterial->strTexture;
			} else {
				// Unimplemented or unrecognized command
			}

			InFile.ignore(1000, L'\n');
		}

		InFile.close();

		return S_OK;
	}

	void Clear() {
		vertices.clear();
		indices.clear();
		attributes.clear();
		materials.clear();
		name.clear();
		hasNormals = false;
		hasTexcoords = false;

		bounds.Center.x = bounds.Center.y = bounds.Center.z = 0.f;
		bounds.Extents.x = bounds.Extents.y = bounds.Extents.z = 0.f;
	}

	HRESULT LoadVBO(_In_z_ const wchar_t* szFileName) {
		Clear();

		WCHAR fname[_MAX_FNAME];
		_wsplitpath_s(szFileName, nullptr, 0, nullptr, 0, fname, _MAX_FNAME, nullptr, 0);

		name = fname;

		Material defmat;
		wcscpy_s(defmat.strName, L"default");
		materials.push_back(defmat);

		std::ifstream vboFile(szFileName, std::ifstream::in | std::ifstream::binary);
		if (!vboFile.is_open())
			return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);

		hasNormals = hasTexcoords = true;

		uint32_t numVertices = 0;
		uint32_t numIndices = 0;

		vboFile.read(reinterpret_cast<char*>(&numVertices), sizeof(uint32_t));
		if (!numVertices)
			return E_FAIL;

		vboFile.read(reinterpret_cast<char*>(&numIndices), sizeof(uint32_t));
		if (!numIndices)
			return E_FAIL;

		vertices.resize(numVertices);
		vboFile.read(reinterpret_cast<char*>(&vertices.front()), sizeof(Vertex) * numVertices);

#pragma warning( suppress : 4127 )
		if (sizeof(index_t) == 2) {
			indices.resize(numIndices);
			vboFile.read(reinterpret_cast<char*>(&indices.front()), sizeof(uint16_t) * numIndices);
		} else {
			std::vector<uint16_t> tmp;
			tmp.resize(numIndices);
			vboFile.read(reinterpret_cast<char*>(&tmp.front()), sizeof(uint16_t) * numIndices);

			indices.reserve(numIndices);
			for (auto it = tmp.cbegin(); it != tmp.cend(); ++it) {
				indices.push_back(*it);
			}
		}

		BoundingBox::CreateFromPoints(bounds, vertices.size(), reinterpret_cast<const XMFLOAT3*>(&vertices.front()), sizeof(Vertex));

		vboFile.close();

		return S_OK;
	}

	struct Material {
		DirectX::XMFLOAT3 vAmbient;
		DirectX::XMFLOAT3 vDiffuse;
		DirectX::XMFLOAT3 vSpecular;
		uint32_t nShininess;
		float fAlpha;

		bool bSpecular;

		WCHAR   strName[MAX_PATH];
		WCHAR   strTexture[MAX_PATH];

		Material() :
			vAmbient(0.2f, 0.2f, 0.2f),
			vDiffuse(0.8f, 0.8f, 0.8f),
			vSpecular(1.0f, 1.0f, 1.0f),
			nShininess(0),
			fAlpha(1.f),
			bSpecular(false) {
			memset(strName, 0, MAX_PATH); memset(strTexture, 0, MAX_PATH);
		}
	};

	std::vector<Vertex>     vertices;
	std::vector<index_t>    indices;
	std::vector<uint32_t>   attributes;
	std::vector<Material>   materials;

	std::wstring            name;
	bool                    hasNormals;
	bool                    hasTexcoords;

	DirectX::BoundingBox    bounds;

private:
	typedef std::unordered_multimap<UINT, UINT> VertexCache;

	DWORD AddVertex(UINT hash, Vertex* pVertex, VertexCache& cache) {
		auto f = cache.equal_range(hash);

		for (auto it = f.first; it != f.second; ++it) {
			auto& tv = vertices[it->second];

			if (0 == memcmp(pVertex, &tv, sizeof(Vertex))) {
				return it->second;
			}
		}

		DWORD index = static_cast<UINT>(vertices.size());
		vertices.push_back(*pVertex);

		VertexCache::value_type entry(hash, index);
		cache.insert(entry);
		return index;
	}
};


text:
<!DOCTYPE HTML>
<html>
<head>
    <title>TTY</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1, IE=9">
    <script src="../lib/phaser.min.js"></script>
    <script src="plugin/TTY.js"></script>
    <style type="text/css">
        html, body {
            margin: 0;
        }
    </style>
</head>
<body>

    <script type="text/javascript">

    var PhaserExample = function () {

        this.tty = null;

    };

    PhaserExample.prototype = {

        preload: function () {

            this.load.spritesheet('ttyFont', 'plugin/font_cpc.png', 16, 18);

        },

        create: function () {

            this.stage.backgroundColor = '#0055aa';

            this.tty = new TTY(this.game, 40, 28, 'ttyFont');

            this.tty.print("Welcome to Phaser.TTY v1.0");

        },

        render: function () {

            //  This could probably move to a TTY bottom-line thing?
            this.game.debug.text("col (x): " + this.tty.col, 32, 550);
            this.game.debug.text("row (y): " + this.tty.row, 200, 550);
            this.game.debug.text("height: " + this.tty.height, 400, 550);

        }

    };

    var game = new Phaser.Game("100%", "100%", Phaser.CANVAS, null, PhaserExample);

    </script>

</body>
</html>


text:
<?php

namespace Lmi\Bundle\SchoolBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class LmiSchoolBundle extends Bundle
{
}


text:
package de.slackspace.openkeepass.crypto;

import de.slackspace.openkeepass.domain.KeePassHeader;
import de.slackspace.openkeepass.util.StreamUtils;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Decrypter {

	public byte[] decryptDatabase(byte[] password, KeePassHeader header, byte[] database) throws IOException {
		byte[] aesKey = createAesKey(password, header);

		return processDatabaseEncryption(false, database, header, aesKey);
	}

	public byte[] encryptDatabase(byte[] password, KeePassHeader header, byte[] database) throws IOException {
		byte[] aesKey = createAesKey(password, header);

		return processDatabaseEncryption(true, database, header, aesKey);
	}

	private byte[] processDatabaseEncryption(boolean encrypt, byte[] database, KeePassHeader header, byte[] aesKey) throws IOException {
		byte[] metaData = new byte[KeePassHeader.VERSION_SIGNATURE_LENGTH + header.getHeaderSize()];
		BufferedInputStream bufferedInputStream = new BufferedInputStream(new ByteArrayInputStream(database));
		bufferedInputStream.read(metaData);

		byte[] payload = StreamUtils.toByteArray(bufferedInputStream);
		byte[] processedPayload;
		if(encrypt) {
			processedPayload = Aes.encrypt(aesKey, header.getEncryptionIV(), payload);
		}
		else {
			processedPayload = Aes.decrypt(aesKey, header.getEncryptionIV(), payload);
		}

		ByteArrayOutputStream output = new ByteArrayOutputStream();
		output.write(metaData);
		output.write(processedPayload);

		return output.toByteArray();
	}

	private byte[] createAesKey(byte[] password, KeePassHeader header) {
		byte[] hashedPwd = Sha256.hash(password);

		byte[] transformedPwd = Aes.transformKey(header.getTransformSeed(), hashedPwd, header.getTransformRounds());
		byte[] transformedHashedPwd = Sha256.hash(transformedPwd);

		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		stream.write(header.getMasterSeed(), 0, 32);
		stream.write(transformedHashedPwd, 0, 32);

		return Sha256.hash(stream.toByteArray());
	}
}


text:
To connect spark-shell with drivers to read from S3 you need to do:
```
spark-shell
```

Download data and load it into S3:
```
#Create a bucket in S3
s3cmd mb s3://files

#Download sonnets.txt files
wget http://www.gutenberg.org/cache/epub/1041/pg1041.txt -o sonnets.txt

#Upload the sonnets.txt to S3 storage
s3cmd put sonnets.txt s3://files/
```


text:
// Copyright (c) 2014, 임경현 (dlarudgus20)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
//   list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "timer.h"
#include "port.h"
#include "idt.h"
#include "gdt.h"
#include "interrupt.h"
#include "pic.h"
#include "terminal.h"
#include "task.h"
#include "memory_map.h"
#include "string.h"
#include "assert.h"

TimerStruct g_TimerStruct = { 0 };

static TimeOut s_SentinalTimeOut = {
	.timeout = 0xffffffff,
	.NoticeQueue = NULL,
	.pNextTimeOut = &s_SentinalTimeOut
};

static void ckTimerReinitialize(void);
static void ckTimerInit_internal(uint16_t count, bool periodic);

static void ckWaitThroughPITCounter(uint16_t count);
static uint16_t ckTimerReadPITCounter(void);

void ckTimerInitialize(void)
{
	g_TimerStruct.pTimeOutHead = &s_SentinalTimeOut;

	ckTimerReinitialize();

	ckIdtInit(g_pIdtTable + PIC_INTERRUPT_TIMER, ckTimerIntHandler, KERNEL_CODE_SEGMENT, 0);
}
static void ckTimerReinitialize(void)
{
	ckTimerInit_internal(PIT_FREQUENCY / TIMER_FREQUENCY, true);
}

static void ckTimerInit_internal(uint16_t count, bool periodic)
{
	ckPortOutByte(PIT_CONTROL_PORT,
		periodic ? PIT_CONTROL_COUNTER0_PERIODIC : PIT_CONTROL_COUNTER0_ONCE);

	ckPortOutByte(PIT_COUNTER0_PORT, (uint8_t)count);
	ckPortOutByte(PIT_COUNTER0_PORT, (uint8_t)(count >> 8));
}

bool ckTimerSet(TimeOut *pTimeOut)
{
	if (pTimeOut->NoticeQueue == NULL)
		return false;

	INTERRUPT_LOCK();

	uint32_t tick = g_TimerStruct.TickCountLow;

	s_SentinalTimeOut.timeout = tick + 0xffffffff;

	TimeOut *before = (TimeOut *)&g_TimerStruct.pTimeOutHead;
	TimeOut *node = before->pNextTimeOut;
	while (1)
	{
		if ((pTimeOut->timeout - tick) <= (node->timeout - tick))
		{
			before->pNextTimeOut = pTimeOut;
			pTimeOut->pNextTimeOut = node;
			break;
		}
		else
		{
			before = node;
			node = node->pNextTimeOut;
		}
	}

	INTERRUPT_UNLOCK();

	return true;
}

void ck_TimerIntHandler(InterruptContext *pContext)
{
	ckPicSendEOI(PIC_IRQ_TIMER);

	// tick count
	uint32_t low = ++g_TimerStruct.TickCountLow;
	if (low == 0)
		g_TimerStruct.TickCountHigh++;

	// TimeOut
	TimeOut *pTimeOut = g_TimerStruct.pTimeOutHead;
	while (1)
	{
		if (pTimeOut->timeout == low)
		{
			g_TimerStruct.pTimeOutHead = pTimeOut->pNextTimeOut;

			if (pTimeOut->NoticeQueue != NULL)
			{
				ckLinkedListPushBack_lockfree(pTimeOut->NoticeQueue, &pTimeOut->NoticeNode);
			}
			else // sentinal
			{
				pTimeOut->timeout += 0xffffffff;
			}

			pTimeOut = pTimeOut->pNextTimeOut;
		}
		else
		{
			break;
		}
	}

	// 태스크 스케쥴링
	ckTaskScheduleOnTimerInt();
}

//TimeOut *ckTimerAllocTimeOut(uint32_t timeout, uint32_t code, LinkedList *NoticeQueue)
//{
//
//}

#define MS_TO_COUNT(ms) (PIT_FREQUENCY * (ms) / 1000)
void ckTimerBusyDirectWait_ms(uint32_t milli)
{
	INTERRUPT_LOCK();

	while (milli > 30)		// 30ms 단위로 쉼.
	{
		ckWaitThroughPITCounter(MS_TO_COUNT(30));
		milli -= 30;
	}
	ckWaitThroughPITCounter(MS_TO_COUNT(milli));

	ckTimerReinitialize();

	INTERRUPT_UNLOCK();
}

static void ckWaitThroughPITCounter(uint16_t count)
{
	ckTimerInit_internal(0xffff, false);

	uint16_t prev = ckTimerReadPITCounter();

	while (((prev - ckTimerReadPITCounter()) & 0xffff) < count)
	{
		// busy waiting...
	}
}

static uint16_t ckTimerReadPITCounter(void)
{
	ckPortOutByte(PIT_CONTROL_PORT, PIT_CONTROL_COUNTER0 | PIT_CONTROL_LATCH);
	uint8_t low = ckPortInByte(PIT_COUNTER0_PORT);
	uint8_t high = ckPortInByte(PIT_COUNTER0_PORT);

	return (high << 8) | low;
}


text:
package tsunagi.example.processModel.node.helloworld;

import java.util.ArrayList;

import tsunagi.core.domain.MetaTaskAssigned;
import tsunagi.core.info.InitialInfo;
import tsunagi.core.info.PageInfo;
import tsunagi.core.info.TaskInfo;
import tsunagi.core.node.NodeUserInputTask;
import tsunagi.core.security.UserManager;
import tsunagi.core.type.Priority;
import tsunagi.core.type.TaskType;
import tsunagi.web.DynamicDomain;

public class NodeHelloWorldReview2 extends NodeUserInputTask {

	public NodeHelloWorldReview2() {
		this.setName("HelloWorldReview2");
		this.setTaskTitle("Review Hello World with Response");
		this.setPriority(Priority.MEDIUM);
		this.setTaskType(TaskType.MO);
		this.setDescription("Hello World Review with Response User Input Task Node");
	}

	@Override
	protected ArrayList<MetaTaskAssigned> buildAssignment(InitialInfo initInfo) {
		DynamicDomain domain = (DynamicDomain)initInfo.getDomain();
		return UserManager.INSTANCE.getUserProcessor().getMetaTaskAssigned(domain.getValue("reviewer"));
	}

	@Override
	protected void setPageInfoForOpenTask(PageInfo pageInfo) {
		pageInfo.setPageName("helloWorldReview2.jsp");
	}

	@Override
	protected boolean validate(TaskInfo taskInfo) {
		return true;
	}

	@Override
	protected void setPageInfoForProcessTask(PageInfo pageInfo) {
		pageInfo.setPageName("index.jsp");
	}

}


text:
#include <proxemics_anytimerrts/state_discretizer.h>

namespace proxemics_anytimerrts
{

StateDiscretizer::StateDiscretizer(DynamicCostmap *costmap,
                                   MotionConstraints motion_constraints) :
  costmap_(costmap),
  time_resolution_(costmap->getTimeResolution().toSec()),
  motion_constraints_(motion_constraints)
{
  double nx = costmap->getStaticROSCostmap()->getCostmap()->getSizeInCellsX();
  double ny = costmap->getStaticROSCostmap()->getCostmap()->getSizeInCellsY();
  num_gridcells_ = nx * ny;

  //calculate number of discrete angles for dynamic settings
  num_orientations_ = getNumDiscreteAngles(motion_constraints.acc_phi,
                                           time_resolution_);

  //calculate number of discrete forward velocities
  num_vel_x_ = 0;
  for(double vel = motion_constraints.min_vel_x;
      vel <= motion_constraints.max_vel_x;
      vel += motion_constraints.acc_x * time_resolution_)
    num_vel_x_ ++;

  //calculate number of discrete rotational velocities
  num_vel_phi_ = 0;
  for(double vel = motion_constraints.min_vel_phi;
      vel <= motion_constraints.max_vel_phi;
      vel += motion_constraints.acc_phi * time_resolution_)
    num_vel_phi_ ++;

  vel_step_x_ = motion_constraints_.acc_x * time_resolution_;
  vel_step_phi_ = motion_constraints_.acc_phi * time_resolution_;
}

int StateDiscretizer::getNumDiscreteAngles(double acc_w, double time_delta)
{
  //calculate the number of orientations that should be represented.
  //needs to be able to jump from one discrete angle to the other at minimum
  //turning speed. otherwise it will expand states that are already there
  //and therefore never be able to turn in place
  int max_angle = (int) ((4 * M_PI) / (acc_w * time_delta) + 1);
  int num_angles = max_angle + 1; //need to be able to represent max_angles + zero
  ROS_INFO("discretizing to %d angles", num_angles);

  return num_angles;
}

DiscreteState StateDiscretizer::discretizeState(Pose pose, Velocity vel, int time_step)
{
  DiscreteState state_i;

  //find cell position
  state_i.in_map = getCellPosition(pose.getX(), pose.getY(), state_i.x_i,
                                   state_i.y_i, state_i.grid_cell);

  //find the nearest discrete orientation
  state_i.angle_i = getDiscreteOrientation(pose.getTheta());

  //find the discrete representation of the velocity
  getDiscreteVelocity(vel, state_i.vel_x_i, state_i.vel_w_i);

  state_i.time_step = time_step;

  return state_i;
}

bool StateDiscretizer::getCellPosition(double x, double y, unsigned int &x_i,
                                       unsigned int &y_i, unsigned int &index)
{
  //find the corresponding grid cell and x y coordinate
  if(costmap_->getStaticROSCostmap()->getCostmap()->worldToMap(x, y, x_i, y_i))
  {
    index = costmap_->getStaticROSCostmap()->getCostmap()->getIndex(x_i, y_i);
    return true;
  }

  else
    return false;
}

unsigned int StateDiscretizer::getDiscreteOrientation(double angle)
{
  if(angle < 0 || angle > 2 * M_PI)
  {
    ROS_ERROR("angle has to be between 0 and 2_PI for calculating the nearest "
              "discrete angle");
    return 0;
  }

  //get next discrete angle
  unsigned int orientation = angle / (2 * M_PI / (num_orientations_-1)) + 0.5;

  if(orientation == num_orientations_)
    orientation = 0;

  return orientation;
}

void StateDiscretizer::getDiscreteVelocity(Velocity vel, unsigned int &vel_x_i,
                                           unsigned int &vel_w_i)
{
  vel_x_i = int ((vel.vel_x / vel_step_x_) -
                 (motion_constraints_.min_vel_x / vel_step_x_) + 0.5);
  vel_w_i = int ((vel.vel_phi / vel_step_phi_) -
                 (motion_constraints_.min_vel_phi / vel_step_phi_) + 0.5);
}

void StateDiscretizer::getLimits(int &num_gridcells, int &num_orientations,
                                 int & num_vels_x, int &num_vels_w)
{
  num_gridcells = num_gridcells_;
  num_orientations = num_orientations_;
  num_vels_x = num_vel_x_;
  num_vels_w = num_vel_phi_;
}

Velocity StateDiscretizer::getVelocity(unsigned int vel_x_i, unsigned int vel_w_i)
{
  return Velocity(vel_x_i * vel_step_x_, vel_w_i * vel_step_phi_);
}

} //namespace lattice_planner


text:
- Multipurpose language
    - Scripting
    - Object Oriented Programming
- 2.x vs 3.x
- Capabilities
    - Django
    - Dropbox
    - YouTube
    - Dropbox
    - EventBrite
- _NOT_ ArcObjects
    - ArcObjects is the term for the Software Development Kit (SDK)
        - .NET SDK
        - Java SDK
    - Provides access to the geoprocessing capabilities of ArcGIS at
      a programatic level

## Python and ArcGIS

- Evolution from VBA
- ArcObjects, .NET SDK vs Python
- Future of Python with ArcGIS

## Examples

- Python script in toolbox
    - AddressErrors
    - Huff Model
- Interpreter
    - ArcGIS
    - IDLE
- Text editor
    - Notepad++
    - IDLE
- IDE
    - [PythonWin](http://sourceforge.net/projects/pywin32/)
    - [PyScripter](https://code.google.com/p/pyscripter/)
- Python Anywhere
    - [pythonanywhere.com](https://www.pythonanywhere.com/)
    - Online python interperter
    - Hosting
    - Tutorials
    - Free beginner account


text:
Handlebars.registerHelper('convert', function (input) {
  return MK.app.getHtmlContent(input).substr(0, 1000);
});

Handlebars.registerHelper('docLink', function () {
  var opts = {ns: this.ns, docUri: this.uri};
  return (Meteor.userId() === this.owner) ? Meteor.editPath(opts) : Meteor.docPath(opts);
});

Handlebars.registerHelper('nsLink', function () {
  return Meteor.nsPath({ns: this._id});
});

Handlebars.registerHelper('highlightKeyword', function (text) {
  return Session.get('search') ? MK.app.highlightSearchKeyword(text, Session.get('search')) : text;
});

Handlebars.registerHelper('activeBox', function (id) {
  return (id === Session.get('docId')) ? 'active' : 'inactive';
});

Handlebars.registerHelper('pageTemplateIn', function (/* arguments */) {
  //	Transform handlebar object into array, discarding the last element
  var args = Array.prototype.slice.call(arguments, 0, -1);
  return args.indexOf(Meteor.router.template()) > -1;
});

Handlebars.registerHelper('showContent', function () {
  return (Session.get('loading')) ? 'hide' : '';
});


text:
import datetime
import unittest

from apel.db.loader import CarParser
from apel.db.loader.xml_parser import XMLParserException

def datetimes_equal(dt1, dt2):
    """Compare if datetimes are equal to the nearest second."""
    diff = dt1 - dt2
    return abs(diff) < datetime.timedelta(seconds=1)

class CarParserTest(unittest.TestCase):
    """Test case for Car Parser"""

    def setUp(self):
        pass
        #self.parser = CarParser(self.example_data)

    def test_car_parser(self):
        # Careful! I added a Z to the end of the dates here but they weren't there in the CAR spec...
        car1 = '''<?xml version="1.0" encoding="UTF-8"?>
<urf:UsageRecord xmlns:urf="http://eu-emi.eu/namespaces/2012/11/computerecord" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://eu-emi.eu/namespaces/2012/11/computerecord ../../../org.glite.dgas_B_4_0_0/config-consumers/car_v1.2.xsd ">
  <urf:RecordIdentity urf:createTime="2001-12-31T12:00:00Z" urf:recordId="token"/>
  <urf:JobIdentity>
    <urf:LocalJobId>urf:LocalJobId</urf:LocalJobId>
  </urf:JobIdentity>
  <urf:UserIdentity>
    <urf:LocalUserId>urf:LocalUserId</urf:LocalUserId>
  </urf:UserIdentity>
  <urf:Status>aborted</urf:Status>
  <urf:Infrastructure/>
  <urf:WallDuration>P1D</urf:WallDuration>
  <urf:CpuDuration>P1D</urf:CpuDuration>
  <urf:ServiceLevel urf:type="token">0.0</urf:ServiceLevel>
  <urf:EndTime>2001-12-31T12:00:00Z</urf:EndTime>
  <urf:StartTime>2001-12-31T12:00:00Z</urf:StartTime>
  <urf:MachineName>MachineName</urf:MachineName>
  <urf:Queue>urf:Queue</urf:Queue>
  <urf:Site>urf:Site</urf:Site>
</urf:UsageRecord>
'''

        values1 = {'Site': 'urf:Site',
                   'MachineName': 'MachineName',
                   'LocalJobId': 'urf:LocalJobId',
                   'LocalUserId': 'urf:LocalUserId',
                   'WallDuration': 86400,
                   'CpuDuration': 86400,
                   'StartTime': datetime.datetime(2001, 12, 31, 12, 00, 00),
                   'EndTime': datetime.datetime(2001, 12, 31, 12, 00, 00),
                   }

        car2 = '''<?xml version="1.0"?>
<UsageRecords xmlns="http://eu-emi.eu/namespaces/2012/11/computerecord">
  <UsageRecord xmlns:urf="http://eu-emi.eu/namespaces/2012/11/computerecord" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RecordIdentity urf:createTime="2013-02-09T15:39:16Z" urf:recordId="ur-pgs03-T1eKDmSEROhnyOkhppswXjgoABFKDmABFKDmzQNKDmABFKDm4BxvIn"/>
  <JobIdentity>
    <GlobalJobId>gsiftp://pgs03.grid.upjs.sk:2811/jobs/T1eKDmSEROhnyOkhppswXjgoABFKDmABFKDmzQNKDmABFKDm4BxvIn</GlobalJobId>
    <LocalJobId>jobid10</LocalJobId>
    </JobIdentity>
    <UserIdentity>
      <GlobalUserName urf:type="opensslCompat">/DC=eu/DC=KnowARC/O=nagios/CN=demo1</GlobalUserName>
      <LocalUserId>gridtest</LocalUserId>
    </UserIdentity>
    <Status>completed</Status>
    <ExitStatus>0</ExitStatus>
    <Infrastructure urf:description="pbs" urf:type="grid"/>
    <Middleware urf:name="arc" urf:version="3.0.0rc5" urf:description="nordugrid-arc 3.0.0rc5"></Middleware>
    <WallDuration>PT4S</WallDuration>
    <CpuDuration urf:usageType="user">PT1S</CpuDuration>
    <CpuDuration urf:usageType="system">PT2S</CpuDuration>
    <CpuDuration urf:usageType="all">PT3S</CpuDuration>
    <Memory urf:type="Shared" urf:metric="average" urf:storageUnit="KB">9404</Memory>
    <Memory urf:type="Physical" urf:metric="max" urf:storageUnit="KB">2368</Memory>
    <ServiceLevel urf:type="Si2K" urf:description="">1.0</ServiceLevel>
    <NodeCount>2</NodeCount>
    <EndTime>2013-02-09T15:11:41Z</EndTime>
    <StartTime>2013-02-09T15:09:16Z</StartTime>
    <MachineName>pgs03.grid.upjs.sk</MachineName>
    <SubmitHost>gsiftp://pgs03.grid.upjs.sk:2811/jobs</SubmitHost>
    <Queue urf:description="execution">gridlong</Queue>
    <Site urf:type="arc">PGS03-GRID-UPJS-SK</Site>
    <Host urf:primary="true">pgs03</Host>
    <Host>pgs03.grid.upjs.sk</Host></UsageRecord>
</UsageRecords>'''

        values2 = {"Site": "PGS03-GRID-UPJS-SK",
                   "MachineName": "pgs03.grid.upjs.sk",
                   "LocalJobId": "jobid10",
                   "LocalUserId": "gridtest",
                   "WallDuration": 4,
                   "CpuDuration": 3,
                   "ServiceLevelType": "Si2K",
                   "ServiceLevel": 1,
                   "NodeCount": 2,
                   "StartTime": datetime.datetime(2013, 2, 9, 15, 9, 16),
                   "EndTime": datetime.datetime(2013, 2, 9, 15, 11, 41),
                   "SubmitHost": "gsiftp://pgs03.grid.upjs.sk:2811/jobs",
                   "Queue": "gridlong"
                   }

        car3 = '''<com:UsageRecord xmlns:com="http://eu-emi.eu/namespaces/2012/11/computerecord">
        <com:RecordIdentity com:recordId="62991a08-909b-4516-aa30-3732ab3d8998" com:createTime="2013-02-22T15:58:44.567+01:00"/>
        <com:JobIdentity>
          <com:GlobalJobId>ac2b1157-7aff-42d9-945e-389aa9bbb19a</com:GlobalJobId>
          <com:LocalJobId>7005</com:LocalJobId>
        </com:JobIdentity>
        <com:UserIdentity>
          <com:GlobalUserName com:type="rfc2253">CN=Bjoern Hagemeier,OU=Forschungszentrum Juelich GmbH,O=GridGermany,C=DE</com:GlobalUserName>
          <com:LocalUserId>bjoernh</com:LocalUserId>
          <com:LocalGroup>users</com:LocalGroup>
        </com:UserIdentity>
        <com:JobName>HiLA</com:JobName>
        <com:Status>completed</com:Status>
        <com:ExitStatus>0</com:ExitStatus>
        <com:Infrastructure com:type="grid"/>
        <com:Middleware com:name="unicore">unicore</com:Middleware>
        <com:WallDuration>PT0S</com:WallDuration>
        <com:CpuDuration>PT0S</com:CpuDuration>
        <com:ServiceLevel com:type="HEPSPEC">1.0</com:ServiceLevel>
        <com:Memory com:metric="total" com:storageUnit="KB" com:type="physical">0</com:Memory>
        <com:Memory com:metric="total" com:storageUnit="KB" com:type="shared">0</com:Memory>
        <com:TimeInstant com:type="uxToBssSubmitTime">2013-02-22T15:58:44.568+01:00</com:TimeInstant>
        <com:TimeInstant com:type="uxStartTime">2013-02-22T15:58:46.563+01:00</com:TimeInstant>
        <com:TimeInstant com:type="uxEndTime">2013-02-22T15:58:49.978+01:00</com:TimeInstant>
        <com:TimeInstant com:type="etime">2013-02-22T15:58:44+01:00</com:TimeInstant>
        <com:TimeInstant com:type="ctime">2013-02-22T15:58:44+01:00</com:TimeInstant>
        <com:TimeInstant com:type="qtime">2013-02-22T15:58:44+01:00</com:TimeInstant>
        <com:TimeInstant com:type="maxWalltime">2013-02-22T16:58:45+01:00</com:TimeInstant>
        <com:NodeCount>1</com:NodeCount>
        <com:Processors>2</com:Processors>
        <com:EndTime>2013-02-22T15:58:45+01:00</com:EndTime>
        <com:StartTime>2013-02-22T15:58:45+01:00</com:StartTime>
        <com:MachineName>zam052v15.zam.kfa-juelich.de</com:MachineName>
        <com:SubmitHost>zam052v02</com:SubmitHost>
        <com:Queue com:description="execution">batch</com:Queue>
        <com:Site>zam052v15.zam.kfa-juelich.de</com:Site>
        <com:Host com:primary="false" com:description="CPUS=2;SLOTS=1,0">zam052v15</com:Host>
        </com:UsageRecord>'''

        values3 = {"LocalJobId": "7005",
                   "GlobalUserName": "CN=Bjoern Hagemeier,OU=Forschungszentrum Juelich GmbH,O=GridGermany,C=DE",
                   "LocalUserId": "bjoernh",
                   "InfrastructureType": "grid",
                   'WallDuration': 0,
                   'CpuDuration': 0,
                   'ServiceLevelType': 'HEPSPEC',
                   'ServiceLevel': 1,
                   'NodeCount': 1,
                   'Processors': 2,
                   'StartTime': datetime.datetime(2013, 2, 22, 14, 58, 45),
                   'EndTime': datetime.datetime(2013, 2, 22, 14, 58, 45),
                   'MachineName': 'zam052v15.zam.kfa-juelich.de',
                   'SubmitHost': 'zam052v02',
                   'Queue': 'batch',
                   'Site': 'zam052v15.zam.kfa-juelich.de'
                   }

        cases = {}
        cases[car1] = values1
        cases[car2] = values2
        cases[car3] = values3

        for car in cases:

            parser = CarParser(car)
            record = parser.get_records()[0]
            cont = record._record_content

            #  Mandatory fields - need checking.
            self.assertTrue('Site' in cont)
            self.assertTrue('Queue' in cont)
            self.assertTrue('LocalJobId' in cont)
            self.assertTrue('WallDuration' in cont)
            self.assertTrue('CpuDuration' in cont)
            self.assertTrue('StartTime' in cont)
            self.assertTrue('EndTime' in cont)

            for key in cases[car].keys():
                if isinstance(cont[key], datetime.datetime):
                    if not datetimes_equal(cont[key], cases[car][key]):
                        self.fail("Datetimes don't match for key %s: %s, %s" % (key, cont[key], cases[car][key]))
                else:
                    self.assertEqual(cont[key], cases[car][key], '%s != %s for key %s' % (cont[key], cases[car][key], key))

    def test_empty_xml(self):
        """
        Check that exception is raised for XML not in computerecord namepsace.
        """
        parser = CarParser("<something></something>")
        self.assertRaises(XMLParserException, parser.get_records)

    #def test_empty_record(self):
    #    # Not sure what should be returned with an empty record like this.
    #    parser = CarParser('<urf:UsageRecord xmlns:urf="http://eu-emi.eu/namesp'
    #                       'aces/2012/11/computerecord"></urf:UsageRecord>')
    #    print parser.get_records()[0]._record_content

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


text:
/****************************************************************************
 * libc/stdio/lib_avsprintf.c
 *
 *   Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
 *   Author: Gregory Nutt <gnutt@nuttx.org>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 * 3. Neither the name NuttX nor the names of its contributors may be
 *    used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 ****************************************************************************/

/****************************************************************************
 * Included Files
 ****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <assert.h>

#include "lib_internal.h"

/****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/
/* On some architectures, va_list is really a pointer to a structure on the
 * stack.  And the va_arg builtin will modify that instance of va_list.  Since
 * avsprintf traverse the parameters in the va_list twice, the va_list will
 * be altered in this first cases and the second usage will fail.  So far, I
 * have seen this only on the X86 family with GCC.
 */

#undef CLONE_APLIST
#define ap1 ap
#define ap2 ap

#if defined(CONFIG_ARCH_X86)
#define CLONE_APLIST 1
#undef ap2
#elif defined(CONFIG_ARCH_SIM) && (defined(CONFIG_HOST_X86) || defined(CONFIG_HOST_X86_64))
#define CLONE_APLIST 1
#undef ap2
#endif

/****************************************************************************
 * Private Type Declarations
 ****************************************************************************/

/****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/****************************************************************************
 * Global Constant Data
 ****************************************************************************/

/****************************************************************************
 * Global Variables
 ****************************************************************************/

/****************************************************************************
 * Private Constant Data
 ****************************************************************************/

/****************************************************************************
 * Private Variables
 ****************************************************************************/

/****************************************************************************
 * Global Functions
 ****************************************************************************/

/****************************************************************************
 * Name: avsprintf
 *
 * Description:
 *   This function is similar to vsprintf, except that it dynamically
 *   allocates a string (as with malloc) to hold the output, instead of
 *   putting the output in a buffer you allocate in advance.  The ptr
 *   argument should be the address of a char * object, and a successful
 *   call to avsprintf stores a pointer to the newly allocated string at that
 *   location.
 *
 * Returned Value:
 *   The returned value is the number of characters allocated for the buffer,
 *   or less than zero if an error occurred. Usually this means that the buffer
 *   could not be allocated.
 *
 ****************************************************************************/

int avsprintf(FAR char **ptr, const char *fmt, va_list ap)
{
	struct lib_outstream_s nulloutstream;
	struct lib_memoutstream_s memoutstream;
#ifdef CLONE_APLIST
	va_list ap2;
#endif
	FAR char *buf;
	int nbytes;

	DEBUGASSERT(ptr && fmt);

#ifdef CLONE_APLIST
	/* Clone the va_list so that the contents of the input values are not altered */

	va_copy(ap2, ap);
#endif

	/* First, use a nullstream to get the size of the buffer.  The number
	 * of bytes returned may or may not include the null terminator.
	 */

	lib_nulloutstream(&nulloutstream);
	lib_vsprintf((FAR struct lib_outstream_s *)&nulloutstream, fmt, ap1);

	/* Then allocate a buffer to hold that number of characters, adding one
	 * for the null terminator.
	 */

	buf = (FAR char *)malloc(nulloutstream.nput + 1);
	if (!buf) {
		return ERROR;
	}

	/* Initialize a memory stream to write into the allocated buffer.  The
	 * memory stream will reserve one byte at the end of the buffer for the
	 * null terminator and will not report this in the number of output bytes.
	 */

	lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream, buf, nulloutstream.nput + 1);

	/* Then let lib_vsprintf do it's real thing */

	nbytes = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap2);

	/* Return a pointer to the string to the caller.  NOTE: the memstream put()
	 * method has already added the NUL terminator to the end of the string (not
	 * included in the nput count).
	 *
	 * Hmmm.. looks like the memory would be stranded if lib_vsprintf() returned
	 * an error.  Does that ever happen?
	 */

	DEBUGASSERT(nbytes < 0 || nbytes == nulloutstream.nput);
	*ptr = buf;
	return nbytes;
}


text:
package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismReferenceValue;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xnode.PrimitiveXNode;
import com.evolveum.midpoint.prism.xnode.XNode;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConstructionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LoginEventType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;
import com.evolveum.prism.xml.ns._public.types_3.RawType;

import javax.xml.bind.JAXBElement;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import java.util.Date;

/**
 * @author mederly
 */
public class ValueDisplayUtil {
    public static String toStringValue(PrismPropertyValue propertyValue) {
        Object value = propertyValue.getValue();
        if (value == null) {
            return null;
        } else if (value instanceof String) {
            return (String) value;
        } else if (value instanceof PolyString) {
            return ((PolyString) value).getOrig();
        } else if (value instanceof ProtectedStringType) {
            return "(protected string)";        // todo i18n
        } else if (value instanceof Boolean || value instanceof Integer || value instanceof Long) {
            return value.toString();
        } else if (value instanceof XMLGregorianCalendar) {
            return ((XMLGregorianCalendar) value).toGregorianCalendar().getTime().toLocaleString(); // todo fix
        } else if (value instanceof Date) {
            return ((Date) value).toLocaleString(); // todo fix
        } else if (value instanceof LoginEventType) {
            LoginEventType loginEventType = (LoginEventType) value;
            if (loginEventType.getTimestamp() != null) {
                return loginEventType.getTimestamp().toGregorianCalendar().getTime().toLocaleString(); // todo fix
            } else {
                return "";
            }
        } else if (value instanceof ApprovalSchemaType) {
            ApprovalSchemaType approvalSchemaType = (ApprovalSchemaType) value;
            return approvalSchemaType.getName() + (approvalSchemaType.getDescription() != null ? (": " + approvalSchemaType.getDescription()) : "") + " (...)";
        } else if (value instanceof ConstructionType) {
            ConstructionType ct = (ConstructionType) value;
            Object resource = (ct.getResource() != null ? ct.getResource().getName() : (ct.getResourceRef() != null ? ct.getResourceRef().getOid() : null));
            return "resource object" + (resource != null ? " on " + resource : "") + (ct.getDescription() != null ? ": " + ct.getDescription() : "");
        } else if (value instanceof Enum) {
            return value.toString();
        } else if (value instanceof ResourceAttributeDefinitionType) {
            ResourceAttributeDefinitionType radt = (ResourceAttributeDefinitionType) value;
            ItemPathType ref = radt.getRef();
            String path;
            if (ref != null) {
                path = ref.getItemPath().toString();
            } else {
                path = "(null)";
            }
            StringBuilder sb = new StringBuilder();
            MappingType mappingType = radt.getOutbound();
            if (mappingType != null) {
                if (mappingType.getExpression() == null) {
                    sb.append("Empty mapping for ").append(path);
                } else {
                    sb.append(path).append(" = ");
                    boolean first = true;
                    for (JAXBElement<?> evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                        if (first) {
                            first = false;
                        } else {
                            sb.append(", ");
                        }
                        if (QNameUtil.match(SchemaConstants.C_VALUE, evaluator.getName()) && evaluator.getValue() instanceof RawType) {
                            RawType raw = (RawType) evaluator.getValue();
                            try {
                                XNode xnode = raw.serializeToXNode();
                                if (xnode instanceof PrimitiveXNode) {
                                    sb.append(((PrimitiveXNode) xnode).getStringValue());
                                } else {
                                    sb.append("(a complex value)");
                                }
                            } catch (SchemaException e) {
                                sb.append("(an invalid value)");
                            }
                        } else {
                            sb.append("(a complex expression)");
                        }
                    }
                }
                if (mappingType.getStrength() != null) {
                    sb.append(" (").append(mappingType.getStrength().value()).append(")");
                }
            } else {
                sb.append("Empty mapping for ").append(path);
            }
            return sb.toString();
        } else if (value instanceof QName) {
            QName qname = (QName) value;
            return qname.getLocalPart();
//            if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
//                return qname.getLocalPart() + " (in " + qname.getNamespaceURI() + ")";
//            } else {
//                return qname.getLocalPart();
//            }
        } else if (value instanceof Number) {
			return String.valueOf(value);
        } else if (value instanceof byte[]) {
            return "(binary data)";
        } else {
            return "(a value of type " + value.getClass().getName() + ")";  // todo i18n
        }
    }

    public static String toStringValue(PrismReferenceValue ref) {

        if (ref.getObject() != null) {
            return ref.getObject().toString();
        } else {
            return (ref.getTargetType() != null ? (ref.getTargetType().getLocalPart()+":") : "") + ref.getOid();
        }
    }
}


text:
set -e

# 5: Check or install the app dependencies via Bundler:
bundle check || bundle install --jobs 8 --retry 5

if [ -f config/database.yml ]; then
  bundle exec rake db:create db:migrate db:test:prepare
fi;

exec "$@"


text:
package com.huixinpn.dionysus.authorize.aspect;

import lombok.extern.slf4j.Slf4j;

import org.springframework.data.rest.core.annotation.HandleBeforeCreate;
import org.springframework.data.rest.core.annotation.HandleBeforeDelete;
import org.springframework.data.rest.core.annotation.HandleBeforeLinkDelete;
import org.springframework.data.rest.core.annotation.HandleBeforeSave;
import org.springframework.data.rest.core.annotation.RepositoryEventHandler;
import org.springframework.security.access.prepost.PreAuthorize;

import com.huixinpn.dionysus.domain.article.Article;

@RepositoryEventHandler(Article.class)
@Slf4j
public class ArticleEventHandler {

	@HandleBeforeCreate
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	public void checkCreateAuthority(Article article) {
		log.debug("Creating article {}", article);
	}

	@HandleBeforeSave
	@PreAuthorize("hasRole('ROLE_ADMIN')")
	public void checkUpdateAuthority(Article article) {
		log.debug("Updating article {}", article);
	}

	@HandleBeforeDelete
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public void checkDeleteAuthority(Article article) {
        log.debug("Deleting article {}", article);
    }

    @HandleBeforeLinkDelete
    @PreAuthorize("denyAll()")
    public void deleteCredentialForbidden(Article article) {
        //deny all, cannot be called
    }
}


text:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace SimpleSchemaParser
{
  public class CodeMirrorSchemaInfoSerializer
  {
    private readonly IEnumerable<SimpleXmlElement> elements;
    private JsonTextWriter writer;
    public bool Pretty { get; set; }

    /*
     * {
        "!top": ["top"],
        top: {
          attrs: {
            lang: ["en", "de", "fr", "nl"],
            freeform: null
          },
          children: ["animal", "plant"]
        },
        animal: {
          attrs: {
            name: null,
            isduck: ["yes", "no"]
          },
          children: ["wings", "feet", "body", "head", "tail"]
        },
        plant: {
          attrs: {name: null},
          children: ["leaves", "stem", "flowers"]
        },
        wings: dummy, feet: dummy, body: dummy, head: dummy, tail: dummy,
        leaves: dummy, stem: dummy, flowers: dummy
      }
     */

    public CodeMirrorSchemaInfoSerializer(IEnumerable<SimpleXmlElement> elements)
    {
      this.elements = elements;
    }

    public void SetPrefix(string @namespace, string prefix)
    {
      NamespacePrefixes[@namespace] = prefix;
    }

    private Dictionary<string, string> NamespacePrefixes = new Dictionary<string, string>();

    public string ToJsonString()
    {
      using (var buffer = new StringWriter())
      {
        using (writer = new JsonTextWriter(buffer))
        {
          writer.Formatting = Pretty ? Formatting.Indented : Formatting.None;
          writer.WriteStartObject();
          WriteTopElements(elements.Where(e => e.IsTopLevelElement));
          foreach (var element in elements)
          {
            WriteElement(element);
          }
          writer.WriteEndObject();
        }
        return buffer.ToString();
      }
    }

    private string ToElementName(SimpleXmlElement element)
    {
      if (string.IsNullOrEmpty(element.Namespace))
        return element.Name;
      return string.Format("{0}:{1}", GetPrefix(element.Namespace), element.Name);
    }

    private string ToElementName(SimpleXmlElementRef elementRef)
    {
      if (string.IsNullOrEmpty(elementRef.Namespace))
        return elementRef.Name;
      return string.Format("{0}:{1}", GetPrefix(elementRef.Namespace), elementRef.Name);
    }

    private int nsCounter = 0;
    private string GetPrefix(string ns)
    {
      string prefix;
      if (!NamespacePrefixes.TryGetValue(ns, out prefix))
      {
        prefix = "cmns" + nsCounter;
        nsCounter++;
        NamespacePrefixes.Add(ns, prefix);
      }

      return prefix;
    }

    private void WriteTopElements(IEnumerable<SimpleXmlElement> elements)
    {
      if (!elements.Any()) return;
      writer.WritePropertyName("!top");
      writer.WriteStartArray();
      foreach (var element in elements)
      {
        writer.WriteValue(ToElementName(element));
      }
      writer.WriteEndArray();
    }

    private void WriteElement(SimpleXmlElement element)
    {
      writer.WritePropertyName(ToElementName(element));
      writer.WriteStartObject();
      if (element.Attributes != null && element.Attributes.Any())
      {
        writer.WritePropertyName("attrs");
        writer.WriteStartObject();
        foreach (var attribute in element.Attributes)
        {
          writer.WritePropertyName(attribute.Name);
          if (attribute.PossibleValues == null || !attribute.PossibleValues.Any())
          {
            writer.WriteNull();
          }
          else
          {
            writer.WriteStartArray();
            foreach (var value in attribute.PossibleValues)
            {
              writer.WriteValue(value);
            }
            writer.WriteEndArray();
          }
        }
        writer.WriteEndObject();
      }

      if (element.Children != null && element.Children.Any())
      {
        writer.WritePropertyName("children");
        writer.WriteStartArray();
        foreach (var child in element.Children)
        {
          writer.WriteValue(ToElementName(child));
        }
        writer.WriteEndArray();
      }
      writer.WriteEndObject();
    }

  }
}