Last active
September 28, 2024 20:34
-
-
Save ankurparihar/24c0f6e34455e075e0177072cfc7ee9c to your computer and use it in GitHub Desktop.
count-to-a-million-challenge-script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For: https://www.reddit.com/r/webdev/comments/1frg8r2/i_built_a_website_that_will_be_won_by_the_first/ | |
// Writeup: https://medium.com/@ankurparihar/count-to-million-challange-javascript-2c1b534c2040 | |
var WebSocketClient = require('websocket').client; | |
var client = new WebSocketClient(); | |
client.on('connectFailed', function(error) { | |
console.log('Connect Error: ' + error.toString()); | |
}); | |
client.on('connect', function(connection) { | |
console.log('WebSocket Client Connected'); | |
connection.on('error', function(error) { | |
console.log("Connection Error: " + error.toString()); | |
}); | |
connection.on('close', function() { | |
console.log('echo-protocol Connection Closed'); | |
process.exit(1); | |
}); | |
let begin = 1; | |
connection.on('message', function(message) { | |
if (message.type === 'utf8') { | |
console.log("Received: '" + message.utf8Data + "'"); | |
try { | |
const {value} = JSON.parse(message.utf8Data); | |
begin = value+1; | |
} catch (error) { | |
console.error(`parsing error`, message.utf8Data); | |
} | |
sendNext(); | |
} | |
}); | |
function sendNext(){ | |
connection.send(JSON.stringify({ | |
type: "update-count", | |
"value": begin++ | |
})) | |
} | |
}); | |
client.connect('wss://api.counttoamillion.com/score', 'echo-protocol', "https://counttoamillion.com", { | |
cookie: "_ga=GA1.1.305294779.1727544835; __cf_bm=9.h7HbdFXLfSO3jssYCRrIBZxHlZcYRo4GY_.Bts55s-1727544835-1.0.1.1-.7vgPRlXmOKT7G.njNb4VdmivRiUp_ZfSQywGawOJrKdnYf9e9USzi8DIyEmMekOrDRWWBkEJrKoUdtg3aq3EQ; session=2e69c256-cb3e-450f-b028-74044c398758; _ga_CGDJG53NZW=GS1.1.1727544835.1.1.1727544995.0.0.0", | |
"sec-websocket-extensions": "permessage-deflate; client_max_window_bits", | |
"sec-websocket-version": 13, | |
"sec-websocket-key": "rAFyF97qnokQvlIpmEt43w==", | |
accept: "gzip, deflate, br, zstd", | |
"accept-language": "en-US,en;q=0.9", | |
"cache-control": "no-cache", | |
connection: "Upgrade", | |
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "counttoamillion", | |
"version": "1.0.0", | |
"description": "", | |
"main": "brute.js", | |
"scripts": { | |
"start": "node brute.js" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment