« first day (3313 days earlier)      last day (1618 days later) » 
02:00 - 18:0018:00 - 00:00

2:10 AM
evening, so, im trying to figure out how to get something from a writestream
a request is made from a client to a server
then i have a router module inside the server than handles this request (a get request)
the router returns this
return {
    body: JSON.stringify(talks),
    headers: {"Content-Type": "application/json",
              "ETag": `"${this.version}"`}
  };
and then the server picks the promise and does this
.then(({body,
                  status = 200,
                  headers = defaultHeaders}) => {
          response.writeHead(status, headers);
          response.end(body);
        });
now, this response is taken by the client module
and i want to make an alert to show on the browser the response
im taking that response and doing this
alert(response.body);
and when the browser shows the alert, an object is returned
i don't know why isn't returning the string contained in the body of the response
what am i doing wrong?
 
2:36 AM
@JDCH Can you create a gist of the entire router? Are you using express?
 
@JBis no, im doing everything from scratch to learn the most i can about nodejs
i'll give you the router model and the server
this is the server
var {createServer} = require("http");
var Router = require("./router");
var ecstatic = require("ecstatic");
const {readFileSync} = require("fs");

var router = new Router();
var defaultHeaders = {"Content-Type": "text/plain"};

var SkillShareServer = class SkillShareServer {
  constructor(talks) {
    this.talks = talks;
    this.version = 0;
    this.waiting = [];
    let fileServer = ecstatic({root: "./public"});
    this.server = createServer((request, response) => {
      let resolved = router.resolve(this, request);
this is the router
var {parse} = require("url");

module.exports = class Router {
  constructor() {
    this.routes = [];
  }
  add(method, url, handler) {
    this.routes.push({method, url, handler});
  }
  resolve(context, request) {
    let path = parse(request.url).pathname;
    for (let {method, url, handler} of this.routes) {
      let match = url.exec(path);
      if (!match || request.method != method) continue;
      let urlParts = match.slice(1).map(decodeURIComponent);
      return handler(context, ...urlParts, request);
 
first off, why this?
var SkillShareServer = class SkillShareServer {
> String(error)
Do error.toString()
 
@JBis i did the binding because i made some methods outside of the inner code
so that i can see a bit more clearly the code
per example:
SkillShareServer.prototype.talkResponse = function() {
  let talks = [];
  for (let title of Object.keys(this.talks)) {
    talks.push(this.talks[title]);
  }
  return {
    body: JSON.stringify(talks),
    headers: {"Content-Type": "application/json",
              "ETag": `"${this.version}"`}
  };
};
this is actually the method that sends the whole json in this.talks
well, it's the one the router method uses to get them and send them to the client
it's used here
router.add("GET", /^\/talks$/, async (server, request) => {
  let tag = /"(.*)"/.exec(request.headers["if-none-match"]);
  let wait = /\bwait=(\d+)/.exec(request.headers["prefer"]);
  if (!tag || tag[1] != server.version) {
    return server.talkResponse();
  } else if (!wait) {
    return {status: 304};
  } else {
    return server.waitForChanges(Number(wait[1]));
  }
});
 
2:52 AM
@JDCH When you define the class the variable is created
||> class Tester{} console.log(typeof Tester)
 
@JBis undefined Logged: "function"
 
Is there any other way to cache and serve a page from cache, like the service worker do? I don't want to use service worker because it have some problems about out of date content from cache, and i don't want to display a button saying the user to refresh the page to get the new content
 
||> var Tester = class Tester{}; console.log(Tester)
 
@JBis undefined Logged: ``
 
Try removing that part @JDCH
@boss what is your question exactly?
 
2:54 AM
@JBis this whole thing is from this book in case you want to see the whole code eloquentjavascript.net/21_skillsharing.html
i also looked at that part of the code but didn't try to modify it cause the author of the code had it that way
and well, he know's move about nodejs than i do
but will modify it
 
@JDCH The author doesn't do the var thing
 
in the browser version he doesn't but in the files he tells you to donwload it does
 
@boss In what context are you talking about? How are you serving a page? Serving a page is done through a server but service workers don't exist on node so what context.
 
@JBis do you know what is a service worker, right? In the service worker i can cache everything. Do you if there's another way to cache and serve a page (example: /index.php) from the cache? I did not find nothing about it on google
 
@JDCH Well i don't see a reason to do that. Maybe there is one but i don't see it.
Yes, i know what a service worker is but i don't understand your question.
 
2:57 AM
i'm serving the page from server
 
Node server?
 
php server
 
So why are you in the JavaScript chat if you are trying to caching stuff with a php server?
 
@JBis the server seems to be running well when i removed the binding
i think it was put there because the author made that same project pre es6
 
well even if i have a php server, i can cache the page with a service worker, which is in javascript, anyways i did not thought that someone would even know something about, as i said, i did not found it on google
 
3:01 AM
@JDCH great!
 
anyways, i evaluated the path the request takes from the client, to the server and to the client again and i coulnd't figure out why i can't get the response to show its body in the alert by doing response.body
 
@boss Again what context are you talking about? Are you making an AJAX request to the php server or soemthing?
@JDCH whats your client side code look like?
 
well, basically the client sees an html page with forms, the forms emit "actions" that are handled by a piece of code that sends the requests to the server
i'll show you some code
this is how the html file, very simple:
<!doctype html>
<meta charset="utf-8">
<title>Skill Sharing</title>
<link rel="stylesheet" href="skillsharing.css">

<h1>Skill Sharing</h1>

<script src="skillsharing_client.js"></script>
the skillsharing_client is run like this:
function runApp() {
  let user = localStorage.getItem("userName") || "Anon";
  let state, app;
  function dispatch(action) {
    state = handleAction(state, action);
    app.syncState(state);
  }

  pollTalks(talks => {
    if (!app) {
      state = {user, talks};
      app = new SkillShareApp(state, dispatch);
      document.body.appendChild(app.dom);
    } else {
      dispatch({type: "setTalks", talks});
    }
  }).catch(reportError);
}

runApp();
pollTalks is in charge of doing the long polling requests, it takes a handler function which takes the talks that the server has
which then are rendered and shown to the client by synchronizing the state in the dispatch funtion after the action the client sent is handled
this is pooltalks and it has the alert part that doesn't return me the body of the response stream
async function pollTalks(update) {
  let tag = undefined;
  for (;;) {
    let response;
    try {
      response = await fetchOK("/talks", {
        headers: tag && {"If-None-Match": tag,
                         "Prefer": "wait=90"}
      });
    } catch (e) {
      console.log("Request failed: " + e);
      await new Promise(resolve => setTimeout(resolve, 500));
      continue;
    }
    if (response.status == 304) continue;
    tag = response.headers.get("ETag");
    await alert(response.body);
the response variable is set like this when it tries to send the request
return {
    body: JSON.stringify(talks),
    headers: {"Content-Type": "application/json",
              "ETag": `"${this.version}"`}
  };
no, wait, that's what the router return to the server
the server takes that from the router
and does this:
  .then(({body,
              status = 200,
              headers = defaultHeaders}) => {
      response.writeHead(status, headers);
      response.end(body);
    });
that's the response
so, in the polltalks function, im taking that response and running this to check the body of the response
await alert(response.body);
the alert is shown to the client
but only an object is shown
when the response.body is a string
or at least that's what i think it is
i don't know if what i sent is just too much, im just a beginner really
maybe i should just sleep a bit and read the code again when im well rested
i've been trying to understand the whole thing the past 4-5 hours
 
 
3 hours later…
6:22 AM
26 messages moved to Trash
 
Hello All,
I am Parth Raval from India.
I need help, I am implementing Remember Me functionality in the browser for one application.
How can I achieve that?
I am using Angular 5.
Please help me with the solution or provide me some links so I can read that.
 
@JennaSloan I have already search on google then i have asked here. :-)
 
6:39 AM
Just use cookies.
 
Actually, I need to implement this functionality without using cookies & localstorage.
 
.. Why?
 
because any User can decrypt the user credentials.
 
Come to the dark side, we have cookies
 
497
Q: What is the best way to implement "remember me" for a website?

Eddie DeyoI want my website to have a checkbox that users can click so that they will not have to log in each time they visit my website. I know I will need to store a cookie on their computer to implement this, but what should be contained in that cookie? Also, are there common mistakes to watch out fo...

You're not gonna store the password in a cookie...
That'd be silly
 
6:43 AM
You shouldn't store passwords anywhere
 
@Cerbrus I was looking for this type of answer.
Actually I have asked the question on meta community,
https://security.stackexchange.com/questions/219062/how-to-store-user-credentials-in-browser-securely
 
@ParthRaval What about indexedDB?
IndexedDB is like a database, but it's indexed.
 
@JennaSloan Bro, We can not store any credentials in the browser(cookies, sessionStorage, localStorage, Browser database) because any user can see the stored password. If we will encrypt the password and store in the browser then this will be vulnerable or any user can decrypt the stored password.
So there is no way to store user credentials in the browser.
am i right @Cerbrus?
 
So don't store the password
Also, don't "bro" me.
 
@JennaSloan Okay
Sorry & Thank you for the help :-)
 
7:07 AM
@santimirandarp Why is your profile picture of a topless person?
 
We discussed this with him a few days ago
 
nvm, I don't want to know
 
He just feels more confident that way
 
My profile picture is of a sideways chalk drawing not drawn by me
 
7:32 AM
Mine is a mouse on top of a cat
because it amused me at the time
 
user7437554
@JennaSloan why do you care?
 
@santimirandarp Why not?
 
user7437554
because there is nothing strange on it...
 
user7437554
once I took a picture of me after waking up, didn't know what prof pic to choose and choose that one...
 
user7437554
i dont like when questions hide a prejudice, but you seem just curious, so..etc @JennaSloan
 
7:55 AM
@santimirandarp I don't like when people presume malintent
 
Whoa, take it easy, guys....
Jenna just asked a question, @santimirandarp.
 
JavaScript room: weird as always.
 
smh'ing my head
 
@Ikari shaking my head'ing my head
Wut xD
 
yeah that's exactly what I meant
:P
 
8:05 AM
@JennaSloan and somehow against all odds, it just got weirder
 
user7437554
8:31 AM
I see...sorry *
 
8:43 AM
Hi. Anyone here worked with wechat ? :)
 
can't say that I have, @MikaelKen
 
I have google documentation with me, just want to understand where they are doing it
 
this isn't a google thing. It's a browser thing
unless steps are made to the contrary, hitting enter will find the first submit and activate it
 
@Neil: Thank you very much for the link, I am reading it.
 
of course they favor letting this behavior happen
but you should be able to just catch the enter key and preventDefault
 
8:58 AM
Yes, I know about this PreventDefault thing, but I did not find anything in google's example for autocomplete, their 'enter' key doesn't create problem, https://jsfiddle.net/api/post/library/pure/
But, with your link, I guess, I would learn about this in detail
if (!place.geometry) {
      // User entered the name of a Place that was not suggested and
      // pressed the Enter key, or the Place Details request failed.
      window.alert("No details available for input: '" + place.name + "'");
      return;
    }
This is how, I think, they prevent enter from submitting the form.
 
or maybe this simply gets called when the form is submitted
 
That way one does need to worry about the 'pac-container' , should it gets changed in the future. But, it's not working as far as I am concerned
You may be right, I should check it once by making changes in js fiddle
 
In node.js, are all true globals inside the 'global' object ?
 
@user123456789 it's global for the module you're in
you have to export it for it to be used elsewhere
 
I mean that we can use "global.console.log('a') "
"console.log(global)" doesn't show any 'console' property
 
9:12 AM
hmm, I think of "global" as more of a namespace
what did you want to do that requires you to use global like an object?
 
read somewhere that "all true globals are the member of the global variable".
 
so you were just curious?
 
yeah
i mean i am learning node.
just a beginner
 
console is a native object though
I don't know if you would technically consider it part of the global
As I see it, global is reserved for say, an address for the local server you want to create which could be used in several places
constant values which may be useful to make available across many modules (though generally, it is better to pass the information if used only in one place)
 
Can't relate between global and top-level scope, like how they work together
 
 
1 hour later…
10:43 AM
hey, is there a way to download an audio file from the server using fetch api??
 
Yeah, looks like
if you can download an image you could almost certainly use it for audio
 
@Neil checking it but when i use res.size (a blob) it is showing 0.
 
> Note: If the Response has a Response.type of "opaque", the resulting Blob will have a Blob.size of 0 and a Blob.type of empty string "", which renders it useless for methods like URL.createObjectURL.
it could be that the data is there, it just shows size 0
 
@Neil i will try once more
 
11:08 AM
QQ.
Is partial repaint of a page possible?
 
@CaptainHere well if you mean repaint as in switching out entire parts of a page, yes
 
@Neil Oh. Thanks. I have a front-end interview in a hour. Any advice?
 
@CaptainHere is it a technical interview?
 
Yeah
 
hmm, then review your data structures
they make for popular questions
what is the difference between a linked list or an array-based list for instance?
would it be a smart idea to use a array-based list as a LRU cache? Why or why not?
etc.
You have a thousand items which are all mostly sorted. Which sorting algorithm do you use to sort it and why?
 
11:20 AM
Great Questions.
I Gotta brush up them Data Structures.
 
also, if you legitimately don't have a clue on a given question, don't be afraid to say you don't know :)
they smell bullshitters a mile a way. They appreciate honesty
answer whatever you can that you know, and for the rest you admit you don't know
 
For javascript in browsers, when we create a variable say 'a'.
a===window.a is true
is there something similar in node ?
 
why would you need something like that?
you're encouraged to make everything modular for a reason
 
I dont need it just curious. When we do 'a=5', we see as a property in 'global' variable. I thought something similar to happen with 'var b = 10' (local to the module)
 
11:36 AM
even if there were a way to do global.b, what would be the purpose of this?
it's easier to type b than it is to type global.b
if you wanted to organize your variables, I suppose you could create a local object holding all your values
so var environ = {a: 5, b: 10};
 
i thought there would be a module.b
Do you know any good book/s for node ?
 
no, sorry. I didn't really learn node.js through books
there are the exports of course
but that's for what you want visible when you include a module
 
 
4 hours later…
3:43 PM
Hi, just after posting I remembered of the chat here, could someone tak a look at stackoverflow.com/questions/58804084/… I think it's not hard, but I'm quite starting Promise and all this stuff and I don't find the way ;)
I try to get response detail + response text (from server) in case of HTTP error during a fetch
 
4:09 PM
This is actually a CSS question rather than a JS question. If I put transform:scale() on a table row, how can I get the table to adjust to the new size of the row?
 
4:22 PM
@Hypersapien You cannot
transformed elements can never affect layout.
 
shit
 
(That's why they are so performant to animate)
 
Not sure what you mean by that
@MadaraUchiha performant?
 
user7437719
4:39 PM
@azro You have some feedback concerning your question!!
 
so, anyone knows about writtable streams and readable streams in nodejs?
 
@Hypersapien Take a bunch of resources to calculate/render.
@JDCH Sure
 
@BenFortune so, this is my issue, i got a server and a client
 
user7437719
Okay
 
@BenFortune the client sends a get request and the server sends a response like this:
wait, first, the router gives the server this:
return {
    body: JSON.stringify(talks),
    headers: {"Content-Type": "application/json",
              "ETag": `"${this.version}"`}
  };
and the server gets that and responds to the client like this:
}).then(({body,
status = 200,
headers = defaultHeaders}) => {
response.writeHead(status, headers);
response.end(body);
});
 
4:45 PM
@JDCH Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
 
god i thought i formatted it
}).then(({body,
                  status = 200,
                  headers = defaultHeaders}) => {
          response.writeHead(status, headers);
          response.end(body);
        });
so, basically, the server sends this to the client
 
user7437719
@JamesBot stop being a control freak.
 
response.writeHead(200, {"Content-Type": "application/json"});
response.end(//a stringified JSON)
the client gets that and i want an alert to show the body of the response
i tried like this:
alert(response.body);
but it doesn't show the body of the response that should be a string
do you know what am i doing wrong?
what is shows me is an array with objets like this
[object Object]
 
response.end(body); is body a string?
 
yes, because it's gotten from body: JSON.stringify(talks);
that's what the router gives to the server
when i write that on a file, it gives me a string with the talks in it
but when i try to get it with alert, it just gives me an object
 
4:54 PM
Have you tried to console.log it ?
 
i tried it but i've never used it in the browser, the client sends the request on the browser
i tried once but i don't know if im doing it well
i put the body inside a console.log
and pressed f12 to see the browser's console
and nothing is shown
 
@TomMinor Where ? I just answereed my own question on SO, I do not see any comment anywhere :p but no matter now I found
 
@BenFortune basically, something like this is what the server sends
{
    body: JSON.stringify(talks),
    headers: {"Content-Type": "application/json",
              "ETag": `"${this.version}"`}
}.then(({body,
    status = 200,
    headers = defaultHeaders}) => {
    response.writeHead(status, headers);
    response.end(body);
});
body's a string because it's a stringified json
i think the client gets a json file because the content type of the header of the response is "Content-Type": "application/json"
but when i stringify the response the client gets like this:
alert(JSON.stringify(response.body));
i also get an object
 
i mean
what do you mean by "i also get an object"
 
5:02 PM
when i do this:
alert(typeof JSON.stringify(response.body));
the alert shows "object"
 
and what does response.body show you?
 
[object Object]
 
use console
 
@JDCH talks is an object I presume?
 
?
what is talks
 
5:04 PM
body: JSON.stringify(talks),
Sorry Kevin @'ed wrong person
 
yes, a json object that has things like this:
[{"title":"testing","presenter":"Anon","summary":"123","comments":[]}]
the client gets that to render the html
 
What i'm getting at is it's not really possible for response.body to be an object and stringifying that object resulting in "object" unless there's some toString foo going on.
something in this explanation isn't matching up
 
Are you sure your fetch is being done properly?
A basic fetch looks like this:
 
when i write that body response on a file in the server
on a .txt file
that's what i get, a stringified version of the json
[{"title":"testing","presenter":"Anon","summary":"123","comments":[]}]
let me just test everything i've tried again
 
fetch('http://example.com/something').then(r => r.text()).then(body => console.log(body);
 
5:07 PM
maybe i did something wrong without realizing
 
the body will be a string there
you can also do
fetch('http://example.com/something.json').then(r => r.json()).then(body => console.log(JSON.stringify(body));
Body will be an object there
you shouldn't be using the body in the first .then function
 
yeah man i think im doing the fetch requests well
this is the function that does the long polling requests
async function pollTalks(update) {
  let tag = undefined;
  for (;;) {
    let response;
    try {
      response = await fetchOK("/talks", {
        headers: tag && {"If-None-Match": tag,
                         "Prefer": "wait=90"}
      });
    } catch (e) {
      console.log("Request failed: " + e);
      await new Promise(resolve => setTimeout(resolve, 500));
      continue;
    }
    if (response.status == 304) continue;
    tag = response.headers.get("ETag");
    await alert(typeof JSON.stringify(response.body));
it's client sided
and it has the piece of code that doesn't' return what i expect to
 
@JDCH why are you using try/catch with promises
 
this await alert(typeof JSON.stringify(response.body));
 
and why are you awaiting a non async function
alert is sync
and what is fetchOK
 
5:13 PM
Why alert and not console.log
 
to force the function to wait a moment when the request fails that's why there's a promise with setTimeout inside the async function
this is fetchOK
function fetchOK(url, options) {
  return fetch(url, options).then(response => {
    alert(typeof response);
    if (response.status < 400) return response;
    else throw new Error(response.statusText);
  });
}
in case there's a network error and the error, that's why try catch is done there
@KevinB i did alert because i don't know where console.log is shown in the browser, with alert i can just see it on the front, i tried pressing f12 and going to the console but nothing is shown there
 
using alert with async actions is risky business
i suggest figuring out the console
 
is it? didn't know that, im a beginner
 
it pauses the javascript thread, however it does not pause what is happening in the background
so you'll get results that may not match what happens when you remove the alert
 
@JDCH this is bad imo
its confusing and unnecessary
and kevin's right about the alert, don't use it to debug
 
5:19 PM
alerts can hide race conditions
 
If I set a <tr>'s opacity to 1, why do the cell borders disappear?
 
maybe the cell obscures them
 
make it transition from 0 to 1, should make clear what is happening
 
i removed all alerts and it keeps showing me an alert
do i have to restart the browser or something?
 
clear cache maybe, but if you're having that problem who knows what other problems you might have
 
5:24 PM
This is in jsfiddle
 
It matters not
 
@Hypersapien can you post the fiddle?
 
you should have the dev tools open and the "disable cache" option checked
 
@JDCH If you have devtools open, you can right click the Refresh button and you have an option to Empty Cache And Reload
or disable cache, yeah
 
5:26 PM
oh, wow, i ran it on chrome and it now shows me something different
in the termina
console i mean
 
What the hell? I took the opacity out and the borders are still gone
 
dare i ask what browser you were using before?
 
something like this imgur.com/7rByjtl
let me keep trying diferent things with console now
 
@Hypersapien whats the expected result?
 
I'm trying to figure out how to collapse table rows smoothly and have them completely disappear.
 
5:29 PM
@forresthopkinsa where do i do that in chrome? right click inside or outside of devtools?
 
Figured it out. I had a stray semicolon outside the CSS tag
Question: If I'm doing a CSS transition, can I set a transition on a style that normally can't be transitioned, like display, have the duration be 0 but put a delay on it?
 
@Hypersapien i don't think so
Transitioning display never works
 
Is there another way to put a delay on changing things like that?
 
hieght
 
@JDCH on the normal page refresh button
not inside devtools, but you can only do it when devtools is open
 
5:41 PM
@forresthopkinsa thanks
 
@Hypersapien i can't figure it out for some reason but when you want to collapse things you usually want to transition the height property with overflow as hidden
 
I can get it to collapse, but it's leaving behind a border which is taking up a pixelwidth of space.
 
so transition the border
 
Actually, no. It's the bottom and top borders of the cells above and below the rows I'm collapsing
 
Hmm, guys, seems like response.body is not a string
it's a readablestream
 
5:56 PM
@JDCH your fetch is wrong
please redo your fetch
don't use try catch
use .catch(err => )
@JDCH and don't use this
 
i'll see what i can do, though, i don't know if i should keep trying to solve that thing, that code is from a book im using to learn some js but people keep telling me that my code is wrong and things like that, when it's the code from someone else that im using to learn
 
02:00 - 18:0018:00 - 00:00

« first day (3313 days earlier)      last day (1618 days later) »