« first day (3827 days earlier)      last day (1346 days later) » 
01:00 - 15:0015:00 - 23:00

01:59
 
5 hours later…
07:25
||> const r = f => function r(...args){
  f(...args);
  return r;
}
const addKeyValues = obj => Object.assign(
  r((k, v) => obj[k] = v),
  {result: obj}
);

const input = ["apple", "banana", "cherry"];

const { result } = input.reduce(
  (acc, item, i) => acc(i+1, item),
  addKeyValues({})
);

console.log(result);
@VLAZ undefined Logged: {"1":"apple","2":"banana","3":"cherry"} Took: 1ms
In case you hate your co-workers or yourself, you can write code like this.
07:37
tsss
when doing codereviewing of others code, it has happened that I have given it a -2 (meaning "I do not want to merge it") because the code could be simpler.
so, 👎 @VLAZ 😁
Hey, I even gave you the good version, and you give me -2 T_T
And yeah, I was just messing around.
Some question asked for "I have this, I want to transform it to that. Give me a oneliner".
I was very tempted to give a very confusing one as an answer
But decided against it. So I cleaned it up and you see it above
I do not recommend that code, though.
> Give me a oneliner
🙄
you can say that their one-liner is in the answer you've given
||> ["apple", "banana", "cherry"].reduce( (o, el, i) => o[i+1] = el, {})
@KarelG "cherry" Logged: `` Took: 1ms
(o[i+1] = el, o)
forgot to return it ... yeah
07:47
And yeah, it's trivial to do with basically any loop or .reduce. No, there wasn't any attempt at either in the question.
but I would do {...; return o;} instead
So many more characters!
||> const input = ["apple", "banana", "cherry"];

const { result } = input.reduce( (acc, item, i) => acc(i+1, item), Object.assign(function r(k, v){ r.result[k] = v; return r; }, {result: {}} ) );

console.log(result);
@VLAZ undefined Logged: {"1":"apple","2":"banana","3":"cherry"} Took: 0ms
Also a oneliner :D
Perfect answer for an imperfect question.
More realistically this seems much simpler:
||> const input = ["apple", "banana", "cherry"];
const result = {};
input.forEach((x, i) => result[i+1]= x);
console.log(result);
@VLAZ undefined Logged: {"1":"apple","2":"banana","3":"cherry"} Took: 1ms
07:52
TIL jbot accepts multilines
@VLAZ " forEach ain't fancy " 😀
@KarelG Heh, I've known since last week. I mostly stumbled upon it by randomly trying something.
08:49
hi everyone
@TeoEm Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
1 hour later…
10:06
@ThiefMaster Yeah, that makes a lot of sense. Instead of calling it immediately I should pass the load function to setInterval so that setInterval can call the load function periodically.
@starboy it appears you're passing arguments to it
so either have another function that calls load with said argument and use it or use anon function
@ThiefMaster yes that did it. setInterval(() => {load(...)}, 5000);
you can omit the {} there since the return value is not significant here (ie the fact that the arrow function returns the result of load isn't a problem)
you have opted for the 2nd option :D\
but the curly braces ain't required here
it is only usable if you have multi-line statements
or when returning something specific
@ThiefMaster var declares a global variable. Since var is at the top level in <script>...</script> I would think that var is best for a variable. Why not?
10:10
no it doesn't. please read about var/const/let :)
you can pretty much always use const or let instad of var
also avoid creating global variables :)
always first use const.
if you need to modify that, step to let
if you put code in script tags, wrap everything in an IIFE to avoid polluting the global scope
and if you need to create globals, be explicit and assign window.something = ...
var is really exceptional case, if you need that, then you have a design smell
@ThiefMaster load(...) the table is not being updated every 5 seconds though. This could be because even though I instructed setInterval to execute load(...) every 5 seconds, the fetch function makes a GET request, the server takes some time to send a response back to the client (i.e. fetch). Is this why the table is not updating every 5 seconds?
@KarelG I used an anonymous function instead of passing a function that calls load to setInterval.
@ThiefMaster Thanks. I know I can use an expression lambda instead of a statement lambda. I'm not sure how JS works and there's no compiler.
@starboy uhm .., for that I advise to take a different approach
your timer is not dependent of the network atm.
10:21
@KarelG Yup, {} is for grouping statements. Since there's just one expression (i.e. load()) I could have omitted {}. You guys sound like the compiler that JavaScript is missing :D
you have to restructure that you have set your interval each 2 minutes (5 seconds is too frequent IMHO - use a display "last updated") that does this job;
1. fetch information you need
2. on response -> update table
so setInterval(getAndUpdateTable, 2 * 60 * 1000); with
function getAndUpdateTable() {
  fetch(...).then(...process...).then(...updatetable...);
}
@ThiefMaster var does not declare a global variable? Can you clarify that because that's new to me. Something like intervalID = ...` would still work but here intervalID is an undeclared global variable`.
@ThiefMaster const declares a named constant. let declares a block scoped variable, i.e. a variable that is limited to a block of code (i.e. {}). They are not interchangeable with var. Am I misunderstanding anything?
inside a script tag you're always in the global scope, so AFAIK using let or const there will simply act in that scope
@ThiefMaster Is the reason you avoid global variables because it will be available in other `<scrip></script> elements in an HTML document?
damn, you like to ping others :P
10:28
first of all it's polluting the global scope, so avoid creating globals unless you need them to be globals - and in that case being explicit about it makes it more maintainable, since later someone may not know whether something is meant to be global or not..
(i think he's just using the reply function ;x)
he does
So maybe var could override a variable with the same name in another `<script>/<script>
yes
and has led to problems. const prevents that
what I do - especially with legacy code - is to put them in a small "cache"
you see usually in old code this
var var1 =...;
var otherVar = ...;
var anotherAgain = ...;
var lorem = ...;
var foobar = ...;
so when you want to use var lorem somewhere else, it overrides that one and leads to a different behavior
I try to check if it is really required to have it as global variable. if it is (or too much work to refactor) I just turn that into
const namedCache = Object.freeze({
  var1 :...,
  otherVar : ...,
  anotherAgain : ...,
  lorem : ...,
  foobar : ...,
});
some legacy scripts are a nightmare man.
@KarelG That's very nice. It wasn't easy for me to get functionality to work, whereby the table is updated periodically. How is this approach better than the one @ThiefMaster helped me to get working?
@ThiefMaster I see, thanks. Shouldn't the use of let and const be avoided in the global scope since that becomes their scope.
> inside a script tag you're always in the global scope
^ do you mean anywhere in a <script> element, or just at the top level?
> your timer is not dependent of the network result atm.
10:44
Before I used setInterval(...) I used:
while (true)
    {
        setTimeout(load(TableData', document.getElementById('theTable')), 3000);
    }
And that crashed my computer. Any idea why that code crashed my computer?
read that as
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
invoke timeout on -> call load function -> get result -> for 3 seconds
ok some copy pastes failed here
you're asking the browser to ignore everything because it's doing the same operation over and over without stopping
eventually the javascript memory (for call load function) gets ran out => no memory => crash
invoke timeout on -> call load function -> get result -> for 3 seconds so the arrow indicates going from one step to another?
I used setTimeout in that while true loop because wanted to call the load(...) function wait 3 seconds, and then call the load function again, wait another 3 seconds. Repeating these instructions as long as the webpage is loaded. So that's not what the code did?
the code does not wait for 3 seconds there.
setTimeout(fx, xTime) says "I want fx to be executed after xTime"
javascript is an event driven scripting language
so what setTimeout does is to create an "object" and place it on the event queue
so
while (true) {
  setTimeout(fx, xTime);
}
@VLAZ yes that is correct, sorry
means "put this object with fx that should be executed after xTime on event queue"
and do that forever
you keep creating objects and place that in the queue.
^ all without letting the queue move on
A busy wait (a loop) is quite literally holding up the queue.
The DOM shows that the table element is being replaced every 1 second (it flashes purple every second), and I have a counter variable in the load function that console.log(...) shows has counted 300 times. So why does it take the table about <strike>10 seconds</strike> 1 minute 20 seconds to update?
11:06
https://image-data-encoder.mistersircode.repl.co/

What it does is encode your text in a set algorithm, like Base64 for example, and parses the ASCII into pixel data using a neat algorithm that parses the Character Codes into Color Data

And that color data is drawn as pixels.
its totally useless
but its fun
well I guess it isnt TOTALLY useless
but still, no real logical point to it, its simply an experiment
it stores the encoder settings, version and config in a single line of pixels near the bottom
this will allow it to be decoded back into text later on
Okay so I did some testing with the browser, and the API endpoint fetch is making a request to also takes over a minute to update when I use the browser to call it. So the JavaScript code is not the bottleneck, neither is the server side program, it's just that the API endpoint does not update anywhere as quickly as I expected.
@starboy you can instruct your fetch call to not cache it. But as said earlier, reconsider your intervals. 2 seconds is too frequent if the data is "big" (subjective)
hi Rob. Something got flagged?
@KarelG Would stopping fetch from catching the response improve performance, and how?
> 2 seconds is too frequent if the data is "big" (subjective)
I dropped it to 1 second. The data is just a small JSON response
11:43
To you json experts... if your json describes objects that you are to draw on the screen would you do it like this:
{
    "foo": [{
        "bar": {
            "prop1":"value1"
        }
    }, {
        "bar": {
            "prop1":"value2"
        }
    }]
}
or
{
    "type": "foo",
    "content": [{
        "type": "bar",
        "prop1": "value1"
    },{
        "type": "bar",
        "prop1": "value2"
    }]
}
||> ((255 << 16) | (255 << 8) | 0).toString(16)
@MisterSirCode "ffff00" Logged: `` Took: 0ms
@Markus not meaningful examples
@KarelG how come?
11:51
||> "#"+((255 < 256 ? 255 : 255 << 16) | (255 < 256 ? 255 : 255 << 8) | 0 < 256 ? 0 : 255 ).toString(16)
@MisterSirCode "#0" Logged: `` Took: 0ms
>:(
damn you
oh wait
Im dumb
"#"+ big brain
well now I have a one line RGB to HEX. Nice
@Markus I am unable to figure out the context. Your JSON structure is really dependent of your data model within a particular context. I only have these information: "draw on screen" and then prop1 + value1, for "bar" which is member of "foo" or as in another example, option "type" is "foo" where "content" is with "type" "bar" and "prop1":"value1"
currently, the second one is more meaningful
@KarelG ok, so in the future there will be more props, and the props might also include more objects with props. It will get rather nested
12:10
|| shrug
¯\_(ツ)_/¯
just use whatever is most convenient.
(ツ)_/¯
window.location !== window.parent.location
Convenience...
How did I never know of this before...
12:17
@VLAZ That looks like Max doing his wave in "How the Grinch Stole Christmas"
Not exactly what I was aiming for but also I didn't really have any particular thing in mind.
I thought it'd be funny to re-use the shrug.
Figured, just thought the similarity was pretty funny
¯\_(ツ)
@MisterSirCode if (window.location !== window.parent.location) return "I moved out of my parent's basement"
(ツ)
Just checked and "ツ" is a Japanese character. Now I wonder if this looks odd to people who know Japanese.
@VLAZ Thats golden lol.
In reality, thats a neat little snippet that detects if youre in an iframe
12:24
I figured.
if so, you can place text / run code to either disable the site, warn the user, or something other
I use it in WYSIWYG type websites to urge users to go to full-screen mode
Or be super meta and show a picture of a basement without any windows.
Lol, I need to add that to my website...
a neat little trinket
Though I could just do it in PHP
but thats boring
PHP iframe redirects are much better solutions, but again, PHP is boring
Had an assignment in Uni to do with Kevin Bacon. I named that class bacon and then passed it into new FryingPan(eggs, bacon). The eggs was a helper class.
12:27
I was running on very little sleep at the time.
I really wanna do fun meta code like that, but I just get too caught up in making stuff functional
@MisterSirCode use window.frameElement ...
that I forget to have fun with it
I just hope the lecturer found it as funny as I did.
@KarelG does that detect if the current site is within an iframe?
If so, it doesnt check if its on a different URL or not
12:28
yes? as by standard?
meaning you wouldnt be able to use iframes in your own website if you needed to
|| mdn window.frameElement
Does it check if its on a different page aswell?
yeah, null if it's on different origin tmk
RTFM
12:29
hmm
might be useful then, alright
@VLAZ I find that adult programmers have less humor then most people, but who knows
Im sure he/she got a kick out of it
I got an OK mark on the assignment. I just wonder to this day whether I had points deducted.
hey does anyone know if Im able to create an SSL Certificate for an IP Address?
my website is blocked, so I have to view it through it's external IP instead, https://35.226.5.214/art
Is it possible to SSL Authenticate the IP address like a normal domain?
TBH, the code wasn't great.
I know this isnt really JS stuff, but just curious
@VLAZ Is it ever?
Even seniors and experts make bad code sometimes
12:33
yeah, Ill just try it and find out
damnit Ive only got 14 days left of free trial, and for some reason my VPS is costing 4 bucks a month...

Even though its got an F1 Micro, its got barely any GB of space, and Ive followed all of the limits
no idea why its still costing me money
@MisterSirCode "sometimes" - sure sign you've not seen professional code. It's mostly terrible.
first things first; why is your website blocked
@KarelG because of my shitty firewall on this domain-controlled device
it detects it as "miscellaneous / unknown" so it just assumes its dangerous
does that with basically 60% of all websites
ah, that ... well don't circumvent around
Nothing wrong with visiting my external IP for my site instead
it aint like the school is going to get mad at me for that
ive once run pirated exploit software to gain access to some privaledges on one of their devices...

No one found out, no one cared
and I fixed it afterward
/shrug
12:38
I mean, don't ask for ip based SSL cert ... not worth and is a plaster on a wooden leg
I get SSL for free
using certbot
so why not
my CA does not accept certbot's CA
so there is that.
and TMK each certs you've signed at cerbot are only available for 90 days?
So it shows unsecure for you when you visit mistersircode.com ?
you should fix the root of your problem
@KarelG it autorenews
you can renew em every 10-20 minutes if you wanted
12:43
my corps network does not, no
@KarelG So its working for you? no?
Ive tested it on lots of networks, and Ive even had people visit from places like turkey and isreal, and even russia, and everyone says my site works fine on every device theyve tried, aswell as internationally
I just add an exclusion/exception
it depends of the CA they are using
Honestly karel youre the first and only person to really have an issue with my SSL certs as of yet
if the CA trusts signed certs from certbot (it is Let's Encrypt) then it is ok
and I have a community with around a thousand people from around the world... I actually asked them specifically if it was working for them

Hundreds replied with minor errors... I received nothing about issues with the certificate
12:45
my corp network has its own CA lol
@KarelG yes, I use LetsEncrypt
it is just not a regular company in a country... It is a large company with many branches where each branch has hundreds employees. To increase the security, the global IT has created a custom CA so that they can control the SSL handshakes better
thing with public CA's is that they are usually ... lazy to revise their trusted CA list
at home, my network uses one of the public CA's
it takes a lot papers to even get a custom port open in a VPN service :D
\o confused soul here. I'm building a multi seller ecom site in XEAN Stack. Need to find X. MongoDB or Postgres Json? Every product will have multiple sellers and every sellers will have multiple products. Products have different attributes and (not same attributes for all products).
Uh, I'd personally go with Mongo. Mostly because I expect it has more support. I've not actually used Mongo, though.
PostgreSQL
12:52
I've heard Postgre is also really good.
I mean, I've used it, but not with JSON.
Mongo does not scale well and has performance issues when there is too many concurrency
^ OK, you've convinced me.
@VLAZ they have integrated JSON support two years ago AFAIK
I've heard that, yes. Just the last time I used Postgre was, like, 8 years ago.
I've also heard the JSON thing is blazingly fast.
I've been reading articles and debates for last 5-6 hours. Some say mongo is better for horizontal scaling and for that custom attribute part. Some say performance of postgre is far better.
12:54
it's an incredible update yes
@KarelG Postgres with json or without it?
With.
If you have irregular data, don't try to fit it in a relational-shaped hole.
I mean, you can but it's a bit of a headache.
I still remember that because version 9 not only has introduced json but also column-specific + conditional triggers and on top of that; it supports 64 bit on windows afterwards
that was just "wow"
The data is irregular, especially custom attributes for each product.
If you can generalise the format, though, you can use regular table. You can have, say, 20 fields and some records will use 5, others might use 12. You need to keep the mappings for what field holds what. That's how things worked pre-NoSQL databases.
12:57
@VLAZ all holes can be filled in ( ͡~ ͜ʖ ͡°)
eeh
even if you intend to use mongodb, be cautious with non-regular data
it is expected to have at least a form of structure in json objects you're inserting
that is damn correct
yesterday, I got a bug report about a problem I could not reproduce. And it appears that if you do step a..b..c..a..b..d..e..c..a..b..f you get that. Like "how do you got those steps"
she was also kind enough to provide a video... a three minute one.
I spy lua concatenation
Did the video help, at least?
oh it does. Otherwise I would just drop the pc somewhere and forget that
13:07
Bug report from last week I saw was that if you triple click every single column of the table (sort ascending -> sort descending -> unsort), the data is then jumbled up. And...yeah, it is.
It seems to completely lose the page number after you do that.
It's also hilarious.
On day 2 of setting up webpack
@SagarV PostgreSQL regular. Don't use JSON with it.
especially for an ECON site. It's a pain to deal with eventual consistency with stock of an item.
Next thing you know you've sold 100 more of a hot item then you actually have cough cough walmart, target, gamestop, and every other fucking company
@VLAZ how'd you get a picture of me?
I hacked your screen and inverted the polarity of it. So, it took a picture instead of emitting a picture.
:O
13:29
@JBis How do you recommend storing irregular data, like product attribute? create mapping tables?
By json I mean postgreSQL JSONB,
@SagarV wdym irregular data?
if it's M:M relationship you use a junction table
I don't like "irregular" data
I just make it structured. If it does not fit, I throw it away
IDGAF :D
Product attributes. For example, food products have an expiry date, mfg date, etc. Dresses have color, size, etc. In json, we can store it as array of objects.
@SagarV theres a couple ways of dealing with that
the most correct way is to have an attribute_name table with stuff like "expiry date" "color" "size" and an id. Then have a product_join_attribute table with a foreign key to the product and the id of a attribute_name and then the value.
non-structured data is just a nightmare on long term. Like opening the gates of oblivion, letting the p̵͉̑l̷̯̊ạ̷̓g̸̻̕u̴͈͌e̶̦͌, amassed from ť̶͓̯̒h̵͇͌e̶̱͒ ̷̫͈̙̣̈́s̶̤͆̈́͠͝ǘ̸͙̱̟̌͂͐f̵̫̯̞̽͒f̶̞̠̠͐̄͊̆ĕ̴͓̒͠r̸̛̰͚̒͐ḛ̶̍͌̓d̸̠̄ͅ ̵͓̅́p̷̡͍̆͜͝ḁ̴̢̛͆̎͝ì̶̺̩̫̿n̶̤̉ ̷͕̼̆̂̚͜ of all past t̷̡̙̞̟̲̟͕̉̉̓͋̌ơ̵̞̣̖̹͔̻͓̫̓́̋͗̂̏̌͐r̴̰͇̱͇͔̓̕m̸̨̖̯̮̜̝̭̥̒̉͜͝ȇ̵͇̟̜̣̲͒̂̽̑͊n̶̞̞͔̔̿͐̈́́͠t̴͖̭̯͔̰̹͎̉̈̌͌̃͆͠ȩ̴̫̀̀͊ͅḑ̶̱̤͕̳̯̋̾̒̇͋͒͂̕̚ ̷͚͖̐̍͑̈́̓̚͝ď̷̮̦̠̗̩̬͒̚ę̷͙͙̈́̆͘͠v̷̫̻̈́͌̌́͝e̴̗͚̝̭̔̈́̀̾̉͘͠lopers infect the next developers work on that
.
(that ^ is intended)
13:35
I thought about it but won't it affect performance?
the slightly less correct way is to have a product_join_attribute with the foreign key of product, attribute name, attribute value
@SagarV not for anything you are creating
@JBis Seriously, XML is a good format for that.
@KarelG huh?
with XML you can describe which property an entity can and should have
and it is also recursive (so sub-entity can have same rules as well)
example?
the only people who really need to worry about performance of relational db's is google size companies. Unless you have a very specific use case.
13:41
<xsd:productType name="book">
  <xsd:element name="title" type="xsd:string"/>
  <xsd:element name="author" type="personType"/>
</xsd:productType>

<xsd:productType name="comic">
  <xsd:element name="series" type="xsd:string"/> or different entities ("marvel comics")
  <xsd:element name="title" type="xsd:string"/>
  <xsd:element name="scenarist" type="personType"/>
  <xsd:element name="artist" type="personType"/>
</xsd:productType>
like this one
the parser then converts these in appropriate entity types
(not sure if "series" is correct terminology, feel free to correct me)
if you do not know the data structure, xml can help you to find "a line" in that
bleh
a lot governmental orgs are using that, mind you :)
more evidence you shouldn't
it has its uses.
I, personally stay away from xml.
13:48
the story of using a hammer or a screwdriver on a nail
@KarelG Don't you mean screw
no, nail. You can chop in the nail with your screwdriver. It is a saying that you can use a screwdriver for that, yet it is not appropriate. Using the hammer is.
I feel like I usually hear it as a hammer vs screw, but really either way makes sense
ah. For screw, you can use both
A screw hit with a hammer is better than a nail turned with a screwdriver.
13:56
Lets just all keep a hammer and multiple screwdrivers to avoid this
|| hammer
Invalid command! Did you mean: ballmer, faster, hmmm? Try help for a list of available commands..‍.‍.‍.‍
uhh, I certainly didn't mean Ballmer
|| stop
heh I am curious about that ballmer command
I don't get it
and try that on sandbox next time pls
(like I did)
Steve Balmer has one famous bit where he shouts "DEVELOPERS! DEVELOPERS!"
4 messages moved to Sandbox
@JBis does jamesbot share memory across rooms?
James is all-knowing. All-seeing. He is now and forever.
@KarelG yes
James is unbound from these mortal constructs called "rooms". He exists beyond the universe.
14:05
James is god
God is a James
that explains those user-taught commands
some of these are from users that did not have been here once (or rarely)
14:25
Hi I have a question. What's the difference between "transform" and "plugin-proposal" for babel loader config?
Hello anybody in here who works with jest and node express js?
@SanketRajgarhia Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
@SanketRajgarhia ask your question :)
14:49
@VLAZ Steve Bulmer should have been a football coach from the start, instead of waiting till after he retired. I know he owns the clippers, he doesn't coach them, but that's as close as you can get without actually being courtside/fieldside yelling instructions at the team
I can imagine he would make a good scrum master
Alright. Webpack, typescript, react, electron is all working nicely together
Next up is configuring the api server :D
@starboy "BUGS! BUGS! BUGS! BUGS!"
01:00 - 15:0015:00 - 23:00

« first day (3827 days earlier)      last day (1346 days later) »