<commit_before>var https = require( "https" ),
	exec = require( "child_process" ).exec,
	diff = require( "./diff" );

getAuth(function( username, password ) {
	var auth = username && password ? username + ":" + password : null,
		args = process.argv.slice( 2 ),
		publicGist = args.indexOf( "--public" );
	
	if ( publicGist !== -1 ) {
		args.splice( publicGist, 1 );
	}
	
	diff( args, function( error, parsedDiff ) {
		var files = {};
		for ( var file in parsedDiff ) {
			files[ file.replace( /\//g, "-" ) + ".diff" ] = {
				content: parsedDiff[ file ].join( "\n" )
			};
		}
		postGist({
			"public": publicGist !== -1,
			files: files
		}, auth, showGist );
	});
});

function postGist( settings, auth, fn ) {
	var data = JSON.stringify( settings ),
		headers = {
			"Content-length": data.length
		};
	
	if ( auth ) {
		headers.Authorization = "Basic " + new Buffer( auth ).toString( "base64" );
	}
	
	var req = https.request({
		host: "api.github.com",
		port: 443,
		path: "/gists",
		method: "POST",
		headers: headers
	}, function( res ) {
		var response = "";
		res.setEncoding( "utf8" );
		res.on( "data", function( chunk ) {
			response += chunk;
		});
		res.on( "end", function() {
			fn( JSON.parse( response ) );
		});
	});
	
	req.write( data );
	req.end();
}

function showGist( data ) {
	if ( data.html_url ) {
		exec( "open " + data.html_url );
	} else {
		console.log( data.message );
	}
}

function getUsername( fn ) {
	exec( "git config --get github.user", function( error, stdout ) {
		fn( stdout.trim() );
	});
}

function requestPassword( username, fn ) {
	process.stdout.write( "GitHub password for " + username + ": " );
	require( "tty" ).setRawMode( true );
	process.stdin.resume();
	process.stdin.setEncoding( "utf8" );

	var password = "";
	process.stdin.on( "data", function( chunk ) {
		if ( chunk.charCodeAt( 0 ) === 13 ) {
			process.stdin.pause();
			console.log( "" );
			fn( password );<commit_msg>gist-diff: Resume stdin before settings raw mode.<commit_after>var https = require( "https" ),
	exec = require( "child_process" ).exec,
	diff = require( "./diff" );

getAuth(function( username, password ) {
	var auth = username && password ? username + ":" + password : null,
		args = process.argv.slice( 2 ),
		publicGist = args.indexOf( "--public" );
	
	if ( publicGist !== -1 ) {
		args.splice( publicGist, 1 );
	}
	
	diff( args, function( error, parsedDiff ) {
		var files = {};
		for ( var file in parsedDiff ) {
			files[ file.replace( /\//g, "-" ) + ".diff" ] = {
				content: parsedDiff[ file ].join( "\n" )
			};
		}
		postGist({
			"public": publicGist !== -1,
			files: files
		}, auth, showGist );
	});
});

function postGist( settings, auth, fn ) {
	var data = JSON.stringify( settings ),
		headers = {
			"Content-length": data.length
		};
	
	if ( auth ) {
		headers.Authorization = "Basic " + new Buffer( auth ).toString( "base64" );
	}
	
	var req = https.request({
		host: "api.github.com",
		port: 443,
		path: "/gists",
		method: "POST",
		headers: headers
	}, function( res ) {
		var response = "";
		res.setEncoding( "utf8" );
		res.on( "data", function( chunk ) {
			response += chunk;
		});
		res.on( "end", function() {
			fn( JSON.parse( response ) );
		});
	});
	
	req.write( data );
	req.end();
}

function showGist( data ) {
	if ( data.html_url ) {
		exec( "open " + data.html_url );
	} else {
		console.log( data.message );
	}
}

function getUsername( fn ) {
	exec( "git config --get github.user", function( error, stdout ) {
		fn( stdout.trim() );
	});
}

function requestPassword( username, fn ) {
	process.stdout.write( "GitHub password for " + username + ": " );
	process.stdin.resume();
	process.stdin.setEncoding( "utf8" );
	require( "tty" ).setRawMode( true );

	var password = "";
	process.stdin.on( "data", function( chunk ) {
		if ( chunk.charCodeAt( 0 ) === 13 ) {
			process.stdin.pause();
			console.log( "" );
			fn( password );
{'fraction_non_alphanumeric': 0.18980532786885246, 'fraction_numerical': 0.007172131147540984, 'mean_word_length': 3.0804597701149423, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '856869', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1382, 'n_words': 348}