text:
package de.nedelosk.modularmachines.api.recipes;

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

import de.nedelosk.modularmachines.api.property.PropertyToolMode;
import de.nedelosk.modularmachines.common.modules.storaged.tools.ModuleLathe.LatheModes;
import net.minecraft.item.ItemStack;

public class RecipeUtil {

	public static final PropertyToolMode LATHEMODE = new PropertyToolMode("mode", LatheModes.class, LatheModes.ROD);

	public static boolean addPulverizer(String recipeName, ItemStack input, RecipeItem[] output, int speed){
		return addPulverizer(recipeName, new RecipeItem(input), output, speed);
	}

	public static boolean addPulverizer(String recipeName, OreStack input, RecipeItem[] output, int speed){
		return addPulverizer(recipeName, new RecipeItem(input), output, speed);
	}

	public static boolean addPulverizer(String recipeName, RecipeItem input, RecipeItem[] output, int speed){
		IRecipeHandler handler = RecipeRegistry.getRecipeHandler("Pulverizer");
		IRecipeBuilder builder = handler.getDefaultTemplate();
		builder
		.set(Recipe.INPUTS, new RecipeItem[]{input}).
		set(Recipe.OUTPUTS, output)
		.set(Recipe.SPEED, speed);
		return handler.registerRecipe(builder.build());
	}

	public static boolean addAlloySmelter(String recipeName, RecipeItem inputFirst, RecipeItem inputSecond, RecipeItem[] output, int speed, double heat, double heatToRemove){
		IRecipeHandler handler = RecipeRegistry.getRecipeHandler("AlloySmelter");
		IRecipeBuilder builder = handler.getDefaultTemplate();
		builder
		.set(Recipe.INPUTS, new RecipeItem[]{inputFirst, inputSecond}).
		set(Recipe.OUTPUTS, output)
		.set(Recipe.SPEED, speed)
		.set(Recipe.HEAT, heat)
		.set(Recipe.HEATTOREMOVE, heatToRemove);
		return handler.registerRecipe(builder.build());
	}

	public static boolean addLathe(String recipeName, RecipeItem input, RecipeItem output, int speed, LatheModes mode){
		IRecipeHandler handler = RecipeRegistry.getRecipeHandler("Lathe");
		IRecipeBuilder builder = handler.getDefaultTemplate();
		builder
		.set(Recipe.INPUTS, new RecipeItem[]{input}).
		set(Recipe.OUTPUTS, new RecipeItem[]{output})
		.set(Recipe.SPEED, speed)
		.set(LATHEMODE, mode);
		return handler.registerRecipe(builder.build());
	}

	/*public static boolean addSawMill(String recipeName, OreStack input, RecipeItem[] output, int speedModifier, int energy){
		return registerRecipe(new Recipe(recipeName, new RecipeItem[] { new RecipeItem(input) }, output, speedModifier, energy, "SawMill"));
	}

	public static boolean addSawMill(String recipeName, ItemStack input, RecipeItem[] output, int speedModifier, int energy){
		return registerRecipe(new Recipe(recipeName, new RecipeItem[] { new RecipeItem(input) }, output, speedModifier, energy, "SawMill"));
	}

	public static boolean addSawMill(String recipeName, RecipeItem input, RecipeItem[] output, int speedModifier, int energy){
		return registerRecipe(new Recipe(recipeName, new RecipeItem[] { input }, output, speedModifier, energy, "SawMill"));
	}*/

	public static boolean addBoilerRecipe(String recipeName, RecipeItem input, RecipeItem output, int speed, double heat, double heatToRemove){
		IRecipeHandler handler = RecipeRegistry.getRecipeHandler("Boiler");
		IRecipeBuilder builder = handler.getDefaultTemplate();
		builder
		.set(Recipe.INPUTS, new RecipeItem[]{input}).
		set(Recipe.OUTPUTS, new RecipeItem[]{output})
		.set(Recipe.SPEED, speed)
		.set(Recipe.HEAT, heat)
		.set(Recipe.HEATTOREMOVE, heatToRemove);
		return handler.registerRecipe(builder.build());
	}

	public static boolean canRemoveRecipeInputs(IRecipeInventory inventory, int chance, RecipeItem[] inputs) {
		if (inputs != null) {
			for(RecipeItem recipeInput : inputs) {
				if (recipeInput != null) {
					int stackSize = 0;
					if (recipeInput.isOre()) {
						stackSize = recipeInput.ore.stackSize;
					} else if (recipeInput.isItem()) {
						stackSize = recipeInput.item.stackSize;
					} else {
						continue;
					}
					ItemStack itemStack = inventory.getStackInSlot(recipeInput.index);
					if (itemStack.stackSize < stackSize) {
						return false;
					}
					continue;
				} else {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	public static void removeRecipeInputs(IRecipeInventory inventory, int chance, RecipeItem[] inputs){
		if (inputs != null) {
			for(RecipeItem recipeInput : inputs) {
				if (recipeInput != null) {
					if (recipeInput.isOre()) {
						inventory.extractItem(recipeInput.index, recipeInput.ore.stackSize, false);
					} else if (recipeInput.isItem()) {
						inventory.extractItem(recipeInput.index, recipeInput.item.stackSize, false);
					}
				}
			}
		}
	}

	public static boolean canAddRecipeOutputs(IRecipeInventory inventory, int chance, RecipeItem[] outputs) {
		List<ItemStack> outputStacks = new ArrayList<ItemStack>(inventory.getOutputs());
		if(inventory.getOutputs() > 0) {
			boolean allFull = true;
			for (int i = inventory.getInputs(); i < inventory.getInputs() + inventory.getOutputs(); i++) {
				ItemStack st = inventory.getStackInSlot(i);
				if(st != null) {
					st = st.copy();
					if(allFull && st.stackSize < st.getMaxStackSize()) {
						allFull = false;
					}
				} else {
					allFull = false;
				}
				outputStacks.add(st);
			}
			if(allFull) {
				return false;
			}
		}

		for (RecipeItem result : outputs) {
			if(result.item != null) {
				if(mergeItemResult(result.item, outputStacks) == 0) {
					return false;
				}
			}
		}

		return true;
	}

	public static void addRecipeOutputs(IRecipeInventory inventory, int chance, RecipeItem[] outputs) {
		List<ItemStack> outputStacks = new ArrayList<ItemStack>(inventory.getOutputs());
		if(inventory.getOutputs() > 0) {
			for (int i = inventory.getInputs(); i < inventory.getInputs() + inventory.getOutputs(); i++) {
				ItemStack it = inventory.getStackInSlot(i);
				if(it != null) {
					it = it.copy();
				}
				outputStacks.add(it);
			}
		}

		for (RecipeItem result : outputs) {
			if(result.item != null) {
				int numMerged = mergeItemResult(result.item, outputStacks);
				if(numMerged > 0) {
					result.item.stackSize -= numMerged;
				}
			}
		}

		if(inventory.getOutputs() > 0) {
			int listIndex = 0;
			for (int i = inventory.getInputs(); i < inventory.getInputs() + inventory.getOutputs(); i++) {
				ItemStack st = outputStacks.get(listIndex);
				if(st != null) {
					st = st.copy();
				}
				inventory.insertItem(i, st, false);
				listIndex++;
			}
		}
	}

	private static int mergeItemResult(ItemStack item, List<ItemStack> outputStacks) {
		int res = 0;

		ItemStack copy = item.copy();

		for (ItemStack outStack : outputStacks) {
			if(outStack != null && copy != null) {
				int num = getNumCanMerge(outStack, copy);
				outStack.stackSize += num;
				res += num;
				copy.stackSize -= num;
				if(copy.stackSize <= 0) {
					return item.stackSize;
				}
			}
		}

		for (int i = 0; i < outputStacks.size(); i++) {
			ItemStack outStack = outputStacks.get(i);
			if(outStack == null) {
				outputStacks.set(i, copy);
				return item.stackSize;
			}
		}

		return 0;
	}

	private static int getNumCanMerge(ItemStack itemStack, ItemStack result) {
		if(!itemStack.isItemEqual(result)) {
			return 0;
		}
		return Math.min(itemStack.getMaxStackSize() - itemStack.stackSize, result.stackSize);
	}
}

redpajama_set_name: RedPajamaGithub


text:
package blockstore

import (
	"context"
	"testing"

	"gx/ipfs/QmSn9Td7xgxm9EV7iEjTckpUWmWApggzPxu7eFGWkkpwin/go-block-format"

	cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
	ds "gx/ipfs/QmdHG8MAuARdGHxx4rPQASLcvhz24fzjSQq7AJRAQEorq5/go-datastore"
	syncds "gx/ipfs/QmdHG8MAuARdGHxx4rPQASLcvhz24fzjSQq7AJRAQEorq5/go-datastore/sync"
)

var exampleBlock = blocks.NewBlock([]byte("foo"))

func testArcCached(ctx context.Context, bs Blockstore) (*arccache, error) {
	if ctx == nil {
		ctx = context.TODO()
	}
	opts := DefaultCacheOpts()
	opts.HasBloomFilterSize = 0
	opts.HasBloomFilterHashes = 0
	bbs, err := CachedBlockstore(ctx, bs, opts)
	if err == nil {
		return bbs.(*arccache), nil
	}
	return nil, err
}

func createStores(t *testing.T) (*arccache, Blockstore, *callbackDatastore) {
	cd := &callbackDatastore{f: func() {}, ds: ds.NewMapDatastore()}
	bs := NewBlockstore(syncds.MutexWrap(cd))
	arc, err := testArcCached(context.TODO(), bs)
	if err != nil {
		t.Fatal(err)
	}
	return arc, bs, cd
}

func trap(message string, cd *callbackDatastore, t *testing.T) {
	cd.SetFunc(func() {
		t.Fatal(message)
	})
}
func untrap(cd *callbackDatastore) {
	cd.SetFunc(func() {})
}

func TestRemoveCacheEntryOnDelete(t *testing.T) {
	arc, _, cd := createStores(t)

	arc.Put(exampleBlock)

	cd.Lock()
	writeHitTheDatastore := false
	cd.Unlock()

	cd.SetFunc(func() {
		writeHitTheDatastore = true
	})

	arc.DeleteBlock(exampleBlock.Cid())
	arc.Put(exampleBlock)
	if !writeHitTheDatastore {
		t.Fail()
	}
}

func TestElideDuplicateWrite(t *testing.T) {
	arc, _, cd := createStores(t)

	arc.Put(exampleBlock)
	trap("write hit datastore", cd, t)
	arc.Put(exampleBlock)
}

func TestHasRequestTriggersCache(t *testing.T) {
	arc, _, cd := createStores(t)

	arc.Has(exampleBlock.Cid())
	trap("has hit datastore", cd, t)
	if has, err := arc.Has(exampleBlock.Cid()); has || err != nil {
		t.Fatal("has was true but there is no such block")
	}

	untrap(cd)
	err := arc.Put(exampleBlock)
	if err != nil {
		t.Fatal(err)
	}

	trap("has hit datastore", cd, t)

	if has, err := arc.Has(exampleBlock.Cid()); !has || err != nil {
		t.Fatal("has returned invalid result")
	}
}

func TestGetFillsCache(t *testing.T) {
	arc, _, cd := createStores(t)

	if bl, err := arc.Get(exampleBlock.Cid()); bl != nil || err == nil {
		t.Fatal("block was found or there was no error")
	}

	trap("has hit datastore", cd, t)

	if has, err := arc.Has(exampleBlock.Cid()); has || err != nil {
		t.Fatal("has was true but there is no such block")
	}

	untrap(cd)

	if err := arc.Put(exampleBlock); err != nil {
		t.Fatal(err)
	}

	trap("has hit datastore", cd, t)

	if has, err := arc.Has(exampleBlock.Cid()); !has || err != nil {
		t.Fatal("has returned invalid result")
	}
}

func TestGetAndDeleteFalseShortCircuit(t *testing.T) {
	arc, _, cd := createStores(t)

	arc.Has(exampleBlock.Cid())

	trap("get hit datastore", cd, t)

	if bl, err := arc.Get(exampleBlock.Cid()); bl != nil || err != ErrNotFound {
		t.Fatal("get returned invalid result")
	}

	if arc.DeleteBlock(exampleBlock.Cid()) != ErrNotFound {
		t.Fatal("expected ErrNotFound error")
	}
}

func TestArcCreationFailure(t *testing.T) {
	if arc, err := newARCCachedBS(context.TODO(), nil, -1); arc != nil || err == nil {
		t.Fatal("expected error and no cache")
	}
}

func TestInvalidKey(t *testing.T) {
	arc, _, _ := createStores(t)

	bl, err := arc.Get(nil)

	if bl != nil {
		t.Fatal("blocks should be nil")
	}
	if err == nil {
		t.Fatal("expected error")
	}
}

func TestHasAfterSucessfulGetIsCached(t *testing.T) {
	arc, bs, cd := createStores(t)

	bs.Put(exampleBlock)

	arc.Get(exampleBlock.Cid())

	trap("has hit datastore", cd, t)
	arc.Has(exampleBlock.Cid())
}

func TestDifferentKeyObjectsWork(t *testing.T) {
	arc, bs, cd := createStores(t)

	bs.Put(exampleBlock)

	arc.Get(exampleBlock.Cid())

	trap("has hit datastore", cd, t)
	cidstr := exampleBlock.Cid().String()

	ncid, err := cid.Decode(cidstr)
	if err != nil {
		t.Fatal(err)
	}

	arc.Has(ncid)
}

func TestPutManyCaches(t *testing.T) {
	arc, _, cd := createStores(t)
	arc.PutMany([]blocks.Block{exampleBlock})

	trap("has hit datastore", cd, t)
	arc.Has(exampleBlock.Cid())
	untrap(cd)
	arc.DeleteBlock(exampleBlock.Cid())

	arc.Put(exampleBlock)
	trap("PunMany has hit datastore", cd, t)
	arc.PutMany([]blocks.Block{exampleBlock})
}


text:
using namespace std;

MSFormat::MSFormat(const string& filename)
{
    if (filename != "")
    {
        ifstream is(filename.c_str());
        if (!is)
            throw runtime_error(("[MSFormat] Unable to open file " + filename).c_str());
        is >> *this;
    }
}

string MSFormat::sequence(size_t sequenceIndex, double positionBegin, double positionEnd) const
{
    if (sequenceIndex >= sequences.size())
        throw runtime_error("[MSFormat::sequence()] Invalid sequence index.");

    vector<double>::const_iterator itBegin =
        lower_bound(positions.begin(), positions.end(), positionBegin);
    vector<double>::const_iterator itEnd =
        lower_bound(positions.begin(), positions.end(), positionEnd);

    size_t index = itBegin - positions.begin();
    size_t length = itEnd - itBegin;

    return sequences[sequenceIndex].substr(index, length);
}

bool operator==(const MSFormat& a, const MSFormat& b)
{
    if (a.segsites() != b.segsites()) return false;
    for (vector<double>::const_iterator it=a.positions.begin(), jt=b.positions.begin(); it!=a.positions.end(); ++it, ++jt)
        if (*it != *jt) return false;

    if (a.sequences.size() != b.sequences.size()) return false;
    for (vector<string>::const_iterator it=a.sequences.begin(), jt=b.sequences.begin(); it!=a.sequences.end(); ++it, ++jt)
        if (*it != *jt) return false;

    return true;
}

bool operator!=(const MSFormat& a, const MSFormat& b)
{
    return !(a==b);
}

ostream& operator<<(ostream& os, const MSFormat& msformat)
{
    os << "segsites: " << msformat.segsites() << endl;
    os << "positions: ";
    copy(msformat.positions.begin(), msformat.positions.end(), ostream_iterator<double>(os," "));
    os << endl;
    copy(msformat.sequences.begin(), msformat.sequences.end(), ostream_iterator<string>(os,"\n"));
    return os;
}

istream& operator>>(istream& is, MSFormat& msformat)
{
    msformat.positions.clear();
    msformat.sequences.clear();

    size_t segsites = 0;

    while (is)
    {
        string buffer;
        getline(is, buffer);
        if (!is)
            return is;

        istringstream iss(buffer);
        string first;
        iss >> first;

        if (first == "segsites:")
        {
            iss >> segsites;
        }
        else if (segsites == 0)
        {
            continue;
        }
        else if (first == "positions:")
        {
            copy(istream_iterator<double>(iss), istream_iterator<double>(),
                 back_inserter(msformat.positions));
            if (segsites != msformat.segsites())
                throw runtime_error("[operator>>(MSFormat)] Position count doesn't match segsites.");
        }
        else if (!first.empty())
        {
            msformat.sequences.push_back(first);
        }
        else
        {
            break;
        }
    }

    return is;
}


text:
'use strict'
module.exports = function () {
  const seneca = this
  const role = 'products'
  seneca.add({role, cmd: 'list' }, cmd_list)

  seneca.listen()

  function cmd_list (args, done) {
    return done(null, [{ id: 1, name: 'product 1'}])
  }

  seneca.ready(() => {
    if (process && process.send) process.send('ready')
  })
}


text:
import sys
import os
sys.path.append(os.path.abspath('./plot/'))
from option import *
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plot
import matplotlib.ticker as ticker
import numpy as np
import csv

def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., height + 0.01,
                '%0.1f' % float(height),
#                '%d' % int(height),
                ha='center', va='bottom')

GROUP_NUM = 2
GROUP_NAMES = ["SuRF", "SuRF-Real8"]

GROUP_SIZE = 7
CATEGORY_NAMES = ["Uncompressed", "Single", "Double", "3-Grams, 65536", "4-Grams, 65536", "ALM-Improved, 4096", "ALM-Improved, 65536"]

CSV_SURF_FILE_PATH = "results/SuRF/point/final_fpr_email_surf.csv"
CSV_SURFREAL_FILE_PATH = "results/SuRF_real/point/final_fpr_email_surfreal.csv"
GRAPH_OUTPUT_PATH = "figures/SuRF/point/fpr_email_surf_point.pdf"

COLORS = ['#ffffff', '#fff7ec', '#fee8c8', '#fc8d59', '#d7301f', '#7f0000', '#4c0000']

Y_LABEL = "False Positive Rate (%)"

X_TICK_FONT_SIZE = 20
Y_TICK_FONT_SIZE = 16

LEGEND_FONT_SIZE = 18
LEGEND_POS = 'upper left'

f_in_surf = open(CSV_SURF_FILE_PATH)
reader = csv.reader(f_in_surf)
csvrows = list(reader)
data_surf = []
for row in csvrows :
    for item in row :
        data_surf.append(float(item) * 100)

f_in_surfreal = open(CSV_SURFREAL_FILE_PATH)
reader = csv.reader(f_in_surfreal)
csvrows = list(reader)
data_surfreal = []
for row in csvrows :
    for item in row :
        data_surfreal.append(float(item) * 100)

data = []
for i in range(0, GROUP_SIZE) :
    data.append([data_surf[i], data_surfreal[i]])

#========================================================================================
mpl.rcParams['ps.useafm'] = True
mpl.rcParams['pdf.use14corefonts'] = True
mpl.rcParams['text.usetex'] = False

mpl.rcParams['text.latex.preamble'] = [
       r'\usepackage{siunitx}',   # i need upright \micro symbols, but you need...
       r'\sisetup{detect-all}',   # ...this to force siunitx to actually use your fonts
       r'\usepackage{helvet}',    # set the normal font here
       r'\usepackage{sansmath}',  # load up the sansmath so that math -> helvet
       r'\sansmath'               # <- tricky! -- gotta actually tell tex to use!
]
#========================================================================================

width = GRAPH_WIDTH  / (((GROUP_SIZE + 1) * GROUP_NUM) + 1.0)

fig = plot.figure(figsize=(GRAPH_WIDTH, 4))
ax = fig.add_subplot(111)

rect = []

for i in range(0, GROUP_SIZE) :
    if i == 0: # baseline
       hatch=HATCH
    else:
       hatch = ""
    pos = []
    for j in range(0, GROUP_NUM) :
        pos.append(width + width * i + width * j * (GROUP_SIZE + 1))
    rect.append(ax.bar(pos, data[i], width, color=COLORS[i], label=CATEGORY_NAMES[i],  linewidth = BORDER_SIZE, edgecolor = BORDER_COLOR, hatch=hatch))
    autolabel(rect[i])

xtick_pos = []
for j in range(0, GROUP_NUM) :
    xtick_pos.append(width + width * (GROUP_SIZE / 2.0) + width * j * (GROUP_SIZE + 1) - 0.5 * width)

ax.set_xticks(xtick_pos)
ax.set_xticklabels(GROUP_NAMES)

for label in ax.get_xticklabels():
    label.set_fontsize(X_TICK_FONT_SIZE)

y_ticks = [0, 10, 20, 30, 40]
ax.set_yticks(y_ticks)
ax.set_ylim(0, 40)

for label in ax.get_yticklabels():
    label.set_fontsize(Y_TICK_FONT_SIZE)

ax.set_ylabel(Y_LABEL, fontsize=Y_LABEL_FONT_SIZE - 4)

#ax.legend(loc=LEGEND_POS, prop={'size':LEGEND_FONT_SIZE})

outFile = GRAPH_OUTPUT_PATH
plot.savefig(outFile, bbox_inches='tight')


text:
#ifndef __GST_RTP_VORBIS_PAY_H__
#define __GST_RTP_VORBIS_PAY_H__

#include <gst/gst.h>
#include <gst/rtp/gstrtpbasepayload.h>
#include <gst/base/gstadapter.h>

G_BEGIN_DECLS

#define GST_TYPE_RTP_VORBIS_PAY \
  (gst_rtp_vorbis_pay_get_type())
#define GST_RTP_VORBIS_PAY(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_RTP_VORBIS_PAY,GstRtpVorbisPay))
#define GST_RTP_VORBIS_PAY_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_RTP_VORBIS_PAY,GstRtpVorbisPayClass))
#define GST_IS_RTP_VORBIS_PAY(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_VORBIS_PAY))
#define GST_IS_RTP_VORBIS_PAY_CLASS(klass) \
  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_VORBIS_PAY))

typedef struct _GstRtpVorbisPay GstRtpVorbisPay;
typedef struct _GstRtpVorbisPayClass GstRtpVorbisPayClass;

struct _GstRtpVorbisPay
{
  GstRTPBasePayload payload;

  /* the headers */
  gboolean      need_headers;
  GList        *headers;

  /* queues of buffers along with some stats. */
  GstBuffer    *packet;
  GList        *packet_buffers;
  guint         payload_pos;
  guint         payload_left;
  guint32       payload_ident;
  guint8        payload_F;
  guint8        payload_VDT;
  guint         payload_pkts;
  GstClockTime  payload_timestamp;
  GstClockTime  payload_duration;

  /* config (re-sending) */
  guint8       *config_data;
  guint         config_size;
  guint         config_extra_len;
  guint         config_interval;
  GstClockTime  last_config;

  gint          rate;
  gint          channels;
};

struct _GstRtpVorbisPayClass
{
  GstRTPBasePayloadClass parent_class;
};

GType gst_rtp_vorbis_pay_get_type (void);

gboolean gst_rtp_vorbis_pay_plugin_init (GstPlugin * plugin);

G_END_DECLS

#endif /* __GST_RTP_VORBIS_PAY_H__ */


text:
import { get } from './property_get';
/**
 @module @ember/utils
*/
/**
  Verifies that a value is `null` or `undefined`, an empty string, or an empty
  array.

  Constrains the rules on `isNone` by returning true for empty strings and
  empty arrays.

  If the value is an object with a `size` property of type number, it is used
  to check emptiness.

  ```javascript
  isEmpty();                 // true
  isEmpty(null);             // true
  isEmpty(undefined);        // true
  isEmpty('');               // true
  isEmpty([]);               // true
  isEmpty({ size: 0});       // true
  isEmpty({});               // false
  isEmpty('Adam Hawkins');   // false
  isEmpty([0,1,2]);          // false
  isEmpty('\n\t');           // false
  isEmpty('  ');             // false
  isEmpty({ size: 1 })       // false
  isEmpty({ size: () => 0 }) // false
  ```

  @method isEmpty
  @static
  @for @ember/utils
  @param {Object} obj Value to test
  @return {Boolean}
  @public
*/
export default function isEmpty(obj: any): boolean {
  let none = obj === null || obj === undefined;
  if (none) {
    return none;
  }

  if (typeof obj.unknownProperty !== 'function' && typeof obj.size === 'number') {
    return !obj.size;
  }

  let objectType = typeof obj;

  if (objectType === 'object') {
    let size = get(obj, 'size');
    if (typeof size === 'number') {
      return !size;
    }
  }

  if (typeof obj.length === 'number' && objectType !== 'function') {
    return !obj.length;
  }

  if (objectType === 'object') {
    let length = get(obj, 'length');
    if (typeof length === 'number') {
      return !length;
    }
  }

  return false;
}


text:
- 0101 Introduction and Course Overview / About The Author
- 0102 Prerequisites


text:
class CommentsController < ApplicationController
  skip_before_action :verify_authenticity_token

  def create
    comment_json = JSON.parse(request.raw_post)

    @current = Comment.create(comment_json)
    hash = {
              id: @current.id,
              article_id: @current.article_id,
              content: @current.content
            }
    render :json => hash, content_type: "application/json"
  end

  def show
    comment_id = params[:id]

    if Comment.exists?(comment_id)
      @current = Comment.find(comment_id)
      hash = {
                id: @current.id,
                article_id: @current.article_id,
                content: @current.content
              }
      render :json => hash, content_type: "application/json"
    else
      render :json => {}, content_type: "application/json"
    end

  end

  def index
    #not sure if sorting works well - first puts capital letters; created_at da se slaga li??
    # render :json => Comment.all().sort_by{|c| c.content}.to_json

    output_json = Array.new
    all =  Comment.all().sort_by{|c| c.content}

    all.each do |c|
      output_json <<  {
                        id: c.id,
                        article_id: c.article_id,
                        content: c.content
                      }
    end
    render :json => output_json, content_type: "application/json"
  end

end


text:
function(add_NVT_test name)
      set(NVT_flags "-DENSEMBLE=1")
      # My test are all called name_test.cpp
      add_executable(${name} ${GOMCHeaders} ${GOMCSources} ${libHeaders} ${libSources} ${TestHeaders} ${TestSources})
      target_link_libraries(${name} gtest_main)
      set_target_properties(${name} PROPERTIES
      COMPILE_FLAGS "${NVT_flags}")
      add_test(NAME BasicTypesTest_NVT COMMAND BasicTypesTest)
      #add_test(NAME CircuitTester_NVT COMMAND DialaTest)
      add_test(NAME MolLookupTest_NVT COMMAND CheckConsensusBeta)
      #add_test(NAME PSFParserTest_NVT COMMAND CheckProtAndWaterTest)
      add_test(NAME EndianTest_NVT COMMAND TestBitSwap)
endfunction(add_NVT_test)

function(add_NPT_test name)
      set(NPT_flags "-DENSEMBLE=4")
      # My test are all called name_test.cpp
      add_executable(${name} ${GOMCHeaders} ${GOMCSources} ${libHeaders} ${libSources} ${TestHeaders} ${TestSources})
      target_link_libraries(${name} gtest_main)
      set_target_properties(${name} PROPERTIES
      COMPILE_FLAGS "${NPT_flags}")
      add_test(NAME BasicTypesTest_NPT COMMAND BasicTypesTest)
      #add_test(NAME CircuitTester_NPT COMMAND DialaTest)
      add_test(NAME MolLookupTest_NPT COMMAND CheckConsensusBeta)
      #add_test(NAME PSFParserTest_NPT COMMAND CheckProtAndWaterTest)
      add_test(NAME EndianTest_NPT COMMAND TestBitSwap)
endfunction(add_NPT_test)

function(add_GCMC_test name)
      set(GCMC_flags "-DENSEMBLE=3")
      # My test are all called name_test.cpp
      add_executable(${name} ${GOMCHeaders} ${GOMCSources} ${libHeaders} ${libSources} ${TestHeaders} ${TestSources})
      target_link_libraries(${name} gtest_main)
      set_target_properties(${name} PROPERTIES
      COMPILE_FLAGS "${GCMC_flags}")
      add_test(NAME BasicTypesTest_GCMC COMMAND BasicTypesTest)
      #add_test(NAME CircuitTester_GCMC COMMAND DialaTest)
      add_test(NAME MolLookupTest_GCMC COMMAND CheckConsensusBeta)
      #add_test(NAME PSFParserTest_GCMC COMMAND CheckProtAndWaterTest)
      add_test(NAME ConsistentTrajectoryTest_GCMC COMMAND CheckPDBTrajCoordinates)
      #add_test(NAME CheckpointTest_GCMC COMMAND CheckMollookup)
      add_test(NAME EndianTest_GCMC COMMAND TestBitSwap)
endfunction(add_GCMC_test)

function(add_GEMC_test name)
      set(GEMC_flags "-DENSEMBLE=2")
      # My test are all called name_test.cpp
      add_executable(${name} ${GOMCHeaders} ${GOMCSources} ${libHeaders} ${libSources} ${TestHeaders} ${TestSources})
      target_link_libraries(${name} gtest_main)
      set_target_properties(${name} PROPERTIES
      COMPILE_FLAGS "${GEMC_flags}")
      add_test(NAME BasicTypesTest_GEMC COMMAND BasicTypesTest)
      #add_test(NAME CircuitTester_GEMC COMMAND DialaTest)
      add_test(NAME MolLookupTest_GEMC COMMAND CheckConsensusBeta)
      #add_test(NAME PSFParserTest_GEMC COMMAND CheckProtAndWaterTest)
      add_test(NAME ConsistentTrajectoryTest_GEMC COMMAND CheckPDBTrajCoordinates)
      #add_test(NAME CheckpointTest_GEMC COMMAND CheckMollookup)
      add_test(NAME EndianTest_GEMC COMMAND TestBitSwap)
endfunction(add_GEMC_test)

add_NVT_test(GOMC_NVT_Test)
add_NPT_test(GOMC_NPT_Test)
add_GCMC_test(GOMC_GCMC_Test)
add_GEMC_test(GOMC_GEMC_Test)


text:
  Gleizé est
      une commune située dans le département de Rhône en Rhône-Alpes. Elle totalisait 7 807 habitants en 2008.

La commune propose quelques  aménagements, elle dispose, entre autres, de un terrain de tennis, un terrain de sport et une salle de combat.

À proximité de Gleizé sont positionnées géographiquement les villes de
Limas à 1 km, 4 394 habitants,
Saint-Julien à 5 km, 812 habitants,
Cogny localisée à 5 km, 981 habitants,
Jassans-Riottier localisée à 4 km, 5 879 habitants,
Saint-Bernard située à 5 km, 1 358 habitants,
Beauregard localisée à 4 km, 895 habitants,
 entre autres. De plus, Gleizé est située à seulement 26 km de Lyon.

Le parc de logements, à Gleizé, se décomposait en 2011 en 1 559 appartements et 1 732 maisons soit
 un marché relativement équilibré.

À Gleizé le salaire moyen mensuel par habitant se situe à approximativement 2 146 €  net. Ceci est supérieur à la moyenne nationale.

À Gleizé, la valorisation moyenne à la vente d'un appartement s'évalue à 2 234 € du m² en vente. La valeur moyenne d'une maison à l'achat se situe à 2 337 € du m². À la location la valeur moyenne se situe à 8,83 € du m² par mois.


text:
package org.jcodec.containers.mp4.boxes;

import java.nio.ByteBuffer;

/**
 * This class is part of JCodec ( www.jcodec.org ) This software is distributed
 * under FreeBSD License
 *
 * A box containing sample presentation time information
 *
 * @author Jay Codec
 *
 */
public class TimeToSampleBox extends FullBox {

    public static class TimeToSampleEntry {
        int sampleCount;
        int sampleDuration;

        public TimeToSampleEntry(int sampleCount, int sampleDuration) {
            this.sampleCount = sampleCount;
            this.sampleDuration = sampleDuration;
        }

        public int getSampleCount() {
            return sampleCount;
        }

        public int getSampleDuration() {
            return sampleDuration;
        }

        public void setSampleDuration(int sampleDuration) {
            this.sampleDuration = sampleDuration;
        }

        public void setSampleCount(int sampleCount) {
            this.sampleCount = sampleCount;
        }

        public long getSegmentDuration() {
            return sampleCount * sampleDuration;
        }
    }

    public static String fourcc() {
        return "stts";
    }

    private TimeToSampleEntry[] entries;

    public TimeToSampleBox(TimeToSampleEntry[] timeToSamples) {
        super(new Header(fourcc()));
        this.entries = timeToSamples;
    }

    public TimeToSampleBox() {
        super(new Header(fourcc()));
    }

    public void parse(ByteBuffer input) {
        super.parse(input);
        int foo = input.getInt();
        entries = new TimeToSampleEntry[foo];
        for (int i = 0; i < foo; i++) {
            entries[i] = new TimeToSampleEntry(input.getInt(), input.getInt());
        }
    }

    public TimeToSampleEntry[] getEntries() {
        return entries;
    }

    @Override
    public void doWrite(ByteBuffer out) {
        super.doWrite(out);
        out.putInt(entries.length);
        for (TimeToSampleEntry timeToSampleEntry : entries) {
            out.putInt(timeToSampleEntry.getSampleCount());
            out.putInt(timeToSampleEntry.getSampleDuration());
        }
    }

    public void setEntries(TimeToSampleEntry[] entries) {
        this.entries = entries;
    }
}


text:
using UnityEditor;
using UnityEngine;

namespace droid.Editor.Utilities {
  /// <summary>
  ///
  /// </summary>
  public static class MeshSaverEditor {
    const string _menu_path = "CONTEXT" + "/MeshFilter" + "/SaveMesh";

    /// <summary>
    ///
    /// </summary>
    /// <param name="menu_command"></param>
    [MenuItem(_menu_path)]
    public static void SaveMeshInPlace(MenuCommand menu_command) {
      var mf = menu_command.context as MeshFilter;

      if (mf != null) {
        var m = mf.sharedMesh;
        SaveMesh(m,
                 m.name,
                 false,
                 true);
      }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="menu_command"></param>
    [MenuItem(_menu_path + "AsANewInstance")]
    public static void SaveMeshNewInstanceItem(MenuCommand menu_command) {
      var mf = menu_command.context as MeshFilter;

      if (mf != null) {
        var m = mf.sharedMesh;
        SaveMesh(m,
                 m.name,
                 true,
                 true);
      }
    }

    public static void SaveMesh(Mesh mesh, string name, bool make_new_instance, bool optimize_mesh) {
      var path = EditorUtility.SaveFilePanel("Save Separate Mesh Asset",
                                             "Neodroid/Runtime/Meshes",
                                             name,
                                             "asset");
      Debug.Log($"Trying to save mesh to {path}");
      if (string.IsNullOrEmpty(path)) {
        return;
      }

      path = FileUtil.GetProjectRelativePath(path);

      var mesh_to_save = make_new_instance ? Object.Instantiate(mesh) : mesh;

      if (optimize_mesh) {
        MeshUtility.Optimize(mesh_to_save);
      }

      AssetDatabase.CreateAsset(mesh_to_save, path);
      AssetDatabase.SaveAssets();
    }
  }
}
#endif


text:
package br.ufsc.myfood.persistence.dao;

import org.hibernate.SessionFactory;

import br.ufsc.myfood.persistence.entity.AddressEntity;
import io.dropwizard.hibernate.AbstractDAO;

public class AddressDAO extends AbstractDAO<AddressEntity>{

	public AddressDAO(SessionFactory sessionFactory) {
		super(sessionFactory);
	}

	public Integer create(AddressEntity address){
		return persist(address).getIdAddress();
	}

}


text:
I finally got rid of my past project. I finished write up of my work,
and posted in to marco. I finally learnt an important lesson.
Advisor is not a coach. I have to follow my own instincts.

I got started on a project with hui. Finished some background reading for it.
Finished GPU book and did some experiments.
Ideally looking to publish something in the next few months

Week3#
Good:
Tracked calories, put in good work cycle.
Played around with gpus and read some papers on this gpu and data processing.
Measured things on elba. Went to a dentist.

Bad:
Unexpected crash mentally exhausted on saturday. Ended up drinking
and ate a lot.
For next week, I need to do a better job at tracking my sleep and wake up time.


text:
from pymongo import MongoClient

client = MongoClient()

db=client.exampledatabase
collect1 = db.queries

for document in collect1.find():
	print document


text:
package elastigo

import (
	"encoding/json"
	"testing"
)

func TestSearchResultToJSON(t *testing.T) {
	c := NewConn()

	qry := map[string]interface{}{
		"query": map[string]interface{}{
			"wildcard": map[string]string{"actor": "a*"},
		},
	}
	var args map[string]interface{}
	out, err := c.Search("github", "", args, qry)

	if err != nil {
		t.Error(err)
	}
	_, err = json.Marshal(out.Hits.Hits)
	if err != nil {
		t.Error(err)
	}
}


text:
export default {
  defaultAppConfig: {
    themes: {
      active: 'PufferPanel',
      available: ['PufferPanel']
    },
    branding: {
      name: 'PufferPanel'
    }
  }
}


text:
'''
devdetect.py

Runs a group of threads which monitor for potential forensic-related system events
and trigger the antiforensic module if the screen is locked

@author: Nia Catlin
'''

import AFroutines
import fileconfig, hardwareconfig, sendemail, winsockbtooth

import socket,sys
import threading, Queue, subprocess
import select
import os,time,datetime
import imapclient
import wmi, win32timezone #cx_freeze doesn't seem to get this unless imported explicitly
from pythoncom import CoInitialize, CoUninitialize

eventQueue = None
allStop = False
startupTime = None

lockedStateText = {True:'Locked',False:'Not Locked'}
#trigger events go here to be checked for activation conditions
def eventHandle(event_type,eventReason):
    locked = hardwareconfig.checkLock()

    while True: #this can be a race condition with configfile alterations. keep trying if we get a bad reading
        try:
            alwaysTriggers = fileconfig.config.get('TRIGGERS','ALWAYSTRIGGERS').split(',')
            lockedTriggers = fileconfig.config.get('TRIGGERS','LOCKEDTRIGGERS').split(',')
            testMode = fileconfig.config.get('TRIGGERS','test_mode')
            break
        except:
            time.sleep(0.3)
            continue

    if (event_type in alwaysTriggers) or (event_type in lockedTriggers and locked == True):

        eventQueue.put(("Log","[%s - *Trigger ACTIVATED*]. %s"%(lockedStateText[locked],eventReason)))
        if testMode == 'False':
            #allow recovery in situations where the computer would otherwise shutdown as soon as it starts up
            if time.time() < startupTime + 90:
                eventQueue.put(("Log",'Shutdown cancelled - Not allowed within 90 seconds of lockwatcher start'))
            else:
                eventQueue.put(("Kill",eventReason))
        else:
            eventQueue.put(("Log",'Shutdown cancelled - test mode active'))
    else:
        '''log the ignored trigger (but not the 2nd killswitch because a logfile containing
        every press of the letter 'p' is going to be a mess)'''
        if event_type not in  ['E_MOUSE_MOVE','E_MOUSE_BTN','E_KILL_SWITCH_2']:
            eventQueue.put(("Log","[%s - Trigger ignored]. %s"%(lockedStateText[locked],eventReason)))

#running as a service makes exception handling more difficult
#write log directly instead of relying on eventqueue processing
VERBOSELOGS = False
def debugLog(msg):
    if VERBOSELOGS != True: return
    logPath = fileconfig.config.get('TRIGGERS','logfile')
    if not os.path.exists(logPath): return
    try:
        fd = open(logPath,'a+')
        fd.write(time.strftime('[%x %X]')+str(msg)+'\n')
        fd.close()
    except:
        pass

#check for logical disk creation events like cdrom insertion
class logicalDiskCreateMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'LDMMonitorCreate'
    def run(self):
        CoInitialize()
        self.c = wmi.WMI()
        self.watcher = self.c.Win32_LogicalDisk.watch_for("creation") #deletion too?
        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            #if event.DriveType in disksOfInterest:
            eventHandle('E_DEVICE',"Logical disk creation (Drive Name: '%s', Drive type: '%s')"%(event.DeviceID,event.Description))
        CoUninitialize()
    def terminate(self):
        self.running = False

#check for logical disk removal events like cdrom removal
class logicalDiskRemoveMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'LDMMonitorRemove'
    def run(self):
        CoInitialize()
        self.c = wmi.WMI()
        self.watcher = self.c.Win32_LogicalDisk.watch_for("deletion")
        #disksOfInterest = [2,5,6] #removable,cdrom,ramdisk

        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            #if event.DriveType in disksOfInterest:
            eventHandle('E_DEVICE',"Logical disk deletion (Drive Name: '%s', Drive type: '%s')"%(event.DeviceID,event.Description))
        CoUninitialize()
    def terminate(self):
        self.running = False

deviceMessages = {
            1:'Configuration Change',
           2:'Device Arrival',
           3:'Device Removal',
           4:'Docking'}

#check for addition/removal of lettered storage volumes
class volumeMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'VolumeMonitor'
    def run(self):
        CoInitialize()
        self.c = wmi.WMI()
        self.watcher = self.c.Win32_VolumeChangeEvent.watch_for()

        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            eventHandle('E_DEVICE',"Volume Monitor (Drive: '%s' Event: '%s')"%(str(event.DriveName),str(deviceMessages[event.EventType])))

        CoUninitialize()
    def terminate(self):
        self.running = False

#detect device insertion/removal
class deviceMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'DeviceMonitor'
    def run(self):
        try:
            CoInitialize()

            self.c = wmi.WMI()
            self.watcher = self.c.Win32_SystemConfigurationChangeEvent.watch_for() #called before devicechangeevent
        except:
            eventQueue.put(("Status",'devices',"Error: WMI Error"))
            eventQueue.put(("Log","Unable to start device monitor: WMI error"))
            return
        eventQueue.put(("Status",'devices',"Active"))

        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            eventHandle('E_DEVICE',"Device Monitor (%s)"%str(deviceMessages[event.EventType]))

        CoUninitialize ()
        eventQueue.put(("Status",'devices',"Not Running"))
    def terminate(self):
        self.running = False

'''
gets information about inserted/removed devices like name,manufacturer,bus,etc

This always fires after the device monitor so only really useful for more verbose logs
containing name/manufacturer etc of the devies that were plugged in

------
#bug: actually this seems to wreck my operating system after a few starts and stops -
#    consent.exe hangs, can't open services.msc due to error 0x80041003, other bad things
#disabling it because it doesn't actually make lockwatcher work any better
------

lDevMonStop = False
class LogicalDeviceMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name='LogicalDeviceMonitor'
        global lDevMonStop
        lDevMonStop = False
    def run(self):
        print('ldevmon start')
        CoInitialize()
        self.c = wmi.WMI()
        self.watcher = self.c.CIM_LogicalDevice.watch_for('creation') #deletion too?

        #using self.running fails to terminate it most of the time - no idea why
        while lDevMonStop == False:
            try:
                event = self.watcher(timeout_ms=1000)
            except wmi.x_wmi_timed_out:
                continue

            if event.Name != 'USB Composite Device': #not helpful in logs
                details = {}
                if hasattr(event,'Name'): details['Name']= event.Name
                if hasattr(event,'Manufacturer'): details['Manufacturer']= event.Manufacturer
                if hasattr(event,'CreationClassName'): details['CreationClass']= event.CreationClassName
                if hasattr(event,'DeviceID'): details['DeviceID']= event.DeviceID

                eventString = ""
                for name,value in details.items():
                    eventString = eventString + "%s: %s. "%(name,value)

                #creates a wall of horrible text, so add some whitespace
                eventHandle('E_DEVICE',"Logical Device addition. \n\t%s\n"%eventString)

        CoUninitialize()

    def terminate(self):
        global lDevMonStop
        lDevMonStop = True
'''

#logs in to specified imap server and selects the inbox
def setupIMAP():
    server = imapclient.IMAPClient(fileconfig.config.get('EMAIL','email_imap_host'), use_uid=False, ssl=True)
    server.login(fileconfig.config.get('EMAIL','email_username'), fileconfig.config.get('EMAIL','email_password'))
    server.select_folder('INBOX')
    return server

#waits for new mail, places it in the event queue if the addressee is correct
class emailMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = "mailMonThread"
        self.running = True
    def run(self):
        eventQueue.put(("Status",'email','Connecting to server...'))
        try:
            server = setupIMAP()
        except socket.gaierror:
            eventQueue.put(("Status",'email',"Error: Connect Failed"))
            return
        except imapclient.IMAPClient.Error as err:
            eventQueue.put(("Status",'email',err.args[0].decode()))
            return
        self.server = server
        server.idle()

        connectionFails = 0

        #dont seem to get an exception when connection attempt interrupted by user
        #this checks if 'stop' was pressed during the connecting phase
        if self.running == False:
            eventQueue.put(("Status",'email','Not Running'))
            return

        eventQueue.put(("Status",'email','Active'))

        while self.running == True:
            #refresh the connection every 14 mins so it doesnt timeout
            try:
                seqid = server.idle_check(840)
            except:
                if self.running == False: #terminate() was called
                    eventQueue.put(("Status",'email','Not Running'))
                    return

            if seqid == []: #no mail
                try:
                    server.idle_done()
                    server.idle()
                    connectionFails = 0
                except:
                    if self.running == False: break

                    eventQueue.put(("Status",'email','Attempting reconnect #%s'%(connectionFails)))
                    eventQueue.put(('Log',"IMAP connection lost. Attempting reconnect #%s"%(connectionFails)))

                    if connectionFails > 0: time.sleep(connectionFails * 3)
                    connectionFails += 1
                    try:
                        server = setupIMAP()
                        self.server = server
                        server.idle()
                        eventQueue.put(("Status",'email','Active'))
                    except:
                        eventQueue.put(("Status",'email',"Error: Connect Failed"))

                continue

            #fetch header data using the sequence id of the new mail
            seqid = seqid[0][0]
            server.idle_done()
            keys = server.fetch(seqid, ['ENVELOPE'])
            server.idle()
            keys = keys[seqid]['ENVELOPE']
            addressee = keys[2][0][2]
            intendedAddressee = fileconfig.config.get('EMAIL','command_email_address').split('@')[0]
            if addressee == intendedAddressee:
                eventQueue.put(("Mail",keys[1]))
            else:
                #ignore our own responses
                if addressee != fileconfig.config.get('EMAIL','sender_email_address').split('@')[0]:
                    eventQueue.put(('Log',"Got an email with unknown addressee: %s (need addressee %s)"%
                                (addressee,intendedAddressee)))

        eventQueue.put(("Status",'email','Not Running'))
    def terminate(self):
        self.running = False
        print('trying server logout')
        try:
            self.server.logout()
        except:
            pass

'''triggers the killswitch if the reported RAM temperature falls below RAM_TRIGGER_TEMP#

requires the Ballistix MOD program to be generating a logfile in the specified location
would be much improved by reading the temperatures straight from the SPD interface'''
class RAMMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'RAM Monitor'
    def run(self):
        self.running = True
        eventQueue.put(("Status",'ram',"Active"))
        while self.running == True:
            try:
                csvfile = open(fileconfig.config.get('TRIGGERS','BALLISTIX_LOG_FILE'),mode='rb')
            except IOError as e:
                eventQueue.put(("Status",'ram',"Error: Not Configured"))
                eventQueue.put(("Log","Unable to open Ballistix MOD Log file: %s. Cannot monitor RAM temperature."%e))
                return
            except:
                time.sleep(0.7)
                continue #probably locked by logger writing

            csvfile.seek(-30, 2)
            line = csvfile.readline()
            csvfile.close()
            RAMTemp = line.decode("utf-8").split(',')[2]
            if float(RAMTemp) <= float(fileconfig.config.get('TRIGGERS','low_temp')):
                eventHandle('E_TEMPERATURE',"Low RAM temperature")
            time.sleep(1) #the MOD logger only writes once per second

        eventQueue.put(("Status",'ram',"Not Running"))
    def terminate(self):
        self.running=False

'''
#detect chassis intrusion detection switch activation
class chasisMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'IntrusionSwitch'
    def run(self):
        CoInitialize()

        self.c = wmi.WMI()
        self.watcher = self.c.Win32_SystemEnclosure.watch_for()
        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue

            if event.BreachDescription != None:
                eventHandle('E_INTRUSION',"Breach detected %s"%event.BreachDescription)
            else:
                print("system enclosure event: ",event)

        CoUninitialize()
    def terminate(self):
        self.running = False
'''

class BTMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'BTmonitor'
        self.socket = None
    def run(self):
        self.running = True

        deviceIDStr = fileconfig.config.get('TRIGGERS','bluetooth_device_id')
        deviceID = hardwareconfig.BTStrToHex(deviceIDStr)

        if ':' not in deviceIDStr:
            eventQueue.put(("Status",'bluetooth','Error: Not configured'))
            eventQueue.put(("Log",'Bluetooth monitor error: Device not configured'))
            return
        eventQueue.put(("Status",'bluetooth','Connecting to device...'))

        #lack of timeout on this is not good
        error, result = winsockbtooth.connect(deviceID)
        if error == True:
            if result == 10060:
                eventQueue.put(("Status",'bluetooth',"Error: Connect failed"))
                eventQueue.put(("Log",'Bluetooth: Could not connect to %s'%deviceIDStr))
            elif result == 10050:
                eventQueue.put(("Status",'bluetooth',"Error: No Bluetooth"))
                eventQueue.put(("Log","Bluetooth: Error 10050: Bluetooth not enabled"))
            else:
                eventQueue.put(("Status",'bluetooth','Error: %s'%result))
                eventQueue.put(("Log",'Bluetooth: other error: %s'%result))

            return

        self.socket = result
        eventQueue.put(("Log",'Bluetooth: Connected to device %s'%deviceIDStr))
        eventQueue.put(("Status",'bluetooth','Active'))
        while self.running == True:
            error,result=winsockbtooth.recv(self.socket)
            if error == True:
                    if self.running == False:
                        eventQueue.put(("Status",'bluetooth','Not Running'))
                        return

                    eventHandle('E_BLUETOOTH',"Bluetooth connection lost")
                    eventQueue.put(("Status",'bluetooth','Error: Connection Lost'))

                    #if we didnt lose connection under trigger conditions
                    #assume user wants auto-reconnect (?)
                    error = True
                    attempts = 0
                    while error == True and attempts < 7:
                        eventQueue.put(("Status",'bluetooth','Error: Connection Failed'))
                        time.sleep(10*1+(attempts*5))
                        eventQueue.put(("Status",'bluetooth','Connecting...'))
                        error, result = winsockbtooth.connect(deviceID)
                        attempts = attempts + 1
                    self.socket = result

                    eventQueue.put(("Log",'Bluetooth: Reconnected to device %s'%deviceIDStr))
                    eventQueue.put(("Status",'bluetooth','Active'))

        eventQueue.put(("Status",'bluetooth','Not Running'))
    def terminate(self):
        self.running = False
        if self.socket != None:
            winsockbtooth.closesocket(self.socket)

#detect network cable removal or wifi AP loss
class adapterDisconnectMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'AdapterDisconnect'
    def run(self):
        try:
            CoInitialize()

            #this code repeated in lw-gui; put it in a function somewhere
            c = wmi.WMI()
            networkAdapters = c.Win32_NetworkAdapter(PhysicalAdapter=True)

            guidDict={}
            for ad in networkAdapters:
                guidDict[ad.Name] = ad.GUID

            self.c = wmi.WMI(moniker="//./root/WMI")
            self.watcher = self.c.MSNdis_StatusMediaDisconnect.watch_for()
        except:
            eventQueue.put(("Status",'netAdaptersOut','Disconnect: WMI Error'))
            return
        eventQueue.put(("Status",'netAdaptersOut','Disconnect: Active'))

        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            if event.InstanceName in guidDict.keys() and \
                guidDict[event.InstanceName] in fileconfig.config.get('TRIGGERS','adapterDisconGUIDS').split(';'):
                eventHandle('E_NET_CABLE_OUT',"Net adapter '%s' lost connection"%event.InstanceName)

        CoUninitialize()
        eventQueue.put(("Status",'netAdaptersOut','Disconnect: Not Running'))
    def terminate(self):
        self.running = False

#detect new network cable inserted
class adapterConnectMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'AdapterConnect'
    def run(self):
        try:
            CoInitialize()

            #this code repeated in lw-gui; put it in a function somewhere
            c = wmi.WMI()
            networkAdapters = c.Win32_NetworkAdapter(PhysicalAdapter=True)

            guidDict={}
            for ad in networkAdapters:
                guidDict[ad.Name] = ad.GUID

            self.c = wmi.WMI(moniker="//./root/WMI")
            self.watcher = self.c.MSNdis_StatusMediaConnect.watch_for()
        except:
            eventQueue.put(("Status",'netAdaptersIn','Connect: WMI Error'))
            return

        eventQueue.put(("Status",'netAdaptersIn','Connect: Active'))
        self.running = True
        while self.running == True:
            try:
                event = self.watcher(timeout_ms=2000)
            except wmi.x_wmi_timed_out:
                continue
            if event.InstanceName in guidDict.keys() and \
                guidDict[event.InstanceName] in fileconfig.config.get('TRIGGERS','adapterConGUIDS').split(';'):
                eventHandle('E_NET_CABLE_IN',"net adapter '%s' gained connection"%event.InstanceName)

        CoUninitialize()
        eventQueue.put(("Status",'netAdaptersIn','Connect: Not Running'))
    def terminate(self):
        self.running = False

class cameraMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'CameraMonitor'
    def run(self):
        try:
            s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
            s.bind( ('127.0.0.1', 22190) )
            self.socket = s
        except:
            eventQueue.put(("Status",'cameras',"Can't bind socket 22190\nIs another lockwatcher running?"))
            eventQueue.put(("Log","Can't bind socket 22190. Is another lockwatcher running?"))
            print('Camera listen exception: %s'%sys.exc_info()[0])
            return

        eventQueue.put(("Status",'cameras',"Active"))

        self.running = True
        while self.running == True:
            try:
                data = s.recv(16)
            except socket.error:
                if self.running == False: break
                debugLog('socket error.. rebinding and retrying')
                s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
                self.socket = s
                s.bind( ('127.0.0.1', 22190) )
                continue

            data = data.decode('UTF-8')
            debugLog('got data: %s'%str(data))

            if data == '1': eventHandle('E_CHASSIS_MOTION',"Chassis camera motion detected")
            elif data == '2': eventHandle('E_ROOM_MOTION',"Room camera motion detected")

        eventQueue.put(("Status",'cameras',"Not Running"))
    def terminate(self):
        self.running = False
        self.socket.shutdown(socket.SHUT_RD)
        self.socket.close()

#listen on port 22191, receive commands from from config programs
class configMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'ConfigMonitor'
    def run(self):
        try:
            s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
            s.bind( ('127.0.0.1', 22191) )
            self.socket = s
        except:
            eventQueue.put(("Log","Can't bind socket 22191"))
            return

        self.running = True
        while self.running == True:
            try:
                ready = select.select([s],[],[],120)
                if not ready[0]: continue
            except socket.error:
                if self.running == False: break
                debugLog('Socketerror in configmonitor %s'%str(sys.exc_info()))

                try:
                    s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
                    s.bind(('127.0.0.1', 22191))
                    self.socket = s
                except:
                    debugLog('Socketerror in configmonitor rebinding.. %s'%str(sys.exc_info()))

                continue

            data = s.recv(1024)
            command = data.decode('UTF-8')
            debugLog('In confmon: '+str(command))
            if ':' in command:
                command,value = command.split(':')
            else: value = None

            if command == 'newListener' and value != None:
                eventQueue.put(('newListener',value))
            elif command == 'getStatuses':
                eventQueue.put(('getStatuses',None))
            elif command == 'startMonitor' or command == 'stopMonitor':
                eventQueue.put((command,value))
            elif command == 'reloadConfig':
                eventQueue.put(('reloadConfig',None))
            else:
                eventQueue.put(('Log','Bad local command received: %s'%command))

    def terminate(self):
        self.running = False
        if self.socket != None:
            try:
                self.socket.shutdown(socket.SHUT_RD)
            except:
                pass
            self.socket.close()

#monitor for killswitch keypresses
class keyboardMonitor(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'KeyboardMonitor'
    def run(self):

        version = sys.getwindowsversion()
        if version.major == 6 and version.minor > 1:
            eventQueue.put(("Status",'killSwitch',"Error: Win8 Not Supported"))
            return

        keyQueue = Queue.Queue()
        self.interceptListener = hardwareconfig.interceptListenThread(keyQueue)
        self.interceptListener.start()

        self.reloadKeys = True
        self.running = True
        eventQueue.put(("Status",'killSwitch',"Active"))
        while self.running == True:
            if self.reloadKeys == True:
                try:
                    primaryKillKeys = {}
                    for key in fileconfig.config.get('TRIGGERS','kbd_kill_combo_1',0).split('+'):
                        if key == '': break
                        primaryKillKeys[int(key)] = False

                    secondaryKillKeys = {}
                    for key in fileconfig.config.get('TRIGGERS','kbd_kill_combo_2').split('+'):
                        if key == '': break
                        secondaryKillKeys[int(key)] = False
                except:
                    #reading and writing from same file
                    time.sleep(0.2)
                    continue
                self.reloadKeys = False

            try:
                eventType,eventDetails = keyQueue.get(True,1)
            except:
                if self.running == False: break
                continue

            if eventType == 'mouse':
                if eventDetails == 'Moved':
                    eventHandle('E_MOUSE_MOVE',"Mouse moved")
                elif eventDetails == 'Button':
                    eventHandle('E_MOUSE_BTN',"Mouse button pressed")
                continue
            else:
                key = eventDetails[0]

            if key in primaryKillKeys.keys():
                primaryKillKeys[key] = eventType
            if key in secondaryKillKeys.keys():
                secondaryKillKeys[key] = eventType

            if len(primaryKillKeys.keys()) > 0:
                for keyState in primaryKillKeys.values():
                    if keyState == False: break
                else:
                    eventHandle('E_KILL_SWITCH_1',"Kill switch 1 pressed")

            if len(secondaryKillKeys.keys()) > 0:
                for keyState in secondaryKillKeys.values():
                    if keyState == False: break
                else: eventHandle('E_KILL_SWITCH_2',"Kill switch 2 pressed")

        eventQueue.put(("Status",'killSwitch',"Not Running"))

    def reloadConfig(self):
        self.reloadKeys = True

    def terminate(self):
        self.running = False
        self.interceptListener.stop()

def isRunning(threadName,threadDict):
    if threadName in threadDict.keys() and \
        threadDict[threadName] != None and \
            threadDict[threadName].is_alive() == True:
                return True
    else: return False

REMOTE_LOCK = 1
REMOTE_STARTMONITOR = 2
REMOTE_STOPMONITOR = 3
REMOTE_SHUTDOWN = 4
REMOTE_KILLSWITCH = 5
commandList = range(REMOTE_LOCK,REMOTE_KILLSWITCH+1)

def executeRemoteCommand(command):
    result = True

    if command == REMOTE_LOCK:
        if hardwareconfig.checkLock() == False:
            AFroutines.lockScreen()
            result = sendemail.sendEmail("Command successful","Screen locked")
            eventQueue.put(("Log",'Screen locked due to remote command'))
        else:
            eventQueue.put(("Log",'Lock screen failed - command received while locked'))
            result = sendemail.sendEmail("Command failed","Screen already locked")

    elif command == REMOTE_STARTMONITOR:
        #cant check ispy camera status, just have to assume it was not monitoring
        iSpyPath = fileconfig.config.get('TRIGGERS','ispy_path')
        roomCamID = fileconfig.config.get('TRIGGERS','room_cam_id')
        if os.path.exists(iSpyPath):
            eventQueue.put(("Log","Starting room camera due to remote command"))
        else:
            eventQueue.put(("Log","iSpy executable not found - cannot fulfill remote command"))
            return

        subprocess.call([iSpyPath,'commands bringonline,2,%s'%roomCamID])
        result = sendemail.sendEmail("Command successful","Movement monitoring initiated. Have a nice day.")

    elif command == REMOTE_STOPMONITOR:
        #cant check ispy camera status, just have to assume it was already monitoring
        iSpyPath = fileconfig.config.get('TRIGGERS','ispy_path')
        roomCamID = fileconfig.config.get('TRIGGERS','room_cam_id')
        if os.path.exists(iSpyPath):
            eventQueue.put(("Log","Stopping room camera due to remote command"))
        else:
            eventQueue.put(("Log","iSpy executable not found - cannot fulfill remote command"))
            return

        subprocess.call([iSpyPath,'commands takeoffline,2,%s'%roomCamID])
        result = sendemail.sendEmail("Command successful","Movement monitoring disabled. Welcome home!")

    elif command == REMOTE_SHUTDOWN:
        result = sendemail.sendEmail("Command successful","Shutting down...")
        eventQueue.put(("Log","Initiating standard shutdown due to remote command"))
        AFroutines.standardShutdown()

    elif command == REMOTE_KILLSWITCH:
        eventQueue.put(("Log","Initiating emergency shutdown due to remote command"))
        AFroutines.emergency()

    if result != True: eventQueue.put(('Log','Mail send failed: %s'%result))

#this is a travesty
trigMonitorMap = {'bluetooth': 'BTMonitor',
                'killSwitch' : 'keyboardMonitor',
                'ram' : 'RAMMonitor',
                'cameras': 'cameraMonitor',
                'devices': 'deviceMonitor',
                'netAdaptersIn' : 'adapterConnectMonitor',
                'netAdaptersOut' : 'adapterDisconnectMonitor',
                'email':'email'}

trigEventMap = {'bluetooth': 'E_BLUETOOTH',
                'killSwitch' : 'E_KILL_SWITCH',
                'ram' : 'E_TEMPERATURE',
                'devices' : 'E_DEVICE',
                'netAdaptersIn' : 'E_NET_CABLE_IN',
                'netAdaptersOut' : 'E_NET_CABLE_OUT',
                'chasCam' : 'E_CHASSIS_MOTION',
                'roomCam' : 'E_ROOM_MOTION',
                'cameras' : 'E_CHASSIS_MOTION',
                'email':'email'}

def startMonitor(threadDict,trigger):
            if trigger == 'E_DEVICE':
                threadDict['deviceMonitor'] = deviceMonitor()
                threadDict['deviceMonitor'].start()
                threadDict['volumeMonitor'] = volumeMonitor()
                threadDict['volumeMonitor'].start()
                threadDict['logicalDiskRemoveMonitor'] = logicalDiskRemoveMonitor()
                threadDict['logicalDiskRemoveMonitor'].start()
                threadDict['logicalDiskCreateMonitor'] = logicalDiskCreateMonitor()
                threadDict['logicalDiskCreateMonitor'].start()
                #threadDict['logicalDeviceMonitor'] = LogicalDeviceMonitor()

            elif trigger == 'E_INTRUSION' :
                #threadDict['chasisMonitor'] = chasisMonitor()
                pass

            elif trigger == 'E_NET_CABLE_IN' :
                threadDict['adapterConnectMonitor'] = adapterConnectMonitor()
                threadDict['adapterConnectMonitor'].start()

            elif trigger == 'E_NET_CABLE_OUT' :
                threadDict['adapterDisconnectMonitor'] = adapterDisconnectMonitor()
                threadDict['adapterDisconnectMonitor'].start()

            elif trigger == 'E_TEMPERATURE':
                threadDict['RAMMonitor'] = RAMMonitor()
                threadDict['RAMMonitor'].start()

            elif trigger == 'E_BLUETOOTH':
                threadDict['BTMonitor'] = BTMonitor()
                threadDict['BTMonitor'].start()

            elif trigger == 'E_CHASSIS_MOTION' or trigger == 'E_ROOM_MOTION':
                if not isRunning('cameraMonitor',threadDict):
                    threadDict['cameraMonitor'] = cameraMonitor()
                    threadDict['cameraMonitor'].start()

            elif 'E_KILL_SWITCH' in trigger or trigger in ['E_MOUSE_MOVE','E_MOUSE_BTN'] :
                if not isRunning('keyboardMonitor',threadDict):
                    threadDict['keyboardMonitor'] = keyboardMonitor()
                    threadDict['keyboardMonitor'].start()

            elif trigger == 'email':
                threadDict['email'] = emailMonitor()
                threadDict['email'].start()
            else:
                eventQueue.put(("Log","Error: Startmonitor passed unknown trigger: %s"%trigger))

#send message to every connected listener
def broadcast(listeners,msg):
    badConnections = []
    msg = msg+'@@'
    for connection in listeners:
        try:
            connection.send(msg.encode())
            #print('lw service sent %s'%msg.encode())
        except:
            badConnections.append(connection)

    for connection in badConnections:
        listeners.remove(connection)

def addLogEntry(msg,listeners):
    entry = time.strftime('[%x %X] ')+msg+'\n'
    logPath = fileconfig.config.get('TRIGGERS','logfile')
    if not os.path.exists(logPath): return
    try:
        fd = open(logPath,'a+')
        fd.write(entry)
        fd.close()
    except:
        pass

    broadcast(listeners,'Log::'+entry)

class lockwatcher(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.name = 'Lockwatcher'
    def run(self):

        if fileconfig.config.get('TRIGGERS','debuglog') == 'True':
            global VERBOSELOGS
            VERBOSELOGS = True

        debugLog('Lockwatcher Started')

        global startupTime
        startupTime = time.time()

        #send log/status updates to connections in here - for config programs
        listeners = []

        confMonThread = configMonitor()
        confMonThread.start()

        LOCKED = fileconfig.config.get('TRIGGERS','lockedtriggers').split(',')
        ALWAYS = fileconfig.config.get('TRIGGERS','alwaystriggers').split(',')
        ACTIVE = LOCKED+ALWAYS

        global eventQueue
        eventQueue = Queue.Queue()

        threadStatuses = {}
        threadDict = {}

        for trigger in ACTIVE:
            if trigger != '': startMonitor(threadDict,trigger)

        if fileconfig.config.get('EMAIL','ENABLE_REMOTE') == 'True':
            startMonitor(threadDict,'email')

        #new month, new log
        logPath = fileconfig.config.get('TRIGGERS','logfile')
        if os.path.exists(logPath):
            creationTime = time.ctime(os.path.getctime(logPath))
            creationMonth = datetime.datetime.strptime(creationTime, "%a %b %d %H:%M:%S %Y")
            monthNow = time.strftime('%m %Y')
            if creationMonth != monthNow:
                try:
                    open(logPath, 'w').close()
                except: pass

        eventQueue.put(('Log','Lockwatcher monitoring started'))

        badCommands = 0
        shutdownActivated = False
        while True:
            event = eventQueue.get(block=True, timeout=None)
            debugLog('Event in queue: '+str(event))
            eventType = event[0]

            #--------------trigger activated under shutdown conditions
            if eventType == 'Kill':
                eventReason = event[1]
                #don't trigger multiple shutdowns but keep logging while we can
                if shutdownActivated == False:
                    shutdownActivated = True

                    if fileconfig.config.get('EMAIL','email_alert') == 'True' and \
                        'Kill switch' not in eventReason:
                        try:
                            #has a 4 second timeout for blocking operations
                            result = sendemail.sendEmail('Emergency shutdown triggered',eventReason)
                            if result != True:
                                eventQueue.put(('Log','Mail send failed: %s'%result))
                        except:
                            pass #email failed, oh well.
                    AFroutines.emergency()

            #--------------thread status changed, inform any listeners
            elif eventType == 'Status':
                #if self.statuses != None: self.statuses[event[1]].set(event[2])
                threadStatuses[event[1]] = event[2]
                msg = 'Status::%s::%s'%(event[1],event[2])
                broadcast(listeners,msg)

            #-----------config programs can request all the current statuses
            elif eventType == 'getStatuses':
                msg = 'AllStatuses::'
                for name,value in threadStatuses.items():
                    msg = msg+ '%s::%s|'%(name,value)
                msg = msg[:-1]

                broadcast(listeners,msg)

            #--------------add to log file + listener log window if they exist
            elif eventType == 'Log':
                addLogEntry(str(event[1]),listeners)

            elif eventType == 'stop':
                broadcast(listeners,'Shutdown')
                for threadname in threadDict.keys():
                    if isRunning(threadname,threadDict): threadDict[threadname].terminate()
                confMonThread.terminate()
                time.sleep(1) #give threads time to shutdown
                return

            elif eventType == 'startMonitor':
                monitor=event[1]
                if monitor in trigMonitorMap.keys():
                    thread = trigMonitorMap[monitor]
                else: continue
                if not isRunning(thread,threadDict): startMonitor(threadDict,trigEventMap[monitor])

            elif eventType == 'stopMonitor':
                monitor = event[1]

                if monitor == 'devices':
                    threadnames = ['deviceMonitor','volumeMonitor',
                                   'logicalDiskRemoveMonitor','logicalDiskCreateMonitor']
                else:
                    threadnames = [trigMonitorMap[monitor]]

                for threadname in threadnames:
                    if isRunning(threadname,threadDict):
                        threadDict[threadname].terminate()
                        threadDict[threadname] = None

            elif eventType == 'Mail':
                #malformed emails would be a good way of crashing lockwatcher
                #be careful to valididate mail here
                validMail = True
                try:
                    command, code = event[1].split(' ')
                    eventQueue.put(('Log','Received mail "%s %s"'%(command,code)))
                except:
                    validMail = False

                #forgive bad command codes - crappy attack and causes
                #loop if we look at our returned emails with same sender/recv addresss
                if validMail == True:
                    try:
                        command = int(command)
                        if command not in commandList:
                            continue
                    except:
                        continue

                if validMail == True and sendemail.validHMAC(code,command) == True:
                    executeRemoteCommand(command)
                    badCommands = 0 #good command resets limit
                else:
                    badCommands += 1
                    result = sendemail.sendEmail("Command failed","Bad command or authentication code received: %s"%str(event[1]))
                    if result != True:
                        eventQueue.put(('Log','Mail send failed: %s'%result))
                    eventQueue.put(('Log','Mail not authenticated or bad command: "%s". Ensure clocks are synchronised.'%str(event[1])))
                    badCommandLimit = int(fileconfig.config.get('EMAIL','BAD_COMMAND_LIMIT'))
                    if badCommandLimit > 0 and badCommands >= badCommandLimit:
                        addLogEntry(str(event[1]),listeners)

                        if shutdownActivated == False:
                            shutdownActivated = True
                            AFroutines.emergency()

                    continue

            elif eventType == 'reloadConfig':
                fileconfig.reloadConfig()
                if isRunning('keyboardMonitor',threadDict): threadDict['keyboardMonitor'].reloadConfig()
                #eventQueue.put(('Log','Config reload forced'))  #debugmode

            elif eventType == 'newListener':
                port = int(event[1])
                s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                eventQueue.put(('Log','Lockwatcher connected to new configuration client'))
                try:
                    s.connect( ('127.0.0.1', port) )
                except:
                    eventQueue.put(('Log','Error: Failed to connect to client port: '+str(port)))
                    continue

                s.send(b'True@@')
                listeners.append(s)

            else:
                eventQueue.put(('Log','Error: Unknown event in queue: '+str(event)))

    def stop(self,msg=None):
        if msg != None: eventQueue.put(('Log',msg))
        eventQueue.put(('stop',None))

monitorThread = None
def createLockwatcher():
    global monitorThread

    monitorThread = lockwatcher()

import cx_Logging #including here so cx_Freeze adds the .pyd for sm.exe to use
import servicemanager

class lockwatcherSvc (object):
    def __init__(self):
        socket.setdefaulttimeout(60.0)
        self.running = True

    def Initialize(self, configFileName):
        pass

    def SessionChanged(self, sessionID, event_type):
        SESSION_LOCK = 0x7
        SESSION_UNLOCK = 0x8

        if event_type == SESSION_LOCK:
                hardwareconfig.lockState = True
        elif event_type == SESSION_UNLOCK:
                hardwareconfig.lockState = False
        else: return

    def Stop(self):
        monitorThread.stop('Service Stop')

    def Run(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              ('Lockwatcher',''))
        debugLog('starting service: Run')
        try:
            self.main()
        except:
            debugLog('EXCEPTION %s in main'%str(sys.exc_info()[0]))

    def main(self):
        createLockwatcher()
        monitorThread.start()
        while monitorThread.is_alive() == True:
            time.sleep(2)


text:
<?php

namespace Abbaye\IndexBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * AgencesRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class AgencesRepository extends EntityRepository
{
}


text:
module Session where

import           Control.Arrow hiding (app)
import           Control.Concurrent
import           Control.Concurrent.STM
import           Control.Monad
import qualified Data.ByteString.Lazy as L
import           Data.List
import           Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import           Data.Maybe
import           Data.Set (Set)
import qualified Data.Set as S
import qualified Data.Text as T
import           Distribution.Text (display)
import           Stackage.View.Cabal
import           Stackage.View.Git
import           Stackage.View.Types
import           Filesystem as FP
import           Filesystem.Loc as FL
import           Filesystem.Path (FilePath)
import qualified Filesystem.Path.CurrentOS as FP
import           IdeSession hiding (errorSpan,errorMsg)
import           Import hiding (FilePath)
import           Language.Haskell.Extension
import           Prelude hiding (FilePath,writeFile,pi)
import           SharedTypes

-- | Continue the session with the given unambiguous targets.
continueWith :: [TargetIdent] -> App -> IO ()
continueWith targets app =
  do unloadTargets (appSession app) (appLoadedTargets app) targets
     loadProject
       (appSession app)
       (M.fromList
          (map (\target ->
                  (targetIdent target,any (== targetIdent target) targets))
               (appTargets app)))
       (mapMaybe (\ident ->
                    find ((== ident) . targetIdent)
                         (appTargets app))
                 targets)
       (appDataFiles app)
       (appLoading app)
       (appLoadedTargets app)

-- | Unload targets.
unloadTargets :: IdeSession -> TVar [Target] -> [TargetIdent] -> IO ()
unloadTargets sess loadedTargets except =
  do targets <- atomically (readTVar loadedTargets)
     let allTargetFiles =
           mconcat (map targetFiles
                        (filter (not .
                                 flip elem except .
                                 targetIdent)
                                targets))
     updateSession
       sess
       (mconcat (map (updateSourceFileDelete . FL.encodeString)
                     (S.toList allTargetFiles)))
       (const (return ()))

-- | Start the session with the cabal file, will not proceed if the
-- targets are unambiguous, in which case it will be continued later
-- after prompting the user.
startSession :: TVar [Target]
             -> TVar LoadingStatus
             -> IO (IdeSession,[Target],Set FilePath)
startSession loadedTargets loading =
  do dir <- FL.getWorkingDir
     cabalfp <- getCabalFp dir
     targets <- getTargets mempty cabalfp
     datafiles <- getGitFiles >>= fmap S.fromList . filterM isFile . S.toList
     session <-
       initSession (sessionParams targets)
                   defaultSessionConfig
     if length (filter (needsMain . targetIdent) targets) >
        1
        then atomically (writeTVar loading (AmbiguousTargets (map targetIdent targets)))
        else loadProject
               session
               (M.fromList
                  (map (targetIdent &&&
                        const True)
                       targets))
               targets
               datafiles
               loading
               loadedTargets
     return (session,targets,datafiles)
  where sessionParams targets =
          defaultSessionInitParams {sessionInitGhcOptions =
                                      ["-hide-all-packages"] <>
                                      concatMap includePackage
                                                (concatMap targetDependencies targets)}
          where includePackage pkgName =
                  ["-package",display pkgName]

-- | Load the project into the ide-backend.
loadProject :: IdeSession
            -> Map TargetIdent Bool
            -> [Target]
            -> Set FilePath
            -> TVar LoadingStatus
            -> TVar [Target]
            -> IO ()
loadProject session targetChoices targets datafiles loading loadedTargets =
  void (forkIO (do atomically (writeTVar loadedTargets targets)
                   setOpts session targets
                   loadFiles session targetChoices targets datafiles loading))

-- | Set GHC options.
setOpts  :: IdeSession -> [Target] ->  IO ()
setOpts sess targets =
  updateSession sess
                (updateGhcOpts (map showExt (concatMap targetExtensions targets)))
                (const (return ()))
  where showExt :: Extension -> String
        showExt g =
          case g of
            EnableExtension e -> "-X" <> show e
            DisableExtension e -> "-XNo" <> show e
            UnknownExtension e -> "-X" <> show e

-- | Load the package files and update the app state of the progress.
loadFiles :: IdeSession
          -> Map TargetIdent Bool
          -> [Target]
          -> Set FilePath
          -> TVar LoadingStatus
          -> IO ()
loadFiles sess targetChoices targets files loading =
  do updates <- forM loadedFiles
                     (\fp ->
                        do content <- L.readFile (FL.encodeString fp)
                           return (updateSourceFile (FL.encodeString fp)
                                                    content))
     updates' <- forM (S.toList files)
                      (\fp ->
                         do content <- L.readFile (FP.encodeString fp)
                            return (updateDataFile (FP.encodeString fp)
                                                   content))
     atomically (writeTVar loading NotLoading)
     updateSession
       sess
       (mconcat updates <> mconcat updates' <>
        updateCodeGeneration True)
       (\progress ->
          atomically
            (writeTVar loading
                       (Loading (progressStep progress)
                                (progressNumSteps progress)
                                (fromMaybe (fromMaybe "Unknown step" (progressOrigMsg progress))
                                           (progressParsedMsg progress)))))
     errs <- fmap (filter isError)
                  (getSourceErrors sess)
     if null errs
        then atomically
               (writeTVar loading
                          (LoadOK (M.toList targetChoices)
                                  (map (T.pack . FL.encodeString)
                                       (sort loadedFiles))))
        else atomically (writeTVar loading (LoadFailed (map toError errs)))
  where loadedFiles =
          S.toList (mconcat (map targetFiles targets))
        isError (SourceError{errorKind = k}) =
          case k of
            KindError -> True
            KindServerDied -> True
            KindWarning -> False

-- | Convert a source error to either an unhelpful text span or a
-- proper span.
toError :: SourceError -> Either Text Error
toError (SourceError _ espan msg) =
  case espan of
    ProperSpan (SourceSpan path sl sc el ec) ->
      Right (Error {errorFile = T.pack path
                   ,errorSpan = Span sl sc el ec
                   ,errorMsg = msg})
    TextSpan e -> Left e


text:
clear; clc;
segmentationFile = '/home/mina/Downloads/vKitti/vkitti_1.3.1_scenegt/0001_clone_scenegt_rgb_encoding.txt';
detectionFile = '/home/mina/Downloads/vKitti/vkitti_1.3.1_motgt/0001_clone.txt';
imageList = 342:399;
images = [];
for i=1:length(imageList)
    if i==1
        assignObjectID = 1;
        image = createImageObject(segmentationFile,detectionFile,i,imageList,assignObjectID);
    else
        assignObjectID = 0;
        image = createImageObject(segmentationFile,detectionFile,i,imageList,assignObjectID);
    end
    images = [images, image];
end
[imagesUniqueID, wrongAssociations] = objectTracker(images);

%plot objetcs of currentImage & image
%         for j=1:currentImage.nObjects
%             rgb = currentImage.uniqueRGB(j,:);
%             mask = I(:,:,1)==rgb(1) & I(:,:,2)==rgb(2) & I(:,:,3)==rgb(3);
%             I_masked = I;
%             new_mask = repmat(mask, 1,1,3);
%             I_masked(new_mask) = 0;
%             add_mask = zeros(size(new_mask), 'uint8');
%             add_mask(:,:,1) = mask*255;
%             I_masked = I_masked + add_mask;
%             figure; imagesc(I_masked);
%             end

result = {};
for i=1:length(imagesUniqueID)
    for j=1:imagesUniqueID(i).nObjects
        classGT = imagesUniqueID(i).objects(j).classGT;
        id = imagesUniqueID(i).objects(j).id;
        if i==1
            result{j,1} = classGT;
            result{j,2} = id;
        else
            [exists,index] = ismember(classGT,result(:,1));
            if ~exists
                result{end+1,1} = classGT;
                result{end,2} = id;
            else
                result{index,2} = [result{index,2},id];
            end
        end
    end
end


text:
package com.google.javascript.jscomp.parsing;

import com.google.javascript.rhino.head.Token;

/**
 * Wrapper for the two comment types so that we can provide an implementation
 * of the Comment interface, regardless of which parser is used.
 */
public class CommentWrapper implements Comment {
  private boolean jsDoc;
  private int position;
  private int length;

  public CommentWrapper(com.google.javascript.jscomp.parsing.parser.trees.Comment comment) {
    jsDoc = comment.type ==
        com.google.javascript.jscomp.parsing.parser.trees.Comment.Type.JSDOC;
    position = comment.location.start.offset;
    length = comment.location.end.offset - position;
  }

  public CommentWrapper(com.google.javascript.rhino.head.ast.Comment comment) {
    jsDoc = comment.getCommentType() == Token.CommentType.JSDOC;
    position = comment.getAbsolutePosition();
    length = comment.getLength();
  }

  @Override
  public boolean isJsDoc() {
    return jsDoc;
  }

  @Override
  public int getAbsolutePosition() {
    return position;
  }

  @Override
  public int getLength() {
    return length;
  }
}


text:
#ifndef FOOLGO_SRC_PLAYER_SGF_PLAYER_H_
#define FOOLGO_SRC_PLAYER_SGF_PLAYER_H_

#include <cassert>
#include <cstdint>

#include "board/full_board.h"
#include "board/position.h"
#include "game/game_info.h"
#include "passable_player.h"

namespace foolgo {

template <BoardLen BOARD_LEN>
class SgfPlayer : public PassablePlayer<BOARD_LEN> {
 public:
  SgfPlayer() = default;

  SgfPlayer(const GameInfo &game_info) : game_info_(&game_info) {}

 protected:
  PositionIndex NextMoveWithPlayableBoard(
      const FullBoard<BOARD_LEN> &full_board);

 private:
  const GameInfo *game_info_ = nullptr;
};

template<BoardLen BOARD_LEN>
PositionIndex SgfPlayer<BOARD_LEN>::NextMoveWithPlayableBoard(
    const FullBoard<BOARD_LEN>& full_board) {
  auto playable_indexes =
    full_board.PlayableIndexes(NextForce(full_board));
  assert(!playable_indexes.empty());

  int index = full_board.MoveCount();
  assert(index <= game_info_->moves.size());
  if (index == game_info_->moves.size()) {
    return POSITION_INDEX_END;
  }

  Move move = game_info_->moves.at(index);
  if (index > 0 && move.force != OppositeForce(full_board.LastForce())) {
    std::cerr << "index:" << index << " last force:" <<
      ForceToString(full_board.LastForce()) << " current force:" <<
          ForceToString(move.force) << std::endl;
    abort();
  }
  return move.position_index;
}

} /* namespace foolgo */

#endif


text:
package org.springframework.boot.test.autoconfigure.json;

import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.json.app.ExampleBasicObject;
import org.springframework.boot.test.autoconfigure.json.app.ExampleJsonApplication;
import org.springframework.boot.test.json.BasicJsonTester;
import org.springframework.boot.test.json.GsonTester;
import org.springframework.boot.test.json.JacksonTester;
import org.springframework.boot.test.json.JsonbTester;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Integration tests for {@link JsonTest @JsonTest} with
 * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}.
 *
 * @author Phillip Webb
 */
@RunWith(SpringRunner.class)
@JsonTest
@AutoConfigureJsonTesters(enabled = false)
@ContextConfiguration(classes = ExampleJsonApplication.class)
public class JsonTestWithAutoConfigureJsonTestersTests {

	@Autowired(required = false)
	private BasicJsonTester basicJson;

	@Autowired(required = false)
	private JacksonTester<ExampleBasicObject> jacksonTester;

	@Autowired(required = false)
	private GsonTester<ExampleBasicObject> gsonTester;

	@Autowired(required = false)
	private JsonbTester<ExampleBasicObject> jsonbTester;

	@Test
	public void basicJson() {
		assertThat(this.basicJson).isNull();
	}

	@Test
	public void jackson() {
		assertThat(this.jacksonTester).isNull();
	}

	@Test
	public void gson() {
		assertThat(this.gsonTester).isNull();
	}

	@Test
	public void jsonb() {
		assertThat(this.jsonbTester).isNull();
	}

}


text:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="36dp"
    android:height="36dp"
    android:viewportHeight="48"
    android:viewportWidth="48">

    <group android:name="next_group">

        <path
            android:name="next"
            android:fillColor="@android:color/white"
            android:pathData="M24 8l-2.83 2.83L32.34 22H8v4h24.34L21.17 37.17 24 40l16-16z" />

    </group>

</vector>


text:
package models

type LocationArea struct {
	ID                   int                   `json:"id"`
	Name                 string                `json:"name"`
	Names                []Name                `json:"names"`
	GameIndex            int                   `json:"game_index"`
	EncounterMethodRates []EncounterMethodRate `json:"encounter_method_rates"`
	LocationProxy        NamedAPIResource      `json:"location"`
	PokemonEncounters    []PokemonEncounter    `json:"pokemon_encounters"`
	Location             *Region
}


text:
using System.Collections.Generic;
using System.Threading.Tasks;
using NuKeeper.Abstractions.Configuration;
using NuKeeper.Abstractions.NuGet;
using NuKeeper.Abstractions.RepositoryInspection;

namespace NuKeeper.Inspection.NuGetApi
{
    public interface IPackageUpdatesLookup
    {
        Task<IReadOnlyCollection<PackageUpdateSet>> FindUpdatesForPackages(
            IReadOnlyCollection<PackageInProject> packages,
            NuGetSources sources,
            VersionChange allowedChange,
            UsePrerelease usePrerelease);
    }
}


text:
"""
Read the phage fasta and plot a tSNE. This is adapted from phage_protein_data.py
"""

import os
import sys
import argparse
import json

import numpy as np
from sklearn.mixture import GaussianMixture
from sklearn.manifold import TSNE

from matplotlib import pyplot as plt
from mpl_toolkits import mplot3d

import seaborn as sns
sns.set()

import pandas as pd

import itertools

from roblib import bcolors, stream_fasta

__author__ = 'Rob Edwards'

def count_pairwise(faf, kmer, verbose=True):
    """
    Count all pairwise amino acids
    :param faf: fasta file
    :param kmer: kmer size
    :param verbose: more output
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Reading {faf}{bcolors.ENDC}\n")

    count = {}
    fns = {}
    for sidf, seq in stream_fasta(faf, whole_id=True):
        posn=0
        # split the sequence id into sequence and function
        # may need to provide an alternate way to do this
        # note we also strip out [organism name]
        sid = sidf[:sidf.index(" ")]
        try:
            fns[sid] = sidf[sidf.index(" ")+1:sidf.index("[")-1]
        except:
            fns[sid] = sidf[sidf.index(" ")+1:]

        count[sid]={}
        while posn < len(seq)-(kmer-1):
            count[sid][seq[posn:posn+kmer]] = count[sid].get(seq[posn:posn+kmer], 0)+1
            posn += 1
        # normalize by protein length
        for aa in count[sid]:
            count[sid][aa] /= len(seq)
    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Read {faf}{bcolors.ENDC}\n")

    return count, fns

def count_pairwise_no_fn(faf, kmer, verbose=True):
    """
    Count all pairwise amino acids
    :param faf: fasta file
    :param kmer: kmer size
    :param verbose: more output
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Reading {faf}{bcolors.ENDC}\n")

    count = {}
    for sid, seq in stream_fasta(faf, whole_id=True):
        posn=0
        count[sid]={}
        while posn < len(seq)-(kmer-1):
            count[sid][seq[posn:posn+kmer]] = count[sid].get(seq[posn:posn+kmer], 0)+1
            posn += 1
        # normalize by protein length
        for aa in count[sid]:
            count[sid][aa] /= len(seq)
    return count

def read_fns(fnf, verbose=True):
    """
    Read the tsv of protein id/function. We use this when the function
    is not included in the fasta file
    """
    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Reading functions from {fnf}{bcolors.ENDC}\n")

    fns={}
    with open(fnf, 'r') as f:
        for l in f:
            p=l.strip().split("\t")
            fns[p[0]]=p[1]
    return fns

def counts_to_df(counts, kmer, verbose=False):
    """
    Convert the count dict to a pandas data frame
    :param counts: the dict of sequences, aa and counts
    :param kmer: the kmer size
    :param verbose: more output
    :return pd.DataFrame
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Making possibilities{bcolors.ENDC}\n")

    # this works for K< 7
    # iupac= ["".join(tple) for tple in itertools.product('ACDEFGHIKLMNPQRSTVWY', repeat=kmer)]

    allmers = set()
    for s in counts:
        allmers.update(counts[s].keys())

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Converting to matrix {bcolors.ENDC}\n")

    aml = list(allmers)
    aml.sort()

    pc = {}
    for sid in counts:
        pc[sid] = []
        for aa in aml:
            pc[sid].append(counts[sid].get(aa, 0))

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Converting to dataframe{bcolors.ENDC}\n")

    df = pd.DataFrame.from_dict(pc, orient='index', columns=aml)
    return df

def unique_functions(fns, verbose=False):
    """
    Returns the number of unique functions
    :param functions: the dict of functions
    :param verbose: more output
    :returns: int
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Unique functions{bcolors.ENDC}\n")

    return len(set(fns.values()))

def fns_to_list(fns, df, verbose=False):
    """
    Conver the functions to an ordered list based on the df
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Listifying functions{bcolors.ENDC}\n")

    return [fns[x] for x in df.index.values]

def create_tSNE(df, fnar, tout, verbose):
    """
    Generate the tSNE data and write it to a text file
    :param df: the data frame
    :param fnar: the function array
    :param tout: the output file to write
    :param verbose: more output
    :return: the tSNE array
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Generating tSNE {bcolors.ENDC}\n")

    tsne = TSNE(n_components=3, perplexity=50, n_iter=5000)
    X = tsne.fit_transform(df)
    if tout:
        data = {
            'tSNE' : X.tolist(),
            'functions' : fnar
        }
        with open(tout, 'w') as out:
            json.dump(data, out)

    return X

def filternz(df, verbose=True):
    """
    Filter columns that sum to 0. We want to remove these
    :param df: the data frame
    :param verbose: more output
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Filtering to remove column sums == 0{bcolors.ENDC}\n")
    return df.loc[:, df.sum() != 0]

def plot_2d(tsne, fnar, palette, outpng, verbose):
    """
    Create the 2d plot
    :param tsne: tSNE array
    :param fnar: functions list
    :param outpng: base name for pg output
    :return: nothing
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Plotting 2D tSNE{bcolors.ENDC}\n")

    snsplot = sns.scatterplot(tsne[:,0], tsne[:,1], legend="full", hue=fnar, palette=palette)
    plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
    plt.tight_layout()
    plt.savefig(outpng + ".png")

def plot_2d_sz(tsne, fnar, palette, outpng, verbose):
    """
    Create the 2d plot
    :param tsne: tSNE array
    :param fnar: functions list
    :param outpng: base name for pg output
    :return: nothing
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Plotting 2D tSNE by size{bcolors.ENDC}\n")

    sp = sns.scatterplot(x=tsne[:,0], y=tsne[:,1], s=tsne[:,2], legend="full", hue=fnar, palette=palette)
    plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
    plt.tight_layout()
    plt.savefig(outpng + ".sz.png")

def plot_3d(tsne, fnar, palette, outpng, verbose):
    """
    Create the 3d plot
    :param tsne: tSNE array
    :param fnar: functions list
    :param outpng: base name for pg output
    :return: nothing
    """

    if verbose:
        sys.stderr.write(f"{bcolors.GREEN}Plotting 3D tSNE by size{bcolors.ENDC}\n")

    plt.clf()
    ax = plt.gca(projection='3d')

    fig = plt.figure(figsize=(40, 40))
    ax = fig.add_subplot(111, projection='3d')

    ax.scatter(tsne[:,0], tsne[:,1], tsne[:,2], s=50, alpha=0.6, edgecolors='w')

    ax.set_xlabel('tSNE-1')
    ax.set_ylabel('tSNE-2')
    ax.set_zlabel('tSNE-3')

    plt.tight_layout()
    plt.savefig(outpng + ".3d.png")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=' ')
    parser.add_argument('-f', help='fasta input file', required=True)
    parser.add_argument('-k', help='kmer size (default=2)', default=2, type=int)
    parser.add_argument('-p', help='png output file', required=True)
    parser.add_argument('-t', help='tSNE output file')
    parser.add_argument('-d', help="dataframe tsv output file")
    parser.add_argument('-n', help='functions file. If not provided will try and extract from fasta file')
    parser.add_argument('-v', help='verbose output', action='store_true')
    args = parser.parse_args()

    if args.n:
        counts = count_pairwise_no_fn(args.f, args.k, args.v)
        fns = read_fns(args.t, args.v)
    else:
        counts, fns = count_pairwise(args.f, args.k, args.v)

    df = counts_to_df(counts, args.k, args.v)
    # Since we only make the df with non zero entries, don't need to do this
    # but should perhaps filter for correlated values
    # df = filternz(dfz, True)
    # if args.v:
    #     sys.stderr.write(f"{bcolors.BLUE}Shape before removing zeros: {dfz.shape} and after: {df.shape}\n")

    if args.d:
        with open(args.d, 'w') as out:
            df.to_csv(out, "\t")

    numcol = unique_functions(fns, args.v)
    palette = sns.color_palette("bright", numcol)
    fnar = fns_to_list(fns, df, args.v)

    tsne = create_tSNE(df, fnar, args.t, args.v)

    outpng = args.p.replace('.png', '')
    plot_2d(tsne, fnar, palette, outpng, args.v)

    # plot_2d_sz(tsne, fnar, palette, outpng, args.v)

    # plot_3d(tsne, fnar, palette, outpng, args.v)