Allah

joined 1 month ago
MODERATOR OF
[–] Allah@lemm.ee 7 points 2 days ago

sir please forgive us

[–] Allah@lemm.ee 1 points 2 days ago* (last edited 2 days ago)

what? i think you mean drill?

 

try using this code do you think it will work?

Below is a minimal example of how you can add a real‐time chat box that only your authenticated users can use. It uses:

  • Node.js + Express for the web server
  • express‐session to track logged-in users
  • Socket.io for real-time messaging

You’ll need to adapt the authentication check to however you store your users (database, JWTs, etc.), but this will give you the core of “only logged‐in folks see/use the chat.”


1. Install dependencies

npm init -y
npm install express express-session socket.io

2. server.js

const express = require('express');
const http    = require('http');
const session = require('express-session');
const SocketIO = require('socket.io');

const app = express();
const server = http.createServer(app);
const io = new SocketIO(server);

// 1) Session middleware
const sessionMiddleware = session({
  secret: 'YOUR_SESSION_SECRET',
  resave: false,
  saveUninitialized: false,
  // store: you can add a store like connect-mongo here
});
app.use(sessionMiddleware);

// 2) Make session available in socket.handshake
io.use((socket, next) => {
  sessionMiddleware(socket.request, socket.request.res || {}, next);
});

// Serve static files (our chat page + JS)
app.use(express.static('public'));

// 3) A simple “login” route for demo purposes.
//    In real life you’d check a DB, hash passwords, etc.
app.get('/login', (req, res) => {
  // e.g. ?user=alice
  const username = req.query.user;
  if (!username) return res.sendStatus(400);
  req.session.user = { name: username };
  res.redirect('/chat.html');
});

// 4) Protect chat page
app.get('/chat.html', (req, res, next) => {
  if (!req.session.user) return res.redirect('/login.html');
  next();
});

// 5) Handle socket connections
io.on('connection', socket => {
  const req = socket.request;
  if (!req.session.user) {
    // kick out any un‐authenticated socket
    return socket.disconnect(true);
  }

  const user = req.session.user.name;
  socket.broadcast.emit('message', {
    from: 'SYSTEM',
    text: `${user} has joined the chat`
  });

  socket.on('message', msg => {
    io.emit('message', {
      from: user,
      text: msg
    });
  });

  socket.on('disconnect', () => {
    socket.broadcast.emit('message', {
      from: 'SYSTEM',
      text: `${user} has left the chat`
    });
  });
});

server.listen(3000, () => {
  console.log('Listening on http://localhost:3000/');
});

3. public/chat.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Chat Room</title>
  <style>
    #messages { list-style: none; padding: 0; max-height: 300px; overflow-y: scroll; }
    #messages li { margin: 5px 0; }
    #form { display: flex; }
    #input { flex: 1; }
  </style>
</head>
<body>
  <h1>Chat Room</h1>
  <ul id="messages"></ul>
  <form id="form">
    <input id="input" autocomplete="off" placeholder="Type a message…" /><button>Send</button>
  </form>

  <script src="/socket.io/socket.io.js"></script>
  <script>
    const socket = io();

    const form = document.getElementById('form');
    const input = document.getElementById('input');
    const messages = document.getElementById('messages');

    socket.on('message', msg => {
      const li = document.createElement('li');
      li.textContent = `${msg.from}: ${msg.text}`;
      messages.appendChild(li);
      messages.scrollTop = messages.scrollHeight;
    });

    form.addEventListener('submit', e => {
      e.preventDefault();
      if (input.value.trim()) {
        socket.emit('message', input.value);
        input.value = '';
      }
    });
  </script>
</body>
</html>

4. How It Works

  1. Session setup We use express-session so that when a user “logs in” (e.g. via your existing form/database), we store { user: { name: '…' } } in req.session.

  2. Socket authentication By re-using the same session middleware in Socket.io’s io.use(…), every incoming socket has access to socket.request.session. If there’s no session.user, we immediately disconnect() them.

  3. Real-time chat

    • On connect/disconnect we broadcast a system message.
    • On client‐side, every message the user sends is emitted and broadcast to all.
  4. Protecting the page We guard chat.html in Express so that if you go there directly, you’ll get bounced to /login.html (you’d build a real login page).


Next Steps

  • Integrate with your real user database. Replace the demo /login route with your own logic.
  • Persist chat history if you want to store messages (e.g. in MongoDB or MySQL).
  • Add rooms or private messaging by namespace or room support in Socket.io.
  • Style it and embed it in your existing layout (lemm.ee) CSS.
[–] Allah@lemm.ee 12 points 2 days ago

Annexing is a formal legal process, it's not just creating settlements and occupying. Almost none of the West Bank has been annexed by Israel ...........................

YET

13
submitted 2 days ago* (last edited 2 days ago) by Allah@lemm.ee to c/youshouldknow@lemmy.world
 

Sci-Hub alternative websites for accessing academic papers for free:

Unpaywall (https://unpaywall.org/) Browser extension for Chrome.

Allows legal, free access to research papers directly on journal websites.

Open Access Button (OAB) (https://openaccessbutton.org/)

Copy and paste a paper’s link or DOI into the OAB website.

Provides legal access to the paper on the subsequent page. PaperPanda (https://paperpanda.app/)

Chrome extension similar to Unpaywall. Enables one-click access to millions of research papers. DOAJ (Directory of Open Access Journals) (https://doaj.org/)

Offers free access to millions of scientific papers globally. Focuses on open-access journals. OA.mg (https://oa.mg/)

Search engine designed specifically for academic papers. Provides access to over 250 million papers. Core (https://core.ac.uk/)

World’s largest database of research papers. Contains over 298 million papers available for free. arXiv (https://arxiv.org/)

Specializes in natural sciences and economics. Offers free access to 2.4 million academic papers.

Tip: Remove any spaces in the URLs if there are issues accessing the websites.

[–] Allah@lemm.ee 2 points 2 days ago
 

Consciousness in AI: Some experts, like Profs Lenore and Manuel Blum, believe AI could achieve consciousness soon, possibly through integrating sensory inputs like vision and touch into large language models (LLMs). They’re developing a model called "Brainish" to process such data, viewing conscious AI as the "next stage in humanity’s evolution." Others, like Prof Anil Seth, argue that consciousness may be tied to living systems, not just computation, and that assuming AI can become conscious is overly optimistic.

Scientific Efforts: Researchers at Sussex and elsewhere are breaking down the study of consciousness into smaller components, analyzing brain activity patterns (e.g., electrical signals, blood flow) to understand its mechanisms. This contrasts with the historical search for a single "spark of life."

AI’s Current State: LLMs like those behind ChatGPT and Gemini can hold sophisticated conversations, surprising even their creators. However, most experts, including Prof Murray Shanahan of Google DeepMind, believe current AI is not conscious. The lack of understanding of how LLMs work internally is a concern, prompting urgent research to ensure safety and control.

Alternative Approaches: Companies like Cortical Labs are exploring "cerebral organoids" (mini-brains made of nerve cells) to study consciousness. These biological systems, which can perform tasks like playing the video game Pong, might be a more likely path to consciousness than silicon-based AI.

Risks and Implications: Prof Seth warns of a "moral corrosion" if people attribute consciousness to AI, leading to misplaced trust, emotional attachment, or skewed priorities (e.g., caring for robots over humans). Prof Shanahan notes that AI will increasingly replicate human relationships (e.g., as teachers or romantic partners), raising ethical questions about societal impacts.

Philosophical Context: The article references David Chalmers’ "hard problem" of consciousness—explaining how brain processes give rise to subjective experiences. This remains unsolved, fueling debates about whether AI could ever truly be conscious.

[–] Allah@lemm.ee 4 points 4 days ago (2 children)

know when to be evil? i am assuming you meant to say when do we have the right to defend ourselves?

[–] Allah@lemm.ee 0 points 4 days ago* (last edited 4 days ago)

Source: The Hindu, published August 21, 2024, citing Association for Democratic Reforms (ADR) report. Total Cases: 151 sitting MPs and MLAs in India have declared cases related to crimes against women. Rape Charges: 16 MPs/MLAs are charged with rape under IPC Section 376. Party Breakdown: Bharatiya Janata Party (BJP): 54 MPs/MLAs with cases of crimes against women. Indian National Congress: 23 MPs/MLAs with cases of crimes against women, including 5 charged with rape. Telugu Desam Party: 17 MPs/MLAs with cases of crimes against women. Data Source: Analysis of 4,809 out of 4,863 election affidavits of sitting MPs and MLAs as of August 2024.

view more: next ›