<commit_before>'use strict';

import * as net from 'net';
import * as path from 'path';
import * as cp from 'child_process';

class GameWrapper
{
	private static getWrapperExecutable()
	{
		let binFolder = path.resolve( __dirname, '..', 'bin' );
		switch ( process.platform ) {
			case 'win32':
				return path.join( binFolder, 'game_jolt_game_wrapper_win32.exe' );
			case 'linux':
				return path.join( binFolder, 'game_jolt_game_wrapper_linux' );
			case 'osx':
				return path.join( binFolder, 'game_jolt_game_wrapper_osx' );
		}

		// Plan for the future, yo
		throw new Error( new Date().getFullYear() > 2100 ?
			'Pepperidge Farm remembers back in 2016 we were still using Windows, Linux or Mac. Kids these days...' :
			'What kind of potato are you running on?' );
	}

	private static findFreePort(): number
	{
		for ( let i = 0; i < 5; i++ ) {
			// Get a random port between 1024 and 65535
			let port = 1024 + Math.floor( Math.random() * ( 0xFFFF - 1024 ) );
			let server = net.createServer();
			server.listen( port );
			server.close();
			return port;
		}
		return 0;
	}

	static start( wrapperId: string, cmd: string, args: string[], options?: cp.SpawnOptions )
	{
		let wrapperExecutable = this.getWrapperExecutable();
		let wrapperPort = this.findFreePort();

		let child = cp.spawn( wrapperExecutable, [ wrapperId, cmd, wrapperPort.toString() ].concat( args ), options );
		child.unref();

		return wrapperPort;
	}
}

export = GameWrapper;<commit_msg>Make sure game wrapper executable is executable<commit_after>'use strict';

import * as fs from 'fs';
import * as net from 'net';
import * as path from 'path';
import * as cp from 'child_process';

class GameWrapper
{
	private static getWrapperExecutable()
	{
		let binFolder = path.resolve( __dirname, '..', 'bin' );
		switch ( process.platform ) {
			case 'win32':
				return path.join( binFolder, 'game_jolt_game_wrapper_win32.exe' );
			case 'linux':
				return path.join( binFolder, 'game_jolt_game_wrapper_linux' );
			case 'osx':
				return path.join( binFolder, 'game_jolt_game_wrapper_osx' );
		}

		// Plan for the future, yo
		throw new Error( new Date().getFullYear() > 2100 ?
			'Pepperidge Farm remembers back in 2016 we were still using Windows, Linux or Mac. Kids these days...' :
			'What kind of potato are you running on?' );
	}

	private static findFreePort()
	{
		for ( let i = 0; i < 5; i++ ) {
			// Get a random port between 1024 and 65535
			let port = 1024 + Math.floor( Math.random() * ( 0xFFFF - 1024 ) );
			let server = net.createServer();
			server.listen( port );
			server.close();
			return port;
		}
		return 0;
	}

	static start( wrapperId: string, cmd: string, args: string[], options?: cp.SpawnOptions )
	{
		let wrapperExecutable = this.getWrapperExecutable();
		let wrapperPort = this.findFreePort();

		// Ensure that the wrapper executable is.. executable.
		fs.chmodSync( wrapperExecutable, '0755' );
		
		let child = cp.spawn( wrapperExecutable, [ wrapperId, cmd, wrapperPort.toString() ].concat( args ), options );
		child.unref();

		return wrapperPort;
	}
}

export = GameWrapper;
{'fraction_non_alphanumeric': 0.12818856958346786, 'fraction_numerical': 0.022602518566354538, 'mean_word_length': 3.61698956780924, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7167680', 'n_tokens_mistral': 1159, 'n_tokens_neox': 989, 'n_words': 319}