text:
/*

  NanoGUI was developed by Wenzel Jakob <wenzel.jakob@epfl.ch>.
  The widget drawing code is based on the NanoVG demo application
  by Mikko Mononen.

  All rights reserved. Use of NanoGUI and NanoVG source code is governed by a
  BSD-style license that can be found in the LICENSE.txt file.

*/

// -todo: write visualizer overview for Readme.md
// -todo: put sensitivity into a separate settings struct - not broke, don't fix
// -todo: visualize one variable from tbl
// -todo: visualize more variables from tbl
// -todo: visualize map keys as u64
// -todo: visualize array as u64
// -todo: draw table under UI
// -todo: use toString to find all string bounds ahead of time for fields
// -todo: find bounds of key-values ahead of time and draw
// -todo: find bounds of array values ahead of time and draw
// -todo: make bnd2f in vec.hpp - put in VizDecl
// -todo: figure out bounding box for window minus sidebar
// -todo: layout bounds within a specified bounding box
// -todo: figure out why resolution goes down - device pixel ratio needs to just be 1.f
// -todo: use templated tbl for layout of table cell drawing
// -todo: sort keys so that they are in alphabetical order
// -todo: fix drawing of empty key
// -todo: use tbl for ofsts
// -todo: convert to using tbl instead of vectors for drawing labels - needed to make push use the copy constructor instead of the assignment operator ( operator= )
// -todo: draw blue line as a separator between tbl sections
// -todo: draw a line around table visualization
// -todo: draw graph of array values
// -todo: make sure selecting same db doesn't close the db
// -todo: fix wrong simdb on first switch - problem is index not being changed when the dbNames is updated? - also needed to change setSelectionIndex(int) on the nanogui ComboBox
// -todo: make memcmp assert in tfm
// -todo: make tbl to Shape function in VizTfm.hpp
// -todo: use tbl for IndexedVerts after adding sub-tables
// -todo: convert makeTriangle and makeCube to return IdxVerts tbls
// -todo: make sure currently selected db is initialized - how does the initial name become set? - needed to reorganize to make sure that listing the dbs was done at first and the dbs were opened on a menu list if there is no current db open, even if the index hasn't changed
// -todo: fix blank tbl elements - look at testGeo creation - tbl initialization arguments were mixed up
// -todo: fix crash while turning on second button - can't repeat this old note/bug
// -todo: take out test db
// -todo: take out nanovg visualization of tbl
// -todo: look back at Shape and if mv is actually deleting the openGL handles - seems like it was
// -todo: convert to using non-templated tbl
// -todo: convert to using new IdxVerts format
// -todo: try drawing most basic shapes possible to get something to show up - triangle y positions were all -1, rendering as points showed the problem
// -todo: fix tbl visualization cells going outside the bounds of bounding box - need to wrap sooner, possibly based on more margins - worry about table visualization later if at all, now done through Brandisher
// -todo: put shaders back to normal
// -todo: change shaders to use string literals
// -todo: make default image all 0s
// -todo: clean out comments in VizTfm.hpp
// -todo: deal with sub tables for vert components not being present in VizTfm.hpp index verts to shape - operator bool added to tbl, initialization of verts added to tbl_to_shape function
// -todo: change project name to Visualizer
// -todo: change project name to visualizer
// -todo: fix crash from VS execution in release mode - no longer a problem for some reason
// -todo: make IdxVerts to shape transformation not need positions by defaulting them to 0
// -todo: make point and line size increase only happen on key down
// -todo: clean out comments
// -todo: debug keys not being updated when changed - need to build in mechanic for updates
// -todo: make empty shapes erase from the Shapes map and delete their buttons - buttons are wiped out every time, but the shapes array was not being treated as the authority on buttons being recreated
// -todo: make sure that a table has type IdxVerts before listing it on the side
// -todo: put back updateKey to udate shapes every frame
// -todo: investigate memory leak on rapidly updating keys - Shape class wasn't deleting current openGL handles when taking in another moved Shape
// -todo: look at concurrency and possibly put in mutex while editing or drawing nanogui - no concurrency going on, this shouldn't be the problem
// -todo: look in to keys from fissure dissapearing when being overwritten constantly - possibly from the loop through the db to get its keys not being able to get a stable key list while the keys are rapidly shifting around - commenting out eraseMissingKeys fixes the issue but leaves a need to take care of missing keys
// -todo: move and rename project to LavaViz or any non test name
// -todo: try out tiny/nano file dialog for saving and loading of serialized data - brandisher can save files, no longer needed
// -todo: make save button or menu to save serialized files
// -todo: make a load button or menu to load serialized files - would need to have a visualizer specific simdb that would keep the files?
// -todo: erase shapes based off of querys to db
// -todo: investigate crash while visualizing multiple tables in a running graph
// -todo: try querying keys to see if they are missing instead of using the keys vector from db.getKey
// -todo: move new types and statics to files made for them
// -todo: test further for crashes
// -todo: test with all threads running in fissure
// -todo: make mouse up events not be stopped even if they happen in the nanoui areas
// -todo: give Visualizer a way to delete db keys - holding right click while pressing a button deletes key, but doesn't work for some reason with multiple keys
// -todo: make delete key delete visible keys
// -todo: fix 'f' fitting and shapes to bounding sphere function with multiple shapes
// -todo: debug why delete is not always working - version is not always 0 even when a key doesn't exist

// todo: debug why db button dissapears when there are four or more indexed verts entries
// todo: do something to bound the clip planes to the current visible models tighter - hopefully this would fix the z-fighting
// todo: make camera fitting use the field of view and change the dist to fit all geometry
//       |  use the camera's new position and take a vector orthongonal to the camera-to-lookat vector. the acos of the dot product is the angle, but tan will be needed to set a position from the angle?
//       |  visualize the fit position and camera frustum in real time to debug
// todo: keep databases in memory after listing them?

// idea: draw histogram from array
// idea: draw variance per pixel when graph of values ends up sub-pixel
// idea: zoom in on array visualization by clicking on a place in the graph or histogram - graph would zoom in on a section in memory - histogram would need to show the indices that are within a certain value range
// idea: visualize memory layout with hex numbers
// idea: use libtcc to interpret a struct declaration for the type of tbl array?
// idea: use field key values in the tbl to interpret the tbl array type?
// idea: look into drag and drop to load indexed verts objects by dragging from a file
// idea: ability to display points of an indexed verts type as numbers - this would give the ability to have numbers floating in space - could be take care of with a specialized tbl

#include <chrono>
#include <memory>
#include <mutex>
#include <algorithm>
#include <fstream>
#include <sstream>
#include "GL/glew.h"

#define GLM_FORCE_RADIANS
#define GLM_ENABLE_EXPERIMENTAL
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "glm/gtc/constants.hpp"
#include "glm/gtx/matrix_decompose.hpp"

#include "glfw3.h"

#include "VizDecl.h"
#include "VizData.hpp"
#include "VizGen.hpp"
#include "VizTfm.hpp"

//#include "no_rt_util.h"
#include "../str_util.hpp"
#include "../no_rt_util.h"

#define ENTRY_DECLARATION int main(void)
#ifdef _MSC_VER
  #pragma comment(lib, "glfw3dll.lib")
  #pragma comment(lib, "opengl32.lib")
  //#pragma comment(lib, "glew32.lib")

  #if defined(_DEBUG)
    #define USE_CONSOLE                                 // turning this off will use the windows subsystem in the linker and change the entry point to WinMain() so that no command line/console will appear
  #endif
  #ifndef USE_CONSOLE
    #pragma comment( linker, "/subsystem:windows" )
    #undef ENTRY_DECLARATION
    #define ENTRY_DECLARATION int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
  #endif
#endif

#define MAX_VERTEX_BUFFER  512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024

//static tbl          tst;
static std::mutex   ui_mutex;
static bool         uiChanged = false;

namespace {  // functions that are a transform from one datatype to another are in VizTfm.hpp - functions here are more state based

using v2i  =  Eigen::Vector2i;
using v4f  =  Eigen::Vector4f;

const u32 TITLE_MAX_LEN = 256;

#include "../../../str_util.hpp"
void   printdb(simdb const& db)
{
  using namespace std;

  Println("size: ", db.size());

  std::vector<i8> memv(db.memsize(), 0);
  memcpy( (void*)memv.data(), db.mem(), db.memsize() );

  Println("\n");

  u64 blksz = db.blockSize();
  TO(memv.size(),i){
    if(i % blksz == 0){
      putc('|', stdout);
    }
    putc(memv[i] ,stdout);
  }
}

void           buttonCallback(str key, bool pushed);
void                refreshDB(VizData* vd);

vec3                      pos(mat4 const& m)
{ return m[3];                      }
void                  set_pos(mat4* m, vec3 const p)
{
  //(*m)[0].w = p.x;
  //(*m)[1].w = p.y;
  //(*m)[2].w = p.z;
  (*m)[3].x = p.x;
  (*m)[3].y = p.y;
  (*m)[3].z = p.z;
}
float        wrapAngleRadians(float angle)
{
  using namespace glm;
  const static float _2PI = 2.f*pi<float>();

  return fmodf(angle, _2PI);
}

void                initSimDB(str const& name)
{
  db.close();
  new (&db) simdb(name.c_str(), 4096, 1 << 14);             // inititialize the DB with placement new into the data segment

  if(vd.win){
    str title = "Visualizer - simdb_" + name;
    glfwSetWindowTitle(vd.win, title.c_str());
  }
}
void                 initGlew()
{
  //glewExperimental = 1;
  if(glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to setup GLEW\n");
    exit(1);
  }
}
Camera             initCamera()
{
  Camera cam;
  cam.fov             = PIf * 0.5f;
  cam.mouseDelta      = vec2(0.0f, 0.0f);
  cam.btn2Delta       = vec2(0.0f, 0.0f);
  cam.sensitivity     = 0.005f;
  cam.pansense        = 0.002f;
  cam.pos             = vec3(0,0,-10.0f);
  cam.rot             = vec3(0,0,0);
  cam.lookAt          = vec3(0.0f, 0.0f, 0.0f);
  cam.dist            = 10.0f;
  cam.up              = vec3(0.0f, 1.0f, 0.0f);
  cam.oldMousePos     = vec2(0.0f, 0.0f);
  cam.rightButtonDown = false;
  cam.leftButtonDown  = false;
  cam.nearClip        = 0.01f;
  cam.farClip         = 1000.0f;

  return cam;
}

void            errorCallback(int e, const char *d) {
  printf("Error %d: %s\n", e, d);
  fflush(stdout);
}
void              keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
  //using namespace glm;

  if(key==GLFW_KEY_ESCAPE && action==GLFW_PRESS)
    glfwSetWindowShouldClose(window, GL_TRUE);

  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);
  auto&   cam = vd->camera;

  if(action==GLFW_PRESS){
    switch(key)
    {
    case GLFW_KEY_K: {
    } break;
    case GLFW_KEY_H: {
      vd->camera = initCamera();
    } break;
    case GLFW_KEY_J:
    case GLFW_KEY_F: {
      //refreshDB(vd);
      vec4   sph   =  shapes_to_bndsph(*vd);
      vec3  cntr   =  vec3(sph.x,sph.y,sph.z);
      vec3  ofst   =  cam.pos - cam.lookAt;
      cam.lookAt   =  cntr;
      cam.pos      =  cam.lookAt + ofst;
      cam.dist     =  sph.w * 1.25f;
      cam.up       =  vec3(0.0f, 1.0f, 0.0f);
    } break;
    case GLFW_KEY_PAGE_UP: {
      vd->ui.ptSz *= 2;
    } break;
    case GLFW_KEY_PAGE_DOWN: {
      vd->ui.ptSz /= 2;
    } break;
    case GLFW_KEY_DELETE: {                            // when the delete key is pressed, delete all the visible keys
      for(auto const& kv : vd->shapes){
        auto const& s = kv.second;
        if(s.active){
          db.del(kv.first);                           // kv.first should be the key as a string
        }
      }
    } break;
    default:
      break;
    }
  }

  vd->ui.screen.keyCallbackEvent(key, scancode, action, mods);
}
void           scrollCallback(GLFWwindow* window, double xofst, double yofst)
{
  using namespace std;

  const float dollySens = 0.1f;

  VizData*   vd = (VizData*)glfwGetWindowUserPointer(window);
  auto&     cam = vd->camera;
  float    ofst = (float) -(cam.dist*yofst*dollySens);
  float  prvDst = cam.dist;                                        // prvDst is previous distance
  float  nxtDst = cam.dist;
  nxtDst        = cam.dist + ofst;
  cam.dist      = nxtDst;

  vd->ui.screen.scrollCallbackEvent(xofst, yofst);
}
void         mouseBtnCallback(GLFWwindow* window, int button, int action, int mods)
{
  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);

  vd->ui.showGuide = false;

  bool used = false;
  if(!uiChanged)
    used = vd->ui.screen.mouseButtonCallbackEvent(button, action, mods);

  if(action==GLFW_RELEASE){ vd->camera.leftButtonDown  = false; }  // do mouse release events no matter what, so that the camera movement doesn't become locked to the mouse movement if the mouse up happens over the nanogui
  if(action==GLFW_RELEASE){ vd->camera.rightButtonDown = false; }

  if( !used )
  {
    if(button==GLFW_MOUSE_BUTTON_LEFT){
      if(action==GLFW_PRESS) vd->camera.leftButtonDown = true;

      //else if(action==GLFW_RELEASE) vd->camera.leftButtonDown = false;
    }

    if(button==GLFW_MOUSE_BUTTON_RIGHT){
      if(action==GLFW_PRESS) vd->camera.rightButtonDown = true;

      //else if(action==GLFW_RELEASE){
      //  vd->camera.rightButtonDown = false;
      //}
    }
  }
}
void        cursorPosCallback(GLFWwindow* window, double x, double y)
{
  //using namespace glm;
  const static float _2PI = 2.f* PIf; //  pi<float>();

  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);

  Camera& cam = vd->camera;
  vec2 newMousePosition = vec2((float)x, (float)y);

  if(cam.leftButtonDown){
    cam.mouseDelta = (newMousePosition - cam.oldMousePos);
  }else{ cam.mouseDelta = vec2(0,0); }

  if(cam.rightButtonDown){
    cam.btn2Delta  = (newMousePosition - cam.oldMousePos);
  }else{
    cam.btn2Delta  = vec2(0,0);

    cam.tfm     =  lookAt(cam.pos, cam.lookAt, cam.up);
    vec3 scale, pos, skew; vec4 persp;
    quat rot;
    decompose(cam.tfm, scale, rot, pos, skew, persp);
    cam.pantfm  =  (mat4)conjugate(rot);
  }

  cam.oldMousePos = newMousePosition;

  vd->ui.screen.cursorPosCallbackEvent(x,y);
}
void             charCallback(GLFWwindow* window, unsigned int codepoint)
{
  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);

  vd->ui.screen.charCallbackEvent(codepoint);
}
void             dropCallback(GLFWwindow* window, int count, const char** filenames)
{
  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);

  vd->ui.screen.dropCallbackEvent(count, filenames);
}
void  framebufferSizeCallback(GLFWwindow* window, int w, int h)
{
  VizData* vd = (VizData*)glfwGetWindowUserPointer(window);

  vd->ui.screen.resizeCallbackEvent(w, h);
}
GLFWwindow*          initGLFW(VizData* vd)
{
  if( !glfwInit() ){
    fprintf(stdout, "[GFLW] failed to init!\n");
    exit(1);
  }
  glfwSetErrorCallback(errorCallback);

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_DOUBLEBUFFER, GL_TRUE);
  glfwWindowHint(GLFW_SAMPLES, 32);

  GLFWwindow* win = glfwCreateWindow(vd->ui.w, vd->ui.h, "Visualizer", NULL, NULL);    assert(win!=nullptr);
  glfwMakeContextCurrent(win);
  glfwGetWindowSize(win, &vd->ui.w, &vd->ui.h);

  glfwSetCharCallback(win,              charCallback);         // in glfw charCallback is for typing letters and is different than the keyCallback for keys like backspace
  glfwSetKeyCallback(win,                keyCallback);
  glfwSetScrollCallback(win,          scrollCallback);
  glfwSetCursorPosCallback(win,    cursorPosCallback);
  glfwSetMouseButtonCallback(win,   mouseBtnCallback);
  glfwSetDropCallback(win,              dropCallback);
  glfwSetFramebufferSizeCallback(win, framebufferSizeCallback);
  //glfwSetScrollCallback(win, )

  #ifdef _WIN32
    //GLFWimage images[2];
    //images[0] = LoadIcon("lava.jpg");
    //images[1] = LoadIcon("lava.jpg");
    //glfwSetWindowIcon(win, 2, images);
  #endif

  return win;
}

void              RenderShape(Shape const& shp, mat4 const& m) // GLuint shaderId)
{
  glUseProgram(shp.shader);  //shader.use();

  GLint transformLoc = glGetUniformLocation(vd.shaderId, "transform");
  glUniformMatrix4fv(transformLoc, 1, GL_FALSE, value_ptr(m));

  GLint size;
  glActiveTexture(GL_TEXTURE0);	// Activate the texture unit first before binding texture
  glBindTexture(GL_TEXTURE_2D, shp.tx);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // GL_LINEAR);
  PRINT_GL_ERRORS

  auto loc = glGetUniformLocation(shp.shader, "tex0");
  glUniform1i(loc, 0);

  glBindVertexArray(shp.vertary);                                          PRINT_GL_ERRORS
  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, shp.idxbuf);                       PRINT_GL_ERRORS
  glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);  PRINT_GL_ERRORS   // todo: keep size with shape instead of querying it
  glDrawElements(shp.mode, shp.indsz, GL_UNSIGNED_INT, 0);                 PRINT_GL_ERRORS   // todo: can't use quads with glDrawElements?

  //glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, 0);

  glBindVertexArray(0);
  glBindTexture(GL_TEXTURE_2D, 0);
}
bool                updateKey(simdb const& db, str const& key, u32 version, VizData* vd)
{
  using namespace std;

  u32 dbVersion = 0;
  u32      vlen = 0;
  auto      len = db.len(key.data(), (u32)key.length(), &vlen, &dbVersion);

  if(len>0 && dbVersion!=version)
  {
    vec<u8> ivbuf(vlen);
    db.get(key.data(), (u32)key.length(), ivbuf.data(), (u32)ivbuf.size());

    Shape  s  = tblbuf_to_shape( move(ivbuf) );
    if( !s.owner ){ return false; }
    s.shader  = vd->shaderId;
    s.active  = true;                     // because updates only happen when the shape is active, always setting an updated shape to active should work
    s.version = dbVersion;
    vd->shapes[key] = move(s);

    return true;
  }

  return false;
}
vec_vs         shapesFromKeys(simdb const& db, vec_vs dbKeys, VizData* vd)  // vec<str> const& dbKeys
{
  using namespace std;

  vec<u8> ivbuf;
  for(auto& vs : dbKeys)
    TO(dbKeys.size(),i)
    {
      auto& vs = dbKeys[i];
      SECTION(continue if the vs.str key name was found in shapes and the version is the same as the new version)
      {
        auto cur = vd->shapes.find(vs.str);
        if(cur!=vd->shapes.end() &&               // if the vs.str key name was found in shapes and the version is the same as the new version, skip it
           cur->second.version == vs.ver
        ){
          continue;
        }
      }

      u32 vlen = 0;
      SECTION(get the length in bytes and version from the db)
      {
        auto len = db.len(vs.str.data(), (u32)vs.str.length(), &vlen, &vs.ver);          // todo: make ui64 as the input length
        if(len < sizeof(tbl::TblFields)){ continue; }
      }

      ivbuf.resize(vlen);
      SECTION(get the bytes from the db and check to make sure the read length is the same)
      {
        u32 readLen=0;
        bool ok = db.get(vs.str.data(), (u32)vs.str.length(),  ivbuf.data(), vlen, &readLen);
        if(!ok || readLen==0 || readLen != vlen){
          continue;
        }
      }

      Shape  s   = tblbuf_to_shape( move(ivbuf) );      PRINT_GL_ERRORS
      if(!s.owner){ continue; }                                                          // if owner is false here then the conversion of the buffer to a shape must have failed

      SECTION(finish the shape fields and move the shape into the global shape map)
      {
        s.shader   = vd->shaderId;
        s.active   = vd->shapes[vs.str].active;
        s.version  = vs.ver;
        vd->shapes[vs.str] = move(s);                                                      // this should destruct the shape with the same name if there is one
      }
    };

  return dbKeys;
}
vec_vs       eraseMissingKeys(vec_vs dbKeys, KeyShapes* shps)           // vec<str> dbKeys,
{
  int cnt = 0;
  sort( ALL(dbKeys) );
  if( shps->size() > 0 && dbKeys.size() == 0 )
    printf("wat");

  for(auto it = shps->begin(); it != shps->end(); )
  {
    auto const& kv = *it;
    VerStr vs;
    vs.ver = kv.second.version;
    vs.str = kv.first;
    bool isKeyInDb = binary_search(ALL(dbKeys),vs, [](VerStr const& a, VerStr const& b){ return a.str < b.str; } );
    if( !isKeyInDb ){
      it = shps->erase(it);
      ++cnt;
    }else
      ++it;
  }

  return dbKeys;
}
u32       eraseMissingKeys(KeyShapes* shps)
{
  u32 cnt = 0;
  for(auto it = shps->begin();  it != shps->end(); )
  {
    u32    vlen = 0;
    u32 version = 0;
    i64     len = db.len(it->first, &vlen, &version);
    if(version==0 || len==0 || vlen==0){
      it = shps->erase(it);
      ++cnt;
    }else
      ++it;
  }

  return cnt;

  //
  //if(version==0 && (len==0 || vlen==0) ){

  //KeyShapes* shps = &vd->shapes;
  //
  //auto const& kv = *it;
  //
  //VerStr vs;
  //vs.ver   = kv.second.version;
  //vs.str   = kv.first;
}
double                   nowd()
{
  using namespace std;
  using namespace std::chrono;

  auto nano = duration_cast<nanoseconds>( chrono::high_resolution_clock::now().time_since_epoch() );

  return nano.count() / 1000000000.0;
}
void                refreshDB(VizData* vd)
{
  auto dbKeys = db.getKeyStrs();                                      // Get all keys in DB - this will need to be ran in the main loop, but not every frame
  dbKeys      = shapesFromKeys(db, move(dbKeys), vd);
  u32 erased  = eraseMissingKeys(&vd->shapes);
  sort(ALL(dbKeys));
  sort(ALL(vd->ui.dbIdxs));                                                  // sort the indices so the largest are removed first and the smaller indices don't change their position

  SECTION(lock the ui_mutex and update the ui with the new buttons)
  {
  LockGuard ui_guard(ui_mutex);
    FROM(vd->ui.dbIdxs.size(), i){
      vd->ui.keyWin->childAt(i)->setVisible(false);
      vd->ui.keyWin->childAt(i)->setEnabled(false);
      vd->ui.keyWin->removeChild(vd->ui.dbIdxs[i]);
    }

    vd->ui.dbIdxs.resize(0);
    vd->ui.dbIdxs.shrink_to_fit();
    for(auto const& kv : vd->shapes)                                              // add the buttons back and keep track of their indices
    {
      auto b = new Button(vd->ui.keyWin, kv.first);
      int  i = vd->ui.keyWin->childIndex(b);
      if(i > -1){ vd->ui.dbIdxs.push_back(i); }
      b->setFlags(Button::ToggleButton);
      b->setChangeCallback([k = kv.first](bool pushed){ buttonCallback(k, pushed); });
      b->setPushed(kv.second.active);
      b->setFixedHeight(25);
    }
    vd->ui.screen.mDragActive = false;
    vd->ui.screen.mDragWidget = nullptr;
    vd->ui.keyWin->mDrag      = false;
    vd->ui.screen.performLayout();
  }

  vd->keyRefreshClock -= vd->keyRefresh;
  vd->verRefreshClock -= vd->verRefresh;

  if(vd->keyRefreshClock > vd->keyRefresh){                           // if there is already enough time saved up for another update make sure that less that two updates worth of time is kept
    vd->keyRefreshClock = vd->keyRefresh + fmod(vd->keyRefreshClock, vd->keyRefresh);
  }
}

void           buttonCallback(str key, bool pushed)
{
  if(vd.camera.rightButtonDown){
    db.del(key);
  }else{
    auto it = vd.shapes.find(key);
    if(it == vd.shapes.end()){ return; }

    if(it->second.owner){ it->second.active = pushed; }
  }

  //vd.shapes[key].active = pushed;
}
void       dbLstPressCallback(int i)
{
  if(i < vd.ui.dbNames.size() ){ // && i!=vd.ui.dbNameIdx){
    vd.ui.dbNameIdx = i;
    vd.ui.dbName = vd.ui.dbNames[i];
    initSimDB(vd.ui.dbName);
    refreshDB(&vd);
    vd.ui.dbLst->setSelectedIndex(i);
  }
  vd.ui.screen.performLayout();
}
void      dbLstChangeCallback(bool pressed)
{
  if(pressed){
    vd.ui.dbNames = simdb_listDBs();                            // all of these are globals

    str  name;
    if(vd.ui.dbNameIdx>=0 && vd.ui.dbNameIdx<vd.ui.dbNames.size()){
      name = vd.ui.dbNames[vd.ui.dbNameIdx];
    }

    auto iter = find( ALL(vd.ui.dbNames), name);
    if(iter != vd.ui.dbNames.end()){
      vd.ui.dbNameIdx = iter - vd.ui.dbNames.begin();
    }else{ vd.ui.dbNameIdx = 0; }                                                        // if the name isn't found in the new listing, then just reset to the first in the list of db names

    if(vd.ui.dbLst){
      vd.ui.dbLst->setItems(vd.ui.dbNames);
      vd.ui.dbLst->setSelectedIndex(vd.ui.dbNameIdx);
      if(db.mem() == nullptr){
        dbLstPressCallback(vd.ui.dbNameIdx);
      }
    }
    vd.ui.screen.performLayout();
  }
}

void       drawBnd(NVGcontext* nvg, f32  b[4])
{
  nvgBeginPath(nvg);
   nvgRect(nvg, b[0], b[1], b[2]-b[0], b[3]-b[1]);
   nvgStrokeWidth(nvg, 1.f);
   nvgStrokeColor(nvg, nvgRGBAf(.8f, .6f, .2f, 1.f));
  nvgStroke(nvg);
}
void      drawLine(NVGcontext* nvg, f32 x, f32 y, f32 w)
{
  nvgBeginPath(nvg);
    nvgRect(nvg, x, y, w, 1.f);
    nvgStrokeWidth(nvg, 1.f);
    nvgStrokeColor(nvg, nvgRGBAf(0,.25f,.8f, 1.f));
  nvgStroke(nvg);
}
void      drawHist(NVGcontext* nvg, u64* buf, u64 len, bnd2f b)
{

}
v2         strOfst(NVGcontext* nvg, str    const&    s)                                      // strOfst is string offset
{
  bnd2f bnd;
  nvgTextBounds(nvg, 0,0, s.c_str(), NULL, bnd.b);

  return { bnd.xmx-bnd.xmn, bnd.ymx-bnd.ymn };
}
f32       drawStrs(NVGcontext* nvg, tblstr const& strs, tblv2 const& ofsts, f32 w, f32 x, f32 y, f32 margin)
{
  f32  h = 0.f;
  f32 m2 = margin * 2.f;
  v2   o = {x,y};                                                                         // o is offset
  TO(strs.size(),i){
    if(o.x+ofsts[i].x+m2 > w){
      o.x  = x;
      o.y += ofsts[i].y + m2;
      h   += ofsts[i].y + m2;
    }else if(i==0){ h += ofsts[i].y + m2; }

    bnd2f bnd = { o.x, o.y, o.x+ofsts[i].x+m2, o.y+ofsts[i].y+m2 };                       //  o.x + margin * 2, o.y + margin * 2 };
    drawBnd(nvg, bnd.b);

    nvgText(nvg, o.x+margin, o.y+ofsts[i].y+margin, strs[i].c_str(), NULL);

    o.x += ofsts[i].x + m2;
  }

  return h;
}
f32      drawGraph(NVGcontext* nvg, tbl    const&    t, bnd2f b)
{
  using namespace std;

  f32 mxf, inc, hgt;

  u64 mx = 0;
  TO(t.size(),i){ mx = max<u64>(mx, (u64)t[i]);  }
  mxf = (f32)mx;
  inc = (b.w()-4) / (f32)t.size();
  hgt = b.h()-4;

  nvgStrokeWidth(nvg, 1.f);
  nvgStrokeColor(nvg, nvgRGBAf(0,.8f,.25f, 1.f));
  nvgFillColor(nvg,   nvgRGBAf(0,.5f,.25f, .5f));
  TO(t.size(),i)
  {
    f32 x = b.xmn + i*inc + 2;
    f32 y = b.ymx - 2;
    f32 h = hgt * ( (u64)t[i] / mxf);
    nvgBeginPath(nvg);
      nvgRect(nvg, x, y-h, inc, h);
    nvgFill(nvg);
    nvgStroke(nvg);
  }

  return b.ymx - b.ymn;
}

//void       drawTbl(NVGcontext* nvg, tblu   const&    t, f32 w, f32 h, f32 x=0.f, f32 y=0.f, f32 sz=50.f, f32 margin=5.f)
//{
//  using namespace std;
//
//  f32 xo=0, yo=0;                                                    // xo is x offset   yo is y offset
//  f32 vizW = w - x - margin*2;
//
//  nvgFontSize(nvg,  sz);
//  nvgFontFace(nvg,  "sans");
//  nvgTextAlign(nvg, NVG_ALIGN_LEFT); // | NVG_ALIGN_MIDDLE);
//  nvgFillColor(nvg, nvgRGBAf(1.f, 1.f, .65f, 1.f));
//
//  tblstr labels;  labels.reserve(5);
//  tblv2   ofsts;  ofsts.reserve(5);
//
//  v2      o = { x+margin, y+margin };                                                                    // o is offset
//  f32  xrem = w;
//  f32   mxY = 0.f;
//  f32    dh = 0.f;                                                                         // dh is draw height
//  SECTION(draw fields)
//  {
//    labels.push_back( toString("sizeBytes:  ",     t.sizeBytes())      );
//    labels.push_back( toString("capacity:  ",      t.capacity())       );
//    labels.push_back( toString("size:  ",          t.size())           );
//    labels.push_back( toString("map elems:  ",     t.elems())          );
//    labels.push_back( toString("map capacity:  ",  t.map_capacity())   );
//    labels.push_back( toString("child capcity:  ", t.child_capacity()) );
//    TO(labels.size(),i){ ofsts.push_back( strOfst(nvg,labels[i]) ); }
//    TO(ofsts.size(),i){ mxY = max<f32>(mxY, ofsts[i].y); }
//
//    dh = drawStrs(nvg, labels, ofsts, w, o.x, o.y, margin);
//  }
//
//  o.x  = x+margin;
//  o.y += dh + margin*2;                                                                   // o is offset
//  drawLine(nvg, x, o.y-margin, w-x-margin*2);
//  SECTION(draw key value pairs)
//  {
//    labels.clear();
//    auto e = t.elemStart();
//    TO(t.map_capacity(),i) if(!e[i].isEmpty()){
//      labels.push_back( toString(e[i].key,":  ", e[i].val) );
//    }
//    sort( ALL(labels) );
//    ofsts.clear();
//    TO(labels.size(),i){ ofsts.push_back(strOfst(nvg, labels[i])); }
//    mxY=0.f;
//    TO(ofsts.size(),i){ mxY = max<f32>(mxY, ofsts[i].y); }
//
//    dh = drawStrs(nvg, labels, ofsts, w, o.x, o.y, margin);
//  }
//
//  o.x   =  x+margin;
//  o.y  +=  dh + margin*2;
//  drawLine(nvg, o.x-margin, o.y-margin, w-x-margin*2);
//  SECTION(draw array elements)
//  {
//    labels.clear();
//    TO(t.size(),i){ labels.push_back( toString(i,":  ",t[i]) ); }
//
//    ofsts.clear();
//    //new (&ofsts) tblv2;
//    TO(labels.size(), i) { ofsts.push_back(strOfst(nvg, labels[i])); }
//    mxY=0.f;
//    TO(ofsts.size(),i){ mxY = max<f32>(mxY, ofsts[i].y); }
//
//    dh = drawStrs(nvg, labels, ofsts, w-margin, o.x, o.y, margin);
//  }
//
//  o.x  =  x+margin;
//  o.y +=  dh + margin*2;
//  dh   =  drawGraph(nvg, t, {o.x, o.y, x+vizW-margin, o.y+100.f});
//
//  o.y  +=  dh + margin*2;
//  nvgBeginPath(nvg);
//    nvgRect(nvg, x, y, w-x-margin*2, o.y);
//    nvgStrokeWidth(nvg, 1.f);
//    nvgStrokeColor(nvg, nvgRGBAf(0,.1f,.6f, 1.f));
//  nvgStroke(nvg);
//
//  //nvgRect(nvg, x, y, w-x-margin*2, o.y+dh);
//}

}

ENTRY_DECLARATION
{
  using namespace std;
  using namespace nanogui;

  SECTION(initialization)
  {
    SECTION(static VizData)
    {
      vd.ui.w             = 1024;
      vd.ui.h             =  768;
      vd.ui.ptSz          =    1.f;
      vd.ui.hudSz         =   16.0f;
      vd.ui.guideSz       =   32.0f;

      vd.now              =  nowd();
      vd.prev             =  vd.now;
      vd.verRefresh       =  1.0/144.0;
      vd.verRefreshClock  =  0.0;
      vd.keyRefresh       =  0.5;
      vd.keyRefreshClock  =  vd.keyRefresh;
      vd.camera           =  initCamera();

      vd.avgFps   =  60;
      vd.prevt    =   0;
      vd.cpuTime  =   0;
      vd.t        =   0;
      vd.dt       =   0;

      vd.ui.keyWin     =  nullptr;
      vd.ui.dbWin      =  nullptr;
      vd.ui.keyLay     =  nullptr;
      vd.ui.dbLst      =  nullptr;
      vd.ui.dbLstIdx   =  -1;
      vd.ui.nvg        =  nullptr;
      vd.ui.showGuide  =  true;
      vd.ui.dbNameIdx  =   0;
    }
    SECTION(glfw and glew)
    {
      vd.win      = initGLFW( &vd );                        assert(vd.win!=nullptr);
      initGlew();
      vd.shaderId = shadersrc_to_shaderid(vertShader, fragShader);   PRINT_GL_ERRORS

      glfwSetWindowUserPointer(vd.win, &vd);
      glfwSwapInterval(1);
      //glfwSwapBuffers(vd.win);
      glfwMakeContextCurrent(vd.win);

      PRINT_GL_ERRORS
    }
    SECTION(nanogui)
    {
      //vd.ui.screen.initialize(vd.win, false);
      vd.ui.screen.initialize(vd.win, true);

      SECTION(sidebar)
      {
        vd.ui.keyLay = new BoxLayout(Orientation::Vertical, Alignment::Fill, 2, 5);
        vd.ui.keyWin = new Window(&vd.ui.screen,  "");
        auto spcr1   = new Label(vd.ui.keyWin,    "");
        auto spcr2   = new Label(vd.ui.keyWin,    "");
        auto spcr3   = new Label(vd.ui.keyWin,    "");
        vd.ui.dbLst  = new ComboBox(vd.ui.keyWin, {"None"} );
        vd.ui.dbLst->setChangeCallback( dbLstChangeCallback );
        dbLstChangeCallback(true);
        vd.ui.dbLst->setCallback( dbLstPressCallback );

        auto spcr4   = new Label(vd.ui.keyWin, "");
        auto spcr5   = new Label(vd.ui.keyWin, "");
        auto spcr6   = new Label(vd.ui.keyWin, "");

        vd.ui.dbLstIdx = vd.ui.keyWin->childIndex(vd.ui.dbLst);                          // only done once so not a problem even though it is a linear search
        vd.ui.keyWin->setLayout(vd.ui.keyLay);
        vd.ui.dbLst->setSide(Popup::Left);

        Theme* thm = vd.ui.keyWin->theme();
        thm->mTransparent         = v4f( .0f,  .0f,  .0f,    .0f );
        thm->mWindowFillUnfocused = v4f( .2f,  .2f,  .225f,  .3f );
        thm->mWindowFillFocused   = v4f( .3f,  .28f, .275f,  .3f );
      }

      vd.ui.screen.setVisible(true);
      vd.ui.screen.performLayout();
    }
    SECTION(nanovg)
    {
      vd.ui.nvg =  nvgCreateGL3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
      if(vd.ui.nvg == NULL){
        printf("Could not init nanovg.\n");
        return -1;
      }

      int font = nvgCreateFontMem(vd.ui.nvg, "sans", Roboto_Regular_ttf, Roboto_Regular_ttf_len, 0);
      if(font == -1){
        printf("Could not add font bold.\n");
        return -1;
      }
    }
  }

  while(!glfwWindowShouldClose(vd.win))
  {
    PRINT_GL_ERRORS

    SECTION(time)
    {
      vd.now  = nowd();
      double passed = vd.now - vd.prev;
      vd.prev = vd.now;
      vd.keyRefreshClock += passed;
      vd.verRefreshClock += passed;

      vd.t     = glfwGetTime();
      vd.dt    = vd.t - vd.prevt;
      vd.prevt = vd.t;
    }
    SECTION(database)
    {
      if( !vd.camera.rightButtonDown && !vd.camera.leftButtonDown ){
        if(vd.keyRefreshClock > vd.keyRefresh)
        {
          uiChanged = true;
          refreshDB(&vd);
        }else{
          for(auto const& kv : vd.shapes){
            Shape const& s = kv.second;
            if(s.active){
              updateKey(db, kv.first, s.version, &vd);
            }
          }
          uiChanged = false;
        }
      }

      PRINT_GL_ERRORS
    }
    SECTION(input)
    {
      vd.camera.mouseDelta = vec2(0,0);
      vd.camera.btn2Delta  = vec2(0,0);
      glfwPollEvents();                                             // PollEvents must be done after zeroing out the deltas
      glfwGetWindowSize(vd.win, &vd.ui.w, &vd.ui.h);

      PRINT_GL_ERRORS
    }
    SECTION(OpenGL setup)
    {
      glViewport(0, 0, vd.ui.w, vd.ui.h);

      //glEnable(GL_TEXTURE_2D);
      //glEnable(GL_DEPTH);
      glDisable(GL_CULL_FACE);
      glFrontFace(GL_CCW);
      glEnable(GL_DEPTH_TEST);                                   // glDepthFunc(GL_LESS);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      PRINT_GL_ERRORS

      glEnable(GL_BLEND);
      glLineWidth(vd.ui.ptSz);
      glPointSize(vd.ui.ptSz);

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glClearColor(0.0625, 0.0625, 0.0625, 0.0625);
      PRINT_GL_ERRORS
    }
    SECTION(render shapes)
    {
      const static auto XAXIS = vec3(1.f, 0.f, 0.f);
      const static auto YAXIS = vec3(0.f, 1.f, 0.f);

      mat4  viewProj;
      vec3      camx;    //  =  normalize( vec3(cam.pantfm*vec4(1.f,0,0,1.f)) );              // use a separate transform for panning that is frozen on mouse down so that the panning space won't constantly be changing due to rotation from the lookat function
      vec3      camy;    //  =  normalize( vec3(cam.pantfm*vec4(0,1.f,0,1.f)) );              // why does the transform change though if both the lookat and offset are being translated? are they not translated at the same time?
      SECTION(update camera)
      {
        auto&  cam    =  vd.camera;
        f32    dst    =  cam.dist;

        float   ry    =  -(cam.mouseDelta.x * cam.sensitivity);
        float   rx    =  -(cam.mouseDelta.y * cam.sensitivity);

        mat4    xzmat = rotate(mat4(), ry, YAXIS);
        mat4     ymat = rotate(mat4(), rx, XAXIS);
        vec4        p = vec4(cam.pos, 1.f);
        cam.pos       =  xzmat * p;
        vec4     ypos(0, p.y, dst, 1.f);
        cam.pos.y     = (ymat * ypos).y;

        vec3 lookOfst = normalize(cam.pos-cam.lookAt)*dst;
        cam.pos = cam.lookAt + lookOfst;

        camx   =  normalize( vec3(cam.pantfm*vec4(1.f,0,0,1.f)) );              // use a separate transform for panning that is frozen on mouse down so that the panning space won't constantly be changing due to rotation from the lookat function
        camy   =  normalize( vec3(cam.pantfm*vec4(0,1.f,0,1.f)) );              // why does the transform change though, if both the lookat and offset are being translated? are they not translated at the same time?

        vec3  ofst(0,0,0);

        ofst        +=  camx *  -cam.btn2Delta.x * cam.pansense * dst;
        ofst        +=  camy *   cam.btn2Delta.y * cam.pansense * dst;
        cam.lookAt  +=  ofst;
        cam.pos     +=  ofst;

        if(vd.ui.w>0 && vd.ui.h>0)
          viewProj   =  camera_to_mat4(cam, (f32)vd.ui.w, (f32)vd.ui.h);
      }
      SECTION(draw shapes)
      {
        for(auto& kv : vd.shapes){
          if(kv.second.active && kv.second.owner)
            RenderShape(kv.second, viewProj);
        }
      }

      PRINT_GL_ERRORS
    }
    SECTION(table)
    {
      //auto w = vd.ui.w - vd.ui.keyWin->width();
      //auto h = vd.ui.h - vd.ui.keyWin->height();

      //nvgBeginFrame(vd.ui.nvg, vd.ui.w, vd.ui.h, 1.f);
      //  drawTbl(vd.ui.nvg, tst, (f32)w, (f32)h, 25, 50, 20, 10);
      //nvgEndFrame(vd.ui.nvg);
    }
    SECTION(nanogui)
    {
      if(vd.ui.keyWin->focused()){
        vd.camera.leftButtonDown  = false;
        vd.camera.rightButtonDown = false;
      }

      v2i   winsz = vd.ui.keyWin->size();
      v2i keyspos = v2i(vd.ui.screen.width() - winsz.x(), 0);
      LockGuard ui_guard(ui_mutex);
        vd.ui.keyWin->setPosition(keyspos);
        vd.ui.keyWin->setSize(v2i(winsz.x(), vd.ui.screen.height()));
        vd.ui.screen.drawContents();
        vd.ui.screen.drawWidgets();
    }
    SECTION(nanovg | tbl visualization, frames per second, color under cursor)
    {
      nvgBeginFrame(vd.ui.nvg, vd.ui.w, vd.ui.h, 1.f); // vd.ui.w/(f32)vd.ui.h);
        f32  tb = 0;
        char nvgStr[TITLE_MAX_LEN];

        SECTION(frames per second)
        {
          vd.avgFps *= 0.9;
          vd.avgFps += (1.0 / vd.dt)*0.1;

          sprintf(nvgStr, "%04.01f", vd.avgFps);

          tb = nvgTextBounds(vd.ui.nvg, 0, 0, nvgStr, NULL, NULL);
          nvgFontSize(vd.ui.nvg, vd.ui.hudSz);
          nvgFontFace(vd.ui.nvg, "sans");
          nvgTextAlign(vd.ui.nvg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);  // NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
          nvgFillColor(vd.ui.nvg, nvgRGBA(255, 255, 255, 255));
          nvgText(vd.ui.nvg, 15.f, vd.ui.hudSz, nvgStr, NULL);
        }
        SECTION(rgb under cursor)
        {
          auto rgb = vd.mouseRGB;
          sprintf(nvgStr, "%.2f  %.2f  %.2f", rgb[0], rgb[1], rgb[2]);
          nvgFontSize(vd.ui.nvg, vd.ui.hudSz);
          nvgFontFace(vd.ui.nvg, "sans");
          nvgTextAlign(vd.ui.nvg, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
          nvgFillColor(vd.ui.nvg, nvgRGBA(255, 255, 255, 255));
          nvgText(vd.ui.nvg, tb + 45.f, vd.ui.hudSz, nvgStr, NULL);
        }

        vd.ui.showGuide = false;
        if(vd.ui.showGuide){
          SECTION(hotkey guide)
          {
            nvgFontSize(vd.ui.nvg, vd.ui.guideSz);
            nvgFontFace(vd.ui.nvg, "sans");
            nvgTextAlign(vd.ui.nvg, NVG_ALIGN_LEFT ); // | NVG_ALIGN_MIDDLE);
            nvgFillColor(vd.ui.nvg, nvgRGBA(255, 255, 255, 235));
            nvgText(vd.ui.nvg, 100, 100,                   hotkeyGuideH,    NULL);
            nvgText(vd.ui.nvg, 100, 100 + vd.ui.guideSz*2, hotkeyGuideF,    NULL);
            nvgText(vd.ui.nvg, 100, 100 + vd.ui.guideSz*4, hotkeyGuidePage, NULL);
          }
        }
      nvgEndFrame(vd.ui.nvg);
    }

    glfwSwapBuffers(vd.win);
    PRINT_GL_ERRORS

    glReadPixels( (GLint)(vd.camera.oldMousePos.x), (GLint)(vd.camera.oldMousePos.y), 1, 1, GL_RGB, GL_FLOAT, vd.mouseRGB);
  }

  nanogui::shutdown();
  glfwTerminate();

  //int a; cin >> a;

  return 0;
}

//if(action==GLFW_PRESS){
//}

//vd.ui.dbLst->setCallback([](int i){                                          // callback for the actual selection
//  if(i < vd.ui.dbNames.size() && i!=vd.ui.dbNameIdx){
//    vd.ui.dbNameIdx = i;
//    vd.ui.dbName = vd.ui.dbNames[i];
//    initSimDB(vd.ui.dbName);
//    refreshDB(&vd);
//    vd.ui.dbLst->setSelectedIndex(i);
//  }
//  vd.ui.screen.performLayout();
//});

//genTestGeo(&db);
//
//void       genTestGeo(simdb* db)
//{
//  using namespace std;
//
//  static simdb db1("test1", 4096, 1 << 14);
//  //static simdb db2("test 2", 4096, 1 << 14);
//
//  //initSimDB("VizDefault");
//
//  // Create serialized IndexedVerts
//  size_t leftLen, rightLen, cubeLen;
//  //vec<u8>  leftData = makeTriangle(leftLen,   true);
//  //vec<u8> rightData = makeTriangle(rightLen, false);
//  //vec<u8>  cubeData = makeCube(cubeLen);
//  IvTbl  leftData = makeTriangle( leftLen,   true);
//  IvTbl rightData = makeTriangle(rightLen,  false);
//  IvTbl  cubeData =     makeCube( cubeLen);
//
//  vec<u8>  leftBytes( leftData.sizeBytes());
//  vec<u8> rightBytes(rightData.sizeBytes());
//  vec<u8>  cubeBytes( cubeData.sizeBytes());
//  memcpy( leftBytes.data(),   leftData.memStart(),  leftData.sizeBytes());
//  memcpy(rightBytes.data(),  rightData.memStart(), rightData.sizeBytes());
//  memcpy( cubeBytes.data(),   cubeData.memStart(),  cubeData.sizeBytes());
//
//  // Store serialized IndexedVerts in the db
//  str  leftTriangle = "leftTriangle";
//  str rightTriangle = "rightTriangle";
//  str          cube = "cube";
//
//  db1.put("1", leftBytes);
//  db1.put("2", rightBytes);
//  db1.put("3", cubeBytes);
//
//  //db2.put("one",    leftBytes);
//  //db2.put("two",   rightBytes);
//  //db2.put("three",  cubeBytes);
//  //db2.put("super long key name as a test", cubeBytes);
//
//  IvTbl lftTri = {             // array of vert structs
//   {{-1.0, -1.0f, 0.0f},       //pos
//    {0.0f, 0.0f, -1.0f},       //norm
//    {1.0f, 1.0f, 1.0f, 1.0f},  //color
//    {0.0f, 0.0f}},             //texCoord
//
//   {{-0.17f, -1.0f, 0.0f},      //pos
//    {0.0f, 0.0f, -1.0f},        //norm
//    {1.0f, 1.0f, 1.0f, 1.0f},   //color
//    {0.0f, 0.0f}},              //texCoord
//
//   {{-0.58f, 1.0f, 0.0f},       //pos
//    {0.0f, 0.0f, -1.0f},        //norm
//    {1.0f, 1.0f, 1.0f, 1.0f},   //color
//    {0.0f, 0.0f}}               //texCoord
//  };
//  auto typenum    =  "IdxVerts";
//  lftTri("type")  =  *((u64*)typenum);
//  lftTri("mode")  =  (u64)GL_TRIANGLES;
//  tu32 ind        =  {0, 1, 2};
//  lftTri("IND")   =  &ind;
//  lftTri.flatten();
//
//  auto f = lftTri.memStart();
//
//  //db->put("tb left triangle", lftTri.memStart(), lftTri.sizeBytes() );
//}

//vd.camera.mouseDelta = vec2(0,0);
//vd.camera.btn2Delta  = vec2(0,0);
//glfwPollEvents();                                             // PollEvents must be done after zeroing out the deltas

//vd->ui.screen.mFocusPath.clear();
//
//dbKeys      = eraseMissingKeys(move(dbKeys), &vd->shapes);

//if( !kv.second.owner ){
//  it = shps->erase(it);
//  ++cnt;
//}else{
//  bool isKeyInDb = binary_search(ALL(dbKeys),vs, [](VerStr const& a, VerStr const& b){ return a.str < b.str; } );
//  if( !isKeyInDb ){
//    it = shps->erase(it);
//    ++cnt;
//  }else
//    ++it;
//}
//else
//++it;
//}

//for(auto key : dbKeys)                                              // add the buttons back and keep track of their indices
//{
//  auto b = new Button(vd->ui.keyWin, key.str);
//  int  i = vd->ui.keyWin->childIndex(b);
//  if(i > -1){ vd->ui.dbIdxs.push_back(i); }
//  b->setFlags(Button::ToggleButton);
//  b->setChangeCallback([k = key.str](bool pushed){ buttonCallback(k, pushed); });
//  b->setPushed(vd->shapes[key.str].active);
//  b->setFixedHeight(25);
//}

//for(auto const& kv : vd.shapes){
//}
//
//auto iter = vd.shapes.begin();
//while(iter != vd.shapes.end()){
//  if( !iter->second.owner )
//    iter = vd.shapes.erase(iter);
//  else
//    ++iter;
//}
//
// end of updates to shapes

//Shape  s  = tbl_to_shape(iv);
//
//key.v){
//
//Shape  s  = ivbuf_to_shape(iv, len);

//u32  version = 0;
//auto     len = db.len(vs.str.data(), (u32)vs.str.length(), &vlen, &version);          // todo: make ui64 as the input length
//
//vs.ver = version;
//
//s.version  = version;

//const tbl iv(ivbuf.data(), false, false);
//
//tbl  ivcpy = iv;
//auto     f = ivcpy.memStart();
//
//Shape  s   = tbl_to_shape(ivcpy);      PRINT_GL_ERRORS

//for(auto& kv : vd.shapes){
//  kv.second.active = true;
//}
//
//RenderShape(kv.second, glm::mat4() );
//
//glBegin(GL_POINTS);
//  glVertex2f(0,0);
//  glVertex2f(1,0);
//  glVertex2f(1,1);
//  glVertex2f(0,1);
//glEnd();


text:
module AwesomeUsps
  module ExpressMail
    def express_mail_label(orgin, destination, ounces, image_type, request_api = "ExpressMailLabelRequest", options={})
      request = express_mail_xml(request_api, orgin, destination, ounces, image_type, options)
      #YES THE API IS SO STUPID THAT WE MUST PASS WHAT TYPE OF MIME TYPE!
      gateway_commit(:express_mail_label, 'ExpressMailLabel', request, :ssl, image_type)
    end

    def canned_express_mail_label_test
      orgin = Location.new( :first_name=> "Craig", :last_name=>"Engle",  :address2 => "6406 Ivy Lane",  :state => 'MD', :city => 'Greenbelt', :zip5 => '20770', :phone => "2127658576")
      destination =Location.new( :firm_name=> "XYZ Corp.",  :address2 =>"1100 West Avenue", :address2 => "6406 Ivy Lane",  :state => 'MD', :city => 'Greenbelt', :zip5 => '20770')
      ounces = "50"
      image_type ="PDF"
      options = {}
      request_api = "ExpressMailLabelCertifyRequest"
      request = express_mail_xml(request_api, orgin, destination, ounces, image_type, options)
      gateway_commit(:express_mail_label_certify, 'ExpressMailLabelCertify', request, :ssl, image_type)
    end

    private
    def express_mail_xml(request_api, orgin, destination, ounces, image_type, options)
      xm = Builder::XmlMarkup.new
      xm.tag!("#{request_api}", "USERID"=>"#{@username}") do
        xm.Option
        xm.EMCAAccount
        xm.EMCAPassword
        xm.ImageParameters
        xm.FromFirstName(orgin.name)
        xm.FromLastName(orgin.last_name)
        xm.FromFirm(orgin.firm_name)
        xm.FromAddress1(orgin.address1) #Used for an apartment or suite number. Yes the API is a bit fucked.
        xm.FromAddress2(orgin.address2)
        xm.FromCity(orgin.city)
        xm.FromState(orgin.state)
        xm.FromZip5(orgin.zip5)
        xm.FromZip4(orgin.zip4)
        xm.FromPhone(orgin.phone)
        xm.ToFirstName(destination.name)
        xm.ToLastName(destination.last_name)
        xm.ToFirm(destination.firm_name)
        xm.ToAddress1(destination.address1)
        xm.ToAddress2(destination.address2)
        xm.ToCity(destination.city)
        xm.ToState(destination.state)
        xm.ToZip5(destination.zip5)
        xm.ToZip4(destination.zip4)
        xm.ToPhone(destination.phone)
        xm.WeightInOunces(ounces)
        xm.FlatRate(options[:flat_rate])
        xm.StandardizeAddress(options[:standardize_address])
        xm.WaiverOfSignature(options[:waiver_signature])
        xm.NoHoliday(options[:no_holiday])
        xm.NoWeekend(options[:no_weekend])
        xm.SeparateReceiptPage(options[:seperate])
        xm.POZipCode(options[:po_zip_code])
        xm.ImageType(image_type)
        xm.LabelDate(options[:labe_date])
        xm.SenderName(options[:sender_name])
        xm.SenderEMail(options[:sender_email])
        xm.RecipientName(options[:recipient_name])
        xm.RecipientEMail(options[:recipient_email])
      end
    end

    def parse_express_mail_label(xml, image_type)
      if image_type == "TIF"
        image_type = "image/tif"
      else
        image_type = "application/pdf"
      end
      parse = Hpricot.parse(xml)/:error
      if parse != []
        RAILS_DEFAULT_LOGGER.info "#{xml}"
        return (Hpricot.parse(xml)/:description).inner_html
      else
        label = Hpricot.parse(xml)/:emlabel
        postage =Hpricot.parse(xml)/:postage
        confirmation_number = Hpricot.parse(xml)/:emconfirmationnumber
        confirmation_number = "none" if confirmation_number == []
        return {:image_type => image_type, :confirmation_number => confirmation_number.inner_html, :postage => postage.inner_html, :label => label.inner_html}
      end
    end

  end
end

redpajama_set_name: RedPajamaGithub


text:
package openshift

import (
	"fmt"
	"os"

	"github.com/docker/machine/libmachine"
	"github.com/docker/machine/libmachine/provision"
	"github.com/minishift/minishift/cmd/minishift/state"
	"github.com/minishift/minishift/pkg/minikube/cluster"
	openshiftVersions "github.com/minishift/minishift/pkg/minishift/openshift/version"
	"github.com/minishift/minishift/pkg/util/os/atexit"
	"github.com/spf13/cobra"
)

// version command represent current running openshift version and available one.
var versionCmd = &cobra.Command{
	Use:   "version [command] [flags]",
	Short: "Prints the current running OpenShift version to the standard output.",
	Long:  `Prints the current running OpenShift version to the standard output.`,
	Run:   runVersion,
}

func runVersion(cmd *cobra.Command, args []string) {
	api := libmachine.NewClient(state.InstanceDirs.Home, state.InstanceDirs.Certs)
	defer api.Close()

	host, err := cluster.CheckIfApiExistsAndLoad(api)
	if err != nil {
		atexit.ExitWithMessage(1, nonExistentMachineError)
	}
	sshCommander := provision.GenericSSHCommander{Driver: host.Driver}

	version, err := openshiftVersions.GetOpenshiftVersion(sshCommander)
	if err != nil {
		atexit.ExitWithMessage(1, fmt.Sprintf("Error getting the OpenShift cluster version: %s", err.Error()))
	}
	fmt.Fprint(os.Stdout, version)
}

func init() {
	OpenShiftCmd.AddCommand(versionCmd)
}


text:
using System.Collections.Generic;
using System.Linq;
using Baseline;
using LamarCodeGeneration;
using LamarCodeGeneration.Model;
using Marten.Schema;
using Marten.Schema.Arguments;
using Marten.Storage;

namespace Marten.Internal.CodeGeneration
{
    public class BulkLoaderBuilder
    {
        private readonly DocumentMapping _mapping;
        private readonly string _tempTable;

        public BulkLoaderBuilder(DocumentMapping mapping)
        {
            _mapping = mapping;
            _tempTable = _mapping.TableName.Name + "_temp" ;
        }

        public GeneratedType BuildType(GeneratedAssembly assembly)
        {
            var upsertFunction = _mapping.Schema.Upsert;

            var arguments = orderArgumentsForBulkWriting(upsertFunction);

            var columns = arguments.Select(x => $"\\\"{x.Column}\\\"").Join(", ");

            var type = assembly.AddType($"{_mapping.DocumentType.Name.Sanitize()}BulkLoader",
                typeof(BulkLoader<,>).MakeGenericType(_mapping.DocumentType, _mapping.IdType));

            if (_mapping.IsHierarchy())
            {
                type.AllInjectedFields.Add(new InjectedField(typeof(DocumentMapping), "mapping"));
            }

            type.MethodFor("MainLoaderSql").Frames
                .Return($"COPY {_mapping.TableName.QualifiedName}({columns}) FROM STDIN BINARY");

            type.MethodFor("TempLoaderSql").Frames
                .Return($"COPY {_tempTable}({columns}) FROM STDIN BINARY");

            type.MethodFor(nameof(CopyNewDocumentsFromTempTable))
                .Frames.Return(CopyNewDocumentsFromTempTable());

            type.MethodFor(nameof(OverwriteDuplicatesFromTempTable))
                .Frames.Return(OverwriteDuplicatesFromTempTable());

            type.MethodFor(nameof(CreateTempTableForCopying))
                .Frames.Return(CreateTempTableForCopying().Replace("\"", "\\\""));

            var load = type.MethodFor("LoadRow");

            foreach (var argument in arguments)
            {
                argument.GenerateBulkWriterCode(type, load, _mapping);
            }

            var loadAsync = type.MethodFor("LoadRowAsync");

            foreach (var argument in arguments)
            {
                argument.GenerateBulkWriterCodeAsync(type, loadAsync, _mapping);
            }

            return type;
        }

        private static List<UpsertArgument> orderArgumentsForBulkWriting(UpsertFunction upsertFunction)
        {
            var arguments = upsertFunction.OrderedArguments().Where(x => !(x is CurrentVersionArgument)).ToList();
            // You need the document body to go last so that any metadata pushed into the document
            // is serialized into the JSON data
            var body = arguments.OfType<DocJsonBodyArgument>().Single();
            arguments.Remove(body);
            arguments.Add(body);
            return arguments;
        }

        public string CopyNewDocumentsFromTempTable()
        {
            var table = _mapping.Schema.Table;

            var storageTable = table.Identifier.QualifiedName;
            var columns = table.Columns.Where(x => x.Name != SchemaConstants.LastModifiedColumn).Select(x => $"\\\"{x.Name}\\\"").Join(", ");
            var selectColumns = table.Columns.Where(x => x.Name != SchemaConstants.LastModifiedColumn).Select(x => $"{_tempTable}.\\\"{x.Name}\\\"").Join(", ");

            return $"insert into {storageTable} ({columns}, {SchemaConstants.LastModifiedColumn}) (select {selectColumns}, transaction_timestamp() from {_tempTable} left join {storageTable} on {_tempTable}.id = {storageTable}.id where {storageTable}.id is null)";
        }

        public string OverwriteDuplicatesFromTempTable()
        {
            var table = _mapping.Schema.Table;
            var storageTable = table.Identifier.QualifiedName;

            var updates = table.Columns.Where(x => x.Name != "id" && x.Name != SchemaConstants.LastModifiedColumn)
                .Select(x => $"{x.Name} = source.{x.Name}").Join(", ");

            return $@"update {storageTable} target SET {updates}, {SchemaConstants.LastModifiedColumn} = transaction_timestamp() FROM {_tempTable} source WHERE source.id = target.id";
        }

        public string CreateTempTableForCopying()
        {
            return $"create temporary table {_tempTable} as select * from {_mapping.TableName.QualifiedName} limit 0";
        }

    }
}


text:
<?php

namespace PHPExiftool\Driver\Tag\Photoshop;

use JMS\Serializer\Annotation\ExclusionPolicy;
use PHPExiftool\Driver\AbstractTag;

/**
 * @ExclusionPolicy("all")
 */
class DisplayInfo extends AbstractTag
{

    protected $Id = 'mixed';

    protected $Name = 'DisplayInfo';

    protected $FullName = 'Photoshop::Main';

    protected $GroupName = 'Photoshop';

    protected $g0 = 'Photoshop';

    protected $g1 = 'Photoshop';

    protected $g2 = 'Image';

    protected $Type = '?';

    protected $Writable = false;

    protected $Description = 'Display Info';
}


text:
SYNONYM

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
J. Bot. Morot 11: 341 (1897)

#### Original name
Trametes grisea Pat., 1897

### Remarks
null


text:
require 'rubygems'
gem 'rspec'
require 'spec'

require 'mocha'
require 'fileutils'

DAEMON_ENV  = "test"
DAEMON_ROOT = "#{File.dirname(__FILE__)}/../tmp"

$:.unshift( File.dirname(__FILE__) + '/../lib' )
require 'daemon_kit'

Spec::Runner.configure do |config|
  # == Mock Framework
  #
  # RSpec uses it's own mocking framework by default. If you prefer to
  # use mocha, flexmock or RR, uncomment the appropriate line:
  #
  config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # setup a fake daemon_root
  config.before(:all) { File.directory?( DAEMON_ROOT ) ? FileUtils.rm_rf("#{DAEMON_ROOT}/*") : FileUtils.mkdir_p( DAEMON_ROOT ) }
  config.after(:all) { FileUtils.rm_rf("#{DAEMON_ROOT}/*") }
end


text:
class Countryregionisation < ActiveRecord::Base
  attr_accessible :country_id, :region_id
  belongs_to :country
  belongs_to :region
end


text:
package com.intellij.psi.impl.compiled;

import com.intellij.lang.PsiBuilder;
import com.intellij.lang.java.parser.JavaParser;
import com.intellij.lang.java.parser.JavaParserUtil;
import com.intellij.lang.java.lexer.JavaLexer;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.DummyHolder;
import com.intellij.psi.impl.source.DummyHolderFactory;
import com.intellij.psi.impl.source.JavaDummyElement;
import com.intellij.psi.impl.source.SourceTreeToPsiMap;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.lang.JavaVersion;
import consulo.internal.org.objectweb.asm.Opcodes;
import consulo.logging.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
 * @author ven
 */
public class ClsParsingUtil
{
	private static final Logger LOG = Logger.getInstance(ClsParsingUtil.class);

	private static final JavaParserUtil.ParserWrapper ANNOTATION_VALUE = new JavaParserUtil.ParserWrapper()
	{
		@Override
		public void parse(final PsiBuilder builder)
		{
			JavaParser.INSTANCE.getDeclarationParser().parseAnnotationValue(builder);
		}
	};

	private ClsParsingUtil()
	{
	}

	public static PsiExpression createExpressionFromText(@Nonnull String exprText, @Nonnull PsiManager manager, @Nonnull ClsElementImpl parent)
	{
		PsiJavaParserFacade parserFacade = JavaPsiFacade.getInstance(manager.getProject()).getParserFacade();
		try
		{
			PsiExpression expr = parserFacade.createExpressionFromText(exprText, null);
			return psiToClsExpression(expr, parent);
		}
		catch(IncorrectOperationException e)
		{
			LOG.error(e);
			return null;
		}
	}

	public static PsiAnnotationMemberValue createMemberValueFromText(@Nonnull String text, @Nonnull PsiManager manager, @Nonnull ClsElementImpl parent)
	{
		LanguageLevel level = PsiUtil.getLanguageLevel(parent);
		DummyHolder holder = DummyHolderFactory.createHolder(manager, new JavaDummyElement(text, ANNOTATION_VALUE, level), null);
		PsiElement element = SourceTreeToPsiMap.treeElementToPsi(holder.getTreeElement().getFirstChildNode());
		if(!(element instanceof PsiAnnotationMemberValue))
		{
			LOG.error("Could not parse initializer:'" + text + "'");
			return null;
		}
		return getMemberValue(element, parent);
	}

	public static PsiAnnotationMemberValue getMemberValue(@Nonnull PsiElement element, @Nonnull ClsElementImpl parent)
	{
		if(element instanceof PsiExpression)
		{
			return psiToClsExpression((PsiExpression) element, parent);
		}
		else if(element instanceof PsiArrayInitializerMemberValue)
		{
			PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue) element).getInitializers();
			PsiAnnotationMemberValue[] clsInitializers = new PsiAnnotationMemberValue[initializers.length];
			ClsArrayInitializerMemberValueImpl arrayValue = new ClsArrayInitializerMemberValueImpl(parent, clsInitializers);
			for(int i = 0; i < initializers.length; i++)
			{
				clsInitializers[i] = getMemberValue(initializers[i], arrayValue);
			}
			return arrayValue;
		}
		else if(element instanceof PsiAnnotation)
		{
			final PsiAnnotation psiAnnotation = (PsiAnnotation) element;
			final PsiJavaCodeReferenceElement referenceElement = psiAnnotation.getNameReferenceElement();
			assert referenceElement != null : psiAnnotation;
			final String canonicalText = referenceElement.getText(); // class file has FQNs
			return new ClsAnnotationValueImpl(parent)
			{
				@Override
				protected ClsJavaCodeReferenceElementImpl createReference()
				{
					return new ClsJavaCodeReferenceElementImpl(this, canonicalText);
				}

				@Override
				protected ClsAnnotationParameterListImpl createParameterList()
				{
					PsiNameValuePair[] psiAttributes = psiAnnotation.getParameterList().getAttributes();
					return new ClsAnnotationParameterListImpl(this, psiAttributes);
				}

				@Override
				public PsiAnnotationOwner getOwner()
				{
					return (PsiAnnotationOwner) getParent();
				}
			};
		}
		else
		{
			LOG.error("Unexpected source element for annotation member value: " + element);
			return null;
		}
	}

	static PsiExpression psiToClsExpression(@Nonnull PsiExpression expr, @Nonnull ClsElementImpl parent)
	{
		if(expr instanceof PsiLiteralExpression)
		{
			boolean forDecompiling = ((ClsFileImpl) parent.getContainingFile()).isForDecompiling();
			PsiType type = forDecompiling ? PsiType.NULL : expr.getType();
			Object value = forDecompiling ? null : ((PsiLiteralExpression) expr).getValue();
			return new ClsLiteralExpressionImpl(parent, expr.getText(), type, value);
		}

		if(expr instanceof PsiPrefixExpression)
		{
			PsiJavaToken sign = ((PsiPrefixExpression) expr).getOperationSign();
			PsiExpression operand = ((PsiPrefixExpression) expr).getOperand();
			if(operand == null)
			{
				LOG.error("Invalid prefix expression: " + expr + " [" + expr.getText() + "]");
				return null;
			}
			return new ClsPrefixExpressionImpl(parent, sign, operand);
		}

		if(expr instanceof PsiClassObjectAccessExpression)
		{
			String exprText = expr.getText();
			if(StringUtil.endsWith(exprText, ".class"))
			{
				String classText = exprText.substring(0, exprText.length() - 6);
				return new ClsClassObjectAccessExpressionImpl(parent, classText);
			}
		}

		if(expr instanceof PsiReferenceExpression)
		{
			return new ClsReferenceExpressionImpl(parent, (PsiReferenceExpression) expr);
		}

		if(expr instanceof PsiBinaryExpression)
		{
			PsiJavaToken sign = ((PsiBinaryExpression) expr).getOperationSign();
			PsiExpression left = ((PsiBinaryExpression) expr).getLOperand();
			PsiExpression right = ((PsiBinaryExpression) expr).getROperand();
			if(right == null)
			{
				LOG.error("Invalid binary expression: " + expr + " [" + expr.getText() + "]");
				return null;
			}
			return new ClsBinaryExpressionImpl(parent, sign, left, right);
		}

		if(((ClsFileImpl) parent.getContainingFile()).isForDecompiling())
		{
			return new ClsLiteralExpressionImpl(parent, expr.getText(), PsiType.NULL, null);
		}

		PsiConstantEvaluationHelper evaluator = JavaPsiFacade.getInstance(expr.getProject()).getConstantEvaluationHelper();
		Object value = evaluator.computeConstantExpression(expr);
		if(value != null)
		{
			return new ClsLiteralExpressionImpl(parent, expr.getText(), expr.getType(), value);
		}

		LOG.error("Unable to compute expression value: " + expr + " [" + expr.getText() + "]");
		return null;
	}

	public static boolean isJavaIdentifier(@Nonnull String identifier, @Nonnull LanguageLevel level)
	{
		return StringUtil.isJavaIdentifier(identifier) && !JavaLexer.isKeyword(identifier, level);
	}

	@Nullable
	public static JavaSdkVersion getJdkVersionByBytecode(int major)
	{
		if(major == Opcodes.V1_1 || major == 45)
		{
			return JavaSdkVersion.JDK_1_1;
		}
		if(major >= 46)
		{
			JavaVersion version = JavaVersion.compose(major - 44);  // 46 = 1.2, 47 = 1.3 etc.
			return JavaSdkVersion.fromJavaVersion(version);
		}
		return null;
	}
}


text:
package com.stubbornjava.common;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Stopwatch;

public class Timers {
    private static final Logger logger = LoggerFactory.getLogger(Timers.class);

    private Timers() {}

    public static void time(String message, Runnable runnable) {
        Stopwatch sw = Stopwatch.createStarted();
        try {
            logger.info("{}", message);
            runnable.run();
        } catch (Exception ex) {
            logger.warn("Exception in runnable", ex);
            throw ex;
        } finally {
            logger.info("{} took {}ms", message, sw.elapsed(TimeUnit.MILLISECONDS));
        }
    }

}


text:
function [chisquare pValue] = lrt(m1, m2, df)

%   This function performs model comparison of M2 to M1 by calculating a
%   likelihood ratio test for each voxel in an fmri data object.  Will take
%   the difference between models for each subject multiply by 2 and then
%   sum the differences.  DF should reflect the difference in the number of
%   parameters between the two models (i.e., number of subjects in Model 1
%   + number of free parameters in Model 1 - the same in model 2)
%
% Usage:
% -------------------------------------------------------------------------
% [chisquare pValue] = LikelihoodRatioTest(m1Dat, m2dat, df)
%
% Author and copyright information:
% -------------------------------------------------------------------------
%     Copyright (C) 2013  Luke Chang
%
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
%
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
%
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
% Inputs:
% -------------------------------------------------------------------------
% m1Dat         Data object containing [vox x subjects] log likelihood values
%               from Model 1
%
% m2Dat         Data object containing [vox x subjects] log likelihood values
%               from Model 2
%
% df            Degrees of freedom = number of parameters in Model 2 minus number of
%               parameters in Model 1
%
% Outputs:
% -------------------------------------------------------------------------
% chisquare     fmri_data object containing chi square values
%
% pValue        fmri_data object containing p - Values
%
% Examples:
% -------------------------------------------------------------------------
% To calculate difference between 30 subjects where m1 = 31 params and m2 =
% 93 params.
%
% [chisquare pValue] = LikelihoodRatioTest(m1, m2, 62)
%
% -------------------------------------------------------------------------

% Programmers' notes:
% 3/13/13 : LC : removed values below df.  p-values are meaningly according
% to Matt Jones.

chisquare = sum((2 * (m2 - m1)));
pValue = chi2pdf(chisquare, df);

% %Remove lower tail p - values
% pValue.dat(chisquare.dat < df) = nan;
% chisquare.dat(chisquare.dat < df) = nan;


text:
var util = require('util');
    should = require('should'),
    JSUS = require('./../jsus').JSUS;

describe('JSUS general tests: ', function(){

   // TODO
});


text:
'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');

const serviceAccount = require('./service-account.json');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`
});

exports.create_token = functions.https.onRequest((req, res) => {
    console.info('req.body', req.body);
    let user = req.body.user;

    if (user == undefined) {
        res.status(200).send({
            msg: 'No user sent',
            body: req.body
        });
    } else {
        let uid = user.provider + '-' + user.id;

        admin.auth().createCustomToken(uid, user).then(function (customToken) {
            res.status(200).send({
                token: customToken,
                uid: uid,
                user: user
            });
        }).catch(function (error) {
            res.status(200).send({
                msg: error.message,
                error: error
            });
        });
    }
});


text:
require File.join(File.dirname(__FILE__), "/test_helper")

class ExtraSanitizeTest < Test::Unit::TestCase

  def test_should_sanitize_only_specified_columns
    article = Article.new(:title => "~*<some title>\"'"'"?¿", :body => "some body~~~~")
    article.valid?
    assert_equal article.title, "some title"
  end

  def test_should_sanitize_column_name_with_percentage_in_it
    article = Article.new(:title => "%%%some %%%title%%%", :body => "some body~~~~")
    article.valid?
    assert_equal article.title, "some title"
  end

  def test_should_sanitize_column_name_with_forward_slash_in_it
    article = Article.new(:title => "some ///title///", :body => "some body~~~~")
    article.valid?
    assert_equal article.title, "some title"
  end

  def test_should_not_sanitize_excluded_columns
    article = Article.new(:title => "~*<some title>\"'"'"?¿", :body => "some body~~~~")
    article.valid?
    assert_equal article.body, "some body~~~~"
  end

  def test_should_not_sanitize_if_not_included
    comment = Comment.new(:title => "some title~*<>\"'"'"?¿", :description => "some body~~~~")

    comment.valid?
    assert_equal comment.title, "some title~*<>\"'"'"?¿"
    assert_equal comment.description, "some body~~~~"
  end

  def test_should_sanitize_all_string_text_columns
    post = Post.new(:title => "<some title>\"'"'"?¿", :description => ""some~~~~ 'body'~~~~"")
    post.valid?
    assert_equal post.title, "some title"
    assert_equal post.description, "some body"
  end

  def test_should_replace_default_reg_exp_to_sanitize
    tag = Tag.new(:name => "<some ~title>\"'"'"?¿")
    tag.valid?

    assert_equal(tag.name, "<some title>\"'"'"")
  end
end


text:
package com.mastertheboss;

import java.net.InetAddress;

import com.mastertheboss.domain.IPAddress;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IPAddressController {
    private int counter;

    @RequestMapping(value = "/ip", method = RequestMethod.GET)
    public IPAddress ipaddress() throws Exception {
        return new IPAddress(++counter, InetAddress.getLocalHost().getHostAddress());
    }
}


text:
package org.apache.jena.riot.system;

import java.util.concurrent.ExecutionException ;

import org.apache.jena.ext.com.google.common.cache.Cache ;
import org.apache.jena.atlas.lib.cache.CacheInfo ;
import org.apache.jena.datatypes.RDFDatatype ;
import org.apache.jena.datatypes.xsd.XSDDatatype ;
import org.apache.jena.ext.com.google.common.cache.CacheBuilder ;
import org.apache.jena.ext.com.google.common.cache.CacheStats ;
import org.apache.jena.graph.Node ;
import org.apache.jena.riot.RiotException ;
import org.apache.jena.riot.lang.LabelToNode ;
import org.apache.jena.sparql.graph.NodeConst ;

/** Adds some caching of created nodes - the caching is tuned to RIOT parser usage */
public class FactoryRDFCaching extends FactoryRDFStd {
    public static final int DftNodeCacheSize = 5000 ;

    // Control the setup - for one thread; start size = 50% of full size, no stats
    private final Cache<String, Node> cache ;

    public FactoryRDFCaching() {
        this(DftNodeCacheSize) ;
    }

    public FactoryRDFCaching(int cacheSize) {
        super() ;
        cache = setCache(cacheSize) ;
    }

    public FactoryRDFCaching(LabelToNode labelMapping) {
        this(DftNodeCacheSize, labelMapping) ;
    }

    public FactoryRDFCaching(int cacheSize, LabelToNode labelMapping) {
        super(labelMapping) ;
        cache = setCache(cacheSize) ;
    }

    private Cache<String, Node> setCache(int cacheSize) {
        return CacheBuilder.newBuilder()
            .maximumSize(cacheSize)
            .initialCapacity(cacheSize/2)
            //.recordStats()
            .concurrencyLevel(1)
            .build() ;
    }

    @Override
    public Node createURI(String uriStr) {
        try {
            return cache.get(uriStr, ()->RiotLib.createIRIorBNode(uriStr)) ;
        }
        catch (ExecutionException e) {
            throw new RiotException("Execution exception filling cache <"+uriStr+">", e) ;
        }
    }

    // A few constants

    @Override
    public Node createTypedLiteral(String lexical, RDFDatatype datatype) {
        if ( XSDDatatype.XSDinteger.equals(datatype) ) {
            switch(lexical) {
                case "0" : return NodeConst.nodeZero ;
                case "1" : return NodeConst.nodeOne ;
                case "2" : return NodeConst.nodeTwo ;
                case "-1" : return NodeConst.nodeMinusOne ;
            }
            // fallthrough.
        } else if ( XSDDatatype.XSDboolean.equals(datatype) ) {
            switch(lexical) {
                case "true" : return NodeConst.nodeTrue ;
                case "false" : return NodeConst.nodeFalse ;
            }
            // fallthrough.
        }
        return super.createTypedLiteral(lexical, datatype) ;
    }

    @Override
    public Node createStringLiteral(String lexical) {
        if ( lexical.isEmpty() )
            return NodeConst.emptyString ;
        return super.createStringLiteral(lexical) ;
    }

    public CacheInfo stats() {
        CacheStats stats = cache.stats() ;
        if ( stats.missCount() == 0 && stats.hitCount() == 0 )
            // Stats not enabled - all counts zero.
            return null ;
        return new CacheInfo(DftNodeCacheSize, stats) ;
    }
}


text:
package bg.softuni.lebank.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.springframework.stereotype.Repository;

import bg.softuni.lebank.interfaces.OperationsStorage;

@Repository
public class OperationsDao implements OperationsStorage {

	@Override
	public Boolean addOperation(
			String id,
			long accoungNo,
			String operation,
			String amount,
			String currency,
			String performedBy) {

		String sql = "INSERT INTO operations (id, account_no, operation, amount, currency, performed_by) VALUES (?,?,?,?,?,?)";
		try (
				Connection connection = DbConnection.getConnection();
				PreparedStatement statement = connection.prepareCall(sql);) {
			statement.setString(1, id);
			statement.setLong(2, accoungNo);
			statement.setString(3, operation);
			statement.setString(4, amount);
			statement.setString(5, currency);
			statement.setString(6, performedBy);

			statement.executeQuery();

		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}

		return true;
	}
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE locale SYSTEM "../../../../../lib/pkp/dtd/locale.dtd">

<locale name="pt_BR" full_name="Português do Brasil">

	<message key="plugins.generic.phpmv.displayName">Análise de tráfego phpMyVisites</message>
	<message key="plugins.generic.phpmv.description"><![CDATA[Integre o sistema com o phpMyVisites, uma ferramenta livre e gratuita de análise de tráfego Web. Exige a instalação prévia do phpMyVisites. Saiba mais em phpMyVisites.]]></message>

	<message key="plugins.generic.phpmv.manager.settings">Configurações</message>
	<message key="plugins.generic.phpmv.manager.phpmvSettings">Configurações phpMyVisites</message>
	<message key="plugins.generic.phpmv.manager.settings.description"><![CDATA[
Com este plugin habilitado, o phpMyVisites pode ser usado para coletar informações e analisar o tráfego de uso do portal para esta revista. O plugin exige a instalação prévia do phpMyVisites. Saiba mais em phpMyVisites.
]]></message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvUrl">URL phpMyVisites</message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvUrlInstructions">A URL completa da instalação do phpMyVisites (ex.: http://myserver.net/phpmv).</message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvUrlRequired">Informe uma URL válida. Inclua o protocolo http:// no início.</message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvSiteId">Número do perfil do portal</message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvSiteIdInstructions"><![CDATA[Dentro do phpMyVisites, clique em Administração -> Modificar Portal (Administration->Modify site). O número do perfil do portal é exibido próximo ao seu nome.]]></message>
	<message key="plugins.generic.phpmv.manager.settings.phpmvSiteIdRequired">Informe o número do perfil do portal.</message>

</locale>


text:
<?php
    include("../TPSBIN/functions.php");
    include("../TPSBIN/db_connect.php");

    // Establish Session
    sec_session_start();

    // GET data
?>
<!DOCTYPE HTML>

        <meta charset="utf-8">
        <meta name="description" content="Login for TPS Radio System">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="author" content="James Oliver">
        <title>TPS Broadcast - Playlist Update</title>

        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">

        <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">

    <?php include "../TPSBIN/bs_menu.php"?>

Playlist Update

File To Upload

<form action="upload_playlist.php" method="post" onsubmit="submitted();"
                                                  enctype="multipart/form-data">
                            <fieldset title="XLS / XLSX Playlist Update">

This requires your playlist XLS file in the supported (supplied) format. This is likely the same file as your playlist update file

                                Filename:
                                <input type="file" name="file" id="file" required>

                                Library Already Updated
                                <input type="checkbox" id="library" checked required/>**This needs to be checked currently... please check it

                                <fieldset title="Range">
                                    Start Row
                                    <input type="number" name="START" step="1" min="1" id="start">

                                    End Row (blank for all)
                                    <input type="number" name="END" step="1" min="1" id="end">

                                </fieldset>
                                <input type="submit" name="submit" value="Submit">
                            </fieldset>
                        </form>

Processing Please Wait...

<progress></progress>

                    RUNTIME: 00:00


text: Remote Linux ObjFW Xcode Template


text:
<html>
<head>
<script>

function state_changed(xhr) {
  if (xhr.readyState == 4)
    window.location.href = "password_xhr_done.html";
}

function send_xhr() {
  var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() { state_changed(xhr); };
  xhr.open("GET", "password_xhr_submit.html", true);
  xhr.send(null);
}

</script>
</head>
<body>
<form action="password_xhr_submit.html" onsubmit="send_xhr(); return false;"
      id="testform">
  <input type="text" id="username_field" name="username_field">
  <input type="password" id="password_field" name="password_field">
  <input type="submit" id="submit_button" name="submit_button">
</form>
</body>
</html>


text:
<?php

namespace Redsys\Tests\Api;

use Redsys\Api\Date;

class DateTest extends \PHPUnit_Framework_TestCase
{
    public function testGetValueShouldReturnValue()
    {
        $date = new Date("2015-11-21");
        $dateTime = \DateTime::createFromFormat("Y-m-d H:i:s", "2015-11-21 00:00:00");

        $this->assertEquals($dateTime, $date->getValue());
    }

    public function testToStringShouldReturnString()
    {
        $date = new Date("2015-11-21");

        $this->assertEquals("2015-11-21", (string)$date);
    }

    /**
     * @expectedException \LengthException
     */
    public function testTooLongValueShouldThrowException()
    {
        new Date("2015-11-21 12:00:00");
    }

    /**
     * @dataProvider invalidValues
     * @expectedException \UnexpectedValueException
     */
    public function testInvalidDateShouldThrowException($value)
    {
        new Date($value);
    }

    public function invalidValues()
    {
        return array(
            array("lorem"),
            array("21/11/2015"),
        );
    }
}


text:
'use strict';

var should = require('should');
var util = require('util');
var _ = require('underscore');

var testUtils = require('../../../util/util');
var CLITest = require('../../../framework/arm-cli-test');
var NetworkTestUtil = require('../../../util/networkTestUtil');
var networkUtil = new NetworkTestUtil();

var testPrefix = 'arm-network-vpn-gateway-tests',
  groupName = 'xplat-test-vpn-gateway1',
  location;

var gatewayProp = {
  name: 'test-vpn-gateway',
  vnetName: 'test-vnet',
  subnetName: 'GatewaySubnet',
  vnetAddressPrefix: '10.1.0.0/16',
  subnetAddressPrefix: '10.1.0.0/28',
  publicIpName: 'test-ip',
  gatewayType: 'Vpn',
  bgpSettingsAsn: 65010,
  bgpPeeringAddress: '10.12.255.30',
  bgpPeerWeight: 0,
  newBgpSettingsAsn: 64999,
  newBgpPeerWeight: 2,
  vpnType: 'RouteBased',
  sku: 'Standard',
  enableBgp: false,
  addressPrefix: '10.0.0.0/24',
  tags: networkUtil.tags,
  newTags: networkUtil.newTags
};

var rootCertProp = {
  name: 'test-root-cert',
  path: 'test/data/root-cert.pem'
};

var revokedCertProp = {
  name: 'test-revoked-cert',
  thumbprint: '633EBFFBD01B6049D51E3CF059CFD940C8CE5780'
};

var localGatewayProp = {
  name: 'test-local-gateway',
  gatewayIpAddress: '10.0.0.0',
  addressPrefix: '10.0.0.0/24',
  tags: networkUtil.tags
};

var requiredEnvironment = [{
  name: 'AZURE_VM_TEST_LOCATION',
  defaultValue: 'westeurope'
}];

describe('arm', function () {
  describe('network', function () {
    var suite, retry = 5, hour = 60 * 60000;

    before(function (done) {
      suite = new CLITest(this, testPrefix, requiredEnvironment);
      suite.setupSuite(function () {
        location = process.env.AZURE_VM_TEST_LOCATION;
        groupName = suite.isMocked ? groupName : suite.generateId(groupName, null);

        gatewayProp.group = groupName;
        gatewayProp.location = location;
        gatewayProp.name = suite.isMocked ? gatewayProp.name : suite.generateId(gatewayProp.name, null);
        gatewayProp.vnetName = suite.isMocked ? gatewayProp.vnetName : suite.generateId(gatewayProp.vnetName, null);
        gatewayProp.publicIpName = suite.isMocked ? gatewayProp.publicIpName : suite.generateId(gatewayProp.publicIpName, null);

        rootCertProp.group = groupName;
        rootCertProp.gatewayName = gatewayProp.name;

        revokedCertProp.group = groupName;
        revokedCertProp.gatewayName = gatewayProp.name;

        localGatewayProp.group = groupName;
        localGatewayProp.location = location;
        localGatewayProp.name = suite.isMocked ? localGatewayProp.name : suite.generateId(localGatewayProp.name, null);

        done();
      });
    });
    after(function (done) {
      // Note: VPN operations are long running and takes about 20-30 minutes to complete,
      // so we need to increase mocha timeout a lot
      this.timeout(hour);
      networkUtil.deleteGroup(groupName, suite, function () {
        suite.teardownSuite(done);
      });
    });
    beforeEach(function (done) {
      suite.setupTest(done);
    });
    afterEach(function (done) {
      suite.teardownTest(done);
    });

    describe('vpn-gateway', function () {

      /*
        Note: VPN operations are long running and takes about 20-30 minutes to complete,
        so we need to increase mocha timeout a lot.
      */
      this.timeout(hour);

      it('create should create vpn gateway', function (done) {
        networkUtil.createGroup(groupName, location, suite, function () {
          networkUtil.createVpnGateway(gatewayProp, suite, function () {
            done();
          });
        });
      });
      it('set should modify vpn gateway', function (done) {
        var cmd = util.format('network vpn-gateway set -g {group} -n {name} -c {addressPrefix} ' +
          '-a {newBgpSettingsAsn} -j {newBgpPeerWeight} -t {newTags} --json').formatArgs(gatewayProp);

        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          vpnGateway.name.should.equal(gatewayProp.name);
          vpnGateway.ipConfigurations.length.should.equal(1);
          vpnGateway.bgpSettings.asn.should.equal(gatewayProp.newBgpSettingsAsn);
          vpnGateway.bgpSettings.bgpPeeringAddress.should.equal(gatewayProp.bgpPeeringAddress);
          vpnGateway.bgpSettings.peerWeight.should.equal(gatewayProp.newBgpPeerWeight);
          var ipConfig = vpnGateway.ipConfigurations[0];
          var vpnConfig = vpnGateway.vpnClientConfiguration;
          vpnConfig.vpnClientAddressPool.addressPrefixes[0].should.equal(gatewayProp.addressPrefix);
          networkUtil.shouldAppendTags(vpnGateway);
          networkUtil.shouldBeSucceeded(vpnGateway);
          done();
        });
      });
      it('set should attach default site to vpn gateway using site id', function (done) {
        networkUtil.createLocalGateway(localGatewayProp, suite, function (localGateway) {
          var cmd = 'network vpn-gateway set -g {group} -n {name} -i {1} --json'.formatArgs(gatewayProp, localGateway.id);
          testUtils.executeCommand(suite, retry, cmd, function (result) {
            result.exitStatus.should.equal(0);
            var vpnGateway = JSON.parse(result.text);
            vpnGateway.gatewayDefaultSite.id.should.equal(localGateway.id);
            networkUtil.shouldBeSucceeded(vpnGateway);
            done();
          });
        });
      });
      it('set should detach default site from vpn gateway using site id', function (done) {
        var cmd = 'network vpn-gateway set -g {group} -n {name} -i --json'.formatArgs(gatewayProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          vpnGateway.should.not.have.property('gatewayDefaultSite');
          networkUtil.shouldBeSucceeded(vpnGateway);
          done();
        });
      });
      it('set should attach default site to vpn gateway using site name', function (done) {
        var cmd = 'network vpn-gateway set -g {group} -n {name} -d {1} --json'.formatArgs(gatewayProp, localGatewayProp.name);
        testUtils.executeCommand(suite, retry, cmd, function (result) {

          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          vpnGateway.gatewayDefaultSite.id.should.containEql(localGatewayProp.name);
          networkUtil.shouldBeSucceeded(vpnGateway);
          done();
        });
      });
      it('set should detach default site from vpn gateway using site name', function (done) {
        var cmd = 'network vpn-gateway set -g {group} -n {name} -d --json'.formatArgs(gatewayProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          vpnGateway.should.not.have.property('gatewayDefaultSite');
          networkUtil.shouldBeSucceeded(vpnGateway);
          done();
        });
      });
      it('root-cert create should attach root certificate to vpn gateway', function (done) {
        var cmd = 'network vpn-gateway root-cert create -g {group} -n {gatewayName} -c {name} -f {path} --json'
          .formatArgs(rootCertProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          var rootCertificates = vpnGateway.vpnClientConfiguration.vpnClientRootCertificates;
          rootCertificates.length.should.equal(1);
          rootCertificates[0].name.should.equal(rootCertProp.name);
          done();
        });
      });
      it('root-cert delete should detach root certificate from vpn gateway', function (done) {
        var cmd = 'network vpn-gateway root-cert delete -g {group} -n {gatewayName} -c {name} --quiet --json'
          .formatArgs(rootCertProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          var rootCertificates = vpnGateway.vpnClientConfiguration.vpnClientRootCertificates;
          rootCertificates.length.should.equal(0);
          done();
        });
      });
      it('revoked-cert create should attach revoked certificate to vpn gateway', function (done) {
        var cmd = 'network vpn-gateway revoked-cert create -g {group} -n {gatewayName} -c {name} -f {thumbprint} --json'
          .formatArgs(revokedCertProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          var revokedCertificates = vpnGateway.vpnClientConfiguration.vpnClientRevokedCertificates;
          revokedCertificates.length.should.equal(1);
          revokedCertificates[0].name.should.equal(revokedCertProp.name);
          done();
        });
      });
      it('revoked-cert delete should detach revoked certificate from vpn gateway', function (done) {
        var cmd = 'network vpn-gateway revoked-cert delete -g {group} -n {gatewayName} -c {name} --quiet --json'
          .formatArgs(revokedCertProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          var revokedCertificates = vpnGateway.vpnClientConfiguration.vpnClientRevokedCertificates;
          revokedCertificates.length.should.equal(0);
          done();
        });
      });
      it('show should display details of vpn gateway', function (done) {
        var cmd = 'network vpn-gateway show -g {group} -n {name} --json'.formatArgs(gatewayProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var vpnGateway = JSON.parse(result.text);
          vpnGateway.name.should.equal(gatewayProp.name);
          done();
        });
      });
      it('list should display all vpn gateways in resource group', function (done) {
        var cmd = 'network vpn-gateway list -g {group} --json'.formatArgs(gatewayProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);
          var gateways = JSON.parse(result.text);
          _.some(gateways, function (gateway) {
            return gateway.name === gatewayProp.name;
          }).should.be.true;
          done();
        });
      });
      it('delete should delete vpn gateway', function (done) {
        var cmd = 'network vpn-gateway delete -g {group} -n {name} --quiet --json'.formatArgs(gatewayProp);
        testUtils.executeCommand(suite, retry, cmd, function (result) {
          result.exitStatus.should.equal(0);

          cmd = 'network vpn-gateway show -g {group} -n {name} --json'.formatArgs(gatewayProp);
          testUtils.executeCommand(suite, retry, cmd, function (result) {
            result.exitStatus.should.equal(0);
            var vpnGateway = JSON.parse(result.text);
            vpnGateway.should.be.empty;
            done();
          });
        });
      });
    });
  });
});


text:
Recent Activity

Langdon's Birthday

										Will be 23 on April 24th

Tasks Progress

 Custom Template Design 70%

						Stats Tab Content

						<form method="post">

General Settings

								 Report panel usage
									<input type="checkbox" class="pull-right" checked />

									Some information about this general settings option

						</form>


text:
package com.cloudera.oryx.common.iterator;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Iterator;

import com.cloudera.oryx.common.io.IOUtils;

/**
 * Iterable representing the lines of a text file. It can produce an {@link Iterator} over those lines. This
 * assumes the text file's lines are delimited in a manner consistent with how {@link java.io.BufferedReader}
 * defines lines.
 *
 * This class will uncompress files that end in .zip or .gz accordingly, too.
 *
 * @author Sean Owen
 */
public final class FileLineIterable implements Iterable<String> {

  private final Reader reader;

  /**
   * Creates a {@code FileLineIterable} over a given {@link File}, assuming a UTF-8 encoding.
   */
  public FileLineIterable(File file) throws IOException {
    this.reader = IOUtils.openReaderMaybeDecompressing(file);
  }

  /**
   * Creates a {@code FileLineIterable} over a given stream of characters from a {@link Reader},
   * assuming a UTF-8 encoding.
   */
  public FileLineIterable(Reader reader) {
    this.reader = reader;
  }

  @Override
  public Iterator<String> iterator() {
    return new FileLineIterator(reader);
  }

}


text:
import {registerEditor} from './../editors.js';
import {BaseEditor} from './_baseEditor.js';
import * as dom from './../dom.js';

/**
 * @private
 * @editor CheckboxEditor
 * @class CheckboxEditor
 */
class CheckboxEditor extends BaseEditor {
  beginEditing() {
    let checkbox = this.TD.querySelector('input[type="checkbox"]');

    if (!dom.hasClass(checkbox, 'htBadValue')) {
      checkbox.click();
    }
  }

  finishEditing() {}
  init() {}
  open() {}
  close() {}
  getValue() {}
  setValue() {}
  focus() {}
}

export {CheckboxEditor};

registerEditor('checkbox', CheckboxEditor);


text:
/* Last changed Time-stamp: <> */
/*             Global variables for Distance-Package */

int  edit_backtrack = 0;  /* calculate aligned representation */

char *aligned_line[4];    /* containes the aligned string representations */

int  cost_matrix = 0;     /* 0 for usual costs, 1 for Shapiro's costs */


text:
FROM node:current
COPY . /typescript
WORKDIR /typescript
RUN npm ci
RUN npx hereby configure-insiders && npx hereby LKG && npx hereby clean && npm pack .


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

<TITLE>
Uses of Class org.apache.avro.util.Utf8 (Avro 1.4.1 API)
</TITLE>

<META NAME="date" CONTENT="2010-10-08">

<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Uses of Class
org.apache.avro.util.Utf8

Packages that use Utf8

org.apache.avro.io
Input/output utilities.

org.apache.avro.mapred
Run Hadoop MapReduce jobs over
Avro data, with map and reduce functions written in Java.

org.apache.avro.util
Common utility classes.

Uses of Utf8 in org.apache.avro.io

Methods in org.apache.avro.io that return Utf8

 Utf8
JsonDecoder.readString(Utf8 old)

 Utf8
BinaryDecoder.readString(Utf8 old)

 Utf8
ValidatingDecoder.readString(Utf8 old)

abstract  Utf8
Decoder.readString(Utf8 old)

          Reads a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).

Methods in org.apache.avro.io with parameters of type Utf8

 Utf8
JsonDecoder.readString(Utf8 old)

 Utf8
BinaryDecoder.readString(Utf8 old)

 Utf8
ValidatingDecoder.readString(Utf8 old)

abstract  Utf8
Decoder.readString(Utf8 old)

          Reads a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).

 void
JsonEncoder.writeString(Utf8 utf8)

 void
ValidatingEncoder.writeString(Utf8 utf8)

 void
BinaryEncoder.writeString(Utf8 utf8)

 void
BlockingBinaryEncoder.writeString(Utf8 utf8)

abstract  void
Encoder.writeString(Utf8 utf8)

          Write a Unicode character string.

Uses of Utf8 in org.apache.avro.mapred

Methods in org.apache.avro.mapred that return types with arguments of type Utf8

 org.apache.hadoop.mapred.RecordReader<AvroWrapper<Utf8>,NullWritable>
AvroUtf8InputFormat.getRecordReader(org.apache.hadoop.mapred.InputSplit split,
                org.apache.hadoop.mapred.JobConf job,
                org.apache.hadoop.mapred.Reporter reporter)

Uses of Utf8 in org.apache.avro.util

Methods in org.apache.avro.util that return Utf8

 Utf8
Utf8.setByteLength(int newLength)

          Set length in bytes.

 Utf8
Utf8.setLength(int newLength)

          Deprecated. call setByteLength(int) instead.

Methods in org.apache.avro.util with parameters of type Utf8

 int
Utf8.compareTo(Utf8 that)

      Overview
      Package
      Class
    Use
      Tree
      Deprecated
      Index
      Help

 PREV
 NEXT

  FRAMES
 NO FRAMES

  All Classes

Copyright © 2010 The Apache Software Foundation