Skip to content

Instantly share code, notes, and snippets.

@TooTallNate
Created March 16, 2012 22:42
Show Gist options
  • Select an option

  • Save TooTallNate/2053342 to your computer and use it in GitHub Desktop.

Select an option

Save TooTallNate/2053342 to your computer and use it in GitHub Desktop.
Running a node.js REPL over `curl`
/**
* Requires node v0.7.7 or greater.
*
* To connect: $ curl -sSNT. localhost:8000
*/
var http = require('http')
, repl = require('repl')
, buf0 = new Buffer([0])
var server = http.createServer(function (req, res) {
res.setHeader('content-type', 'multipart/octet-stream')
res.write('Welcome to the Fun House\r\n')
repl.start({
prompt: 'curl repl> '
, input: req
, output: res
, terminal: false
, useColors: true
, useGlobal: false
})
// log
console.log(req.headers['user-agent'])
// hack to thread stdin and stdout
// simultaneously in curl's single thread
var iv = setInterval(function () {
res.write(buf0)
}, 100)
res.connection.on('end', function () {
clearInterval(iv)
})
})
server.listen(8000)
☮ ~ (master) ⚡ curl -sSNT. localhost:8000
Welcome to the Fun House
curl repl> process.platform
'darwin'
curl repl> process.arch
'x64'
curl repl> process.cwd()
'/Users/nrajlich'
curl repl> path
{ resolve: [Function],
normalize: [Function],
join: [Function],
relative: [Function],
dirname: [Function],
basename: [Function],
extname: [Function],
_makeLong: [Function] }
curl repl> ^C
☮ ~ (master) ⚡
@mdaryen33220-create
Copy link

// ১. গেমের প্রতীকগুলো সেট করা
const symbols = ["🍒", "💎", "7️⃣"];

function playSlotMachine() {
// ২. তিনটি ঘরে র‍্যান্ডম প্রতীক বসানো
const reel1 = symbols[Math.floor(Math.random() * symbols.length)];
const reel2 = symbols[Math.floor(Math.random() * symbols.length)];
const reel3 = symbols[Math.floor(Math.random() * symbols.length)];

console.log(`ফলাফল: ${reel1} | ${reel2} | ${reel3}`);

// ৩. জেতা বা হারার লজিক চেক করা
if (reel1 === reel2 && reel2 === reel3) {
    console.log("অভিনন্দন! আপনি জিতেছেন! 🎉");
} else {
    console.log("আবার চেষ্টা করুন। ❌");
}

}

// গেমটি চালানো
playSlotMachine();

@mdaryen33220-create
Copy link

let userBalance = 100; // শুরুতে ইউজারের ১০০ টাকা আছে
const betAmount = 10; // প্রতি স্পিনের খরচ ১০ টাকা

function playSlotMachine() {
if (userBalance < betAmount) {
console.log("আপনার পর্যাপ্ত ব্যালেন্স নেই! ❌");
return;
}

// বাজি ধরার পর ব্যালেন্স কমানো
userBalance -= betAmount;

const symbols = ["🍒", "💎", "7️⃣"];
const r1 = symbols[Math.floor(Math.random() * symbols.length)];
const r2 = symbols[Math.floor(Math.random() * symbols.length)];
const r3 = symbols[Math.floor(Math.random() * symbols.length)];

console.log(`ফলাফল: ${r1} | ${r2} | ${r3}`);

if (r1 === r2 && r2 === r3) {
    let winPrize = betAmount * 5; // জিতলে ৫ গুণ টাকা
    userBalance += winPrize;
    console.log(`অভিনন্দন! আপনি ${winPrize} টাকা জিতেছেন! 🎉`);
} else {
    console.log("আপনি হেরেছেন।");
}

console.log(`বর্তমান ব্যালেন্স: ${userBalance} টাকা`);

}

// গেমটি একবার চালিয়ে দেখা
playSlotMachine();

@mdaryen33220-create
Copy link

`// ১. গেমের প্রতীকগুলো সেট করা
const symbols = ["🍒", "💎", "7️⃣"];

function playSlotMachine() {
// ২. তিনটি ঘরে র‍্যান্ডম প্রতীক বসানো
const reel1 = symbols[Math.floor(Math.random() * symbols.length)];
const reel2 = symbols[Math.floor(Math.random() * symbols.length)];
const reel3 = symbols[Math.floor(Math.random() * symbols.length)];

console.log(`ফলাফল: ${reel1} | ${reel2} | ${reel3}`);

// ৩. জেতা বা হারার লজিক চেক করা
if (reel1 === reel2 && reel2 === reel3) {
    console.log("অভিনন্দন! আপনি জিতেছেন! 🎉");
} else {
    console.log("আবার চেষ্টা করুন। ❌");
}

}

// গেমটি চালানো
playSlotMachine();`

@mdaryen33220-create
Copy link

  1. 6568

@mdaryen33220-create
Copy link

let userBalance = 100; // শুরুতে ইউজারের ১০০ টাকা আছে
const betAmount = 10; // প্রতি স্পিনের খরচ ১০ টাকা

function playSlotMachine() {
if (userBalance < betAmount) {
console.log("আপনার পর্যাপ্ত ব্যালেন্স নেই! ❌");
return;
}

// বাজি ধরার পর ব্যালেন্স কমানো
userBalance -= betAmount;

const symbols = ["🍒", "💎", "7️⃣"];
const r1 = symbols[Math.floor(Math.random() * symbols.length)];
const r2 = symbols[Math.floor(Math.random() * symbols.length)];
const r3 = symbols[Math.floor(Math.random() * symbols.length)];

console.log(`ফলাফল: ${r1} | ${r2} | ${r3}`);

if (r1 === r2 && r2 === r3) {
    let winPrize = betAmount * 5; // জিতলে ৫ গুণ টাকা
    userBalance += winPrize;
    console.log(`অভিনন্দন! আপনি ${winPrize} টাকা জিতেছেন! 🎉`);
} else {
    console.log("আপনি হেরেছেন।");
}

console.log(`বর্তমান ব্যালেন্স: ${userBalance} টাকা`);

}

// গেমটি একবার চালিয়ে দেখা
playSlotMachine();

@mdaryen33220-create
Copy link

Uploading 1000025678.jpg…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment