« first day (2076 days earlier)      last day (3097 days later) » 

15:00
What ever happened to @RocketHazmat or @MattMcDonald? Those were the good old days
is there a formalized name for the process of merging two arrays of objects by id (map -> find -> extend in lodash)?
@NathanJones zip
@NathanJones Merging?
array_combine (in PHP)?
@NathanJones something like a database join?
are you merging the arrays or the objects within them?
15:02
@ssube objects within them
// here's what i'm doing right now, probably terrible.
/* _ is lodash */
var a1 = [{ id : 1, name : "test"}, { id : 2, name : "test2"}];
var a2 = [{ id : 1, count : "1"}, {id : 2, count : "2"}];
var a3 = [{ id : 1, type : "string"}, {id : 3, type : "string"}];

function mergeById(object, array) {
  try {
    var matchingArrayObject = _.find(array, {id: object.id});
    if (!matchingArrayObject) {
      throw 'no match found for id: ' + object.id
    }
    return _.extend(object, matchingArrayObject)
(see full text)
It's close to grouping by id
@NathanJones Consider using _.groupBy for each and group by the id, it might make it easier
Then merging all of the arrays down to single objects
Then I dont think you need the map @NathanJones
@Neal will that be useful if id is unique?
15:05
@NathanJones very slightly
it saves you the find
@NathanJones Yes. because then you would have each grouped by id. then you just need one loop of ids to merge them all
@ssube oh, then i can just do an object key lookup by id instead?
@NathanJones Yea, but in your case you are doing the lookup for each array multiple times
costs time.
@NathanJones if you have to objects (the output of groupby), then you can just do Object.assign({}, a2[id], a3[id]) and make a mashed up copy all at once
@ssube ^ that @NathanJones
15:07
you could also group, then combine the grouped objects, then merge every item in the array
Or if you do not have Object.assign you can use _.extend
which is... weird, but clever, so maybe good but probably unnecessary
@Neal nice lodash bro, but this is 2016
var a1 = [{ id : 1, name : "test"}, { id : 2, name : "test2"}];
var a2 = [{ id : 1, count : "1"}, {id : 2, count : "2"}];
var a3 = [{ id : 1, type : "string"}, {id : 3, type : "string"}];

const groups = {};
[a1, a2, a3].reduce((p, c) => p.concat(c), []).forEach(it => {
  const group = groups[it.id] || [];
  group.push(it);
  groups[it.id] = group;
});

const results = Object.keys(groups).map(key => {
  const group = groups[key];
  return Object.assign.apply(null, [{}].concat(group));
});

console.log(results);
(see full text)
that's way overly clever
@ssube too fancy for me.
I am stuck on old systems. lodash/underscore is the way to go.
the ugly old lodash version is roughly flatten -> groupBy -> fuck knows -> map { extend }, maybe?
it will be a million times more ugly, whatever it ends up being
can I do array["4"] in all browsers?
or I should convert the number to an integer
15:15
@Neoares what part of that are you worried about?
compatibility
@Neoares if you know you need a number, you should always do the conversion explicitly
implicit conversion won't error out if it's not really a number
so like "4a7" will magically turn into just 4
I'll have always a number as string
although in that case it will actually look at array['4a7'] which is equally bad
15:16
@ssube Wait if you're already using a reduce, why then a foreach where you fill an object that's defined outside of it?
it should just be 2 reduces
but I'll have always a number as string :P
@ssube "4a7" will look for property 4a7 in the array and return undefined I think no?
that's why I was wondering about compatibility
@StephanMuller good point
15:16
@MadaraUchiha Sir?
I'm thinking of starting playing some Screeps seriously
Screeps? What is that?
@Neal Google it
So I figured, why not make it interesting
@MadaraUchiha Whoa. this is soo cool!
Will anyone from this room be interested in a collaborative, open source screeps AI project, made by Room 17?
17
15:18
inb4 free premium invites
@MadaraUchiha sure.
@littlepootis Almost
//this is pretty clever @ssube. i had to stare at this for a bit.
const groups = {};
[a1, a2, a3].reduce((p, c) => p.concat(c), []).forEach(it => {
  const group = groups[it.id] || [];
  group.push(it);
  groups[it.id] = group;
});
@MadaraUchiha Hmm how much is it? (i have never used "Steam" before)
15:19
@StephanMuller @NathanJones try jsfiddle.net/k677cmfa
@Neal If you buy it on steam for $15, you get lifetime basic subscription
@MadaraUchiha Sounds interesting, I'd have to buy it after the first.
@ssube oh, it works. i just started playing around with it in ScratchJS.
@MadaraUchiha What does the "CPU subscription" mean?
@MadaraUchiha I'd send in a PR or two
15:20
@Neal It's a server-persistent MMO that runs real JS on Node 6.2.1 for all players each tick
CPU is expensive, so they're charging money
@NathanJones
_.map(_.groupBy(_.concat(a1, a2, a3), 'id'), x => _.reduce(x, _.merge))
So what does "basic" get you instead?
(They're releasing the server source in a few months, so you can open your own server and play for free)
Guys, just a quick question, I am not sure. Can I apply onevent property for document?
@Neal You're limited by how much ms you consume
15:21
@MadaraUchiha Room 17? Are they related to Team 17?
user1596138
@SterlingArcher lol
user1596138
The basic subscription gives you 10ms/tick
@MadaraUchiha if they do that, we could just run a server
plenty of us have spare hardware
I could spin one up on the million CPUs we don't use at work
@ssube Yes, but then you'd have to get people to play it (it's fun because it's MMO)
Which is also fine
Also, there's nothing stopping us from taking the same code and deploying it to multiple servers
15:22
@MadaraUchiha Interesting.
thinking a sandbox before we go live
@ssube There's the public test realm
Which is a weekly dump of the database
oh, never mind then, carry on
Screep looks fun. I'm in
So here's what we do
15:23
I think we should make a GH repo with our routine and set Travis up to deploy master to the screeps server
then do PRs like any other project
@ssube No, we deploy to the public test realm
Only stable should go to prod
(We can also develop on a dev branch and merge to master to push to the dev server)
A big plus is that they have an API for posting code
do we consider master stable or do we have test/master or dev/master or something?
So we can deploy automatically
@MadaraUchiha that's how I tell people to use git
@ssube I think master/stable is better
15:24
:'(
Because it's most intuitive to PR against mater
ok, then we just set Travis up to deploy master to their sandbox and stable to prod
Oh wait, you can tell GH which branch is the default
easy enough
Yeah
They have an API endpoint for posting code
So we can completely automate that part
15:25
Has anyone here fought the whole "No 'Access-Control-Allow-Origin' header is present on the requested resource" issue when making a $Http.get call to php? I have header("Access-Control-Allow-Origin: *"); in my php script, I'm so frustrated
@Tiago Welcome to the JavaScript chat! Please review the room rules. Please don't ask if you can ask or if anyone's around; just ask your question, and if anyone's free and interested they'll help.
@MadaraUchiha how do they manage credentials/API keys?
@ssube Basic auth
You send your email/password pair on each request
ok, we can encrypt that in the repo and send it to travis
0
Q: Encryption & Encoding(AES, UTF-8 and base64)code conversion from JAVA to node.js giving different results

Gandalf the WhiteJava Code public String encrypt(String key,String inputString) { try { SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(1, secretKeySpec); byte[] aBytes = cipher.doFinal(inputString.getByt...

Please.
15:27
we'd use ES6 and then bundle it, maybe?
@ssube That's what I do
I don't use babel because they run Node 6.2.1 which has 95% ES6 support
Stuck at this since yesterday. Github repo and stackoverflow, tried all given examples.
But I do use webpack because the module system there is counterintuitive
The result is not the same.
screep you
15:29
@GandalftheWhite Have you tried reading the documentation and comparing outputs step-by-step?
@ssube How will travis decrypt it?
@MadaraUchiha they have a gem that does that
you essentially encrypt the values in a config file with their public key
@ssube Really? Link to docs?
it's what you use to hide deploy keys even though you need them in a public repo
it's just normal key crypto, so only Travis (for your specific project) can decrypt it
@OliverSalzburg, Crypto Yes, Java one - No.
15:31
@ssube That's neat, TIL
it will let us keep the credentials in the repo without having to worry
@ssube what if i wanted to give priority to a1's groups so throw an error if the a2 or a3 don't have any id matches?
@NathanJones don't reduce. Group by, separately, then tweak the merge.
@GandalftheWhite Your code already contains way too much crap. If you want to make sure you're getting the same output in 2 languages, concentrate on what matters. Don't convert to Base64 needlessly and don't have any try{}catch(e){/*nothing*/} in your code
Oh... you did not see the paste bins. Wait. pastebin.com/JjWEDeR7 pastebin.com/ap4Dk1ti
That try catch was done by ndugger, just for lulz
15:35
@GandalftheWhite Even worse if the real information isn't in the question
And it wouldn't hurt to include your input, key and output so that people can compare
The way you're posing the question would require people to compile and run the Java part to be able to compare with the JS part
In fact the node.js is different but the base64 one looks identical nevertheless.
so the binary is identical but the... string? is different?
This don't work. Gives Error TypeError: undefined is not a function on the cipher.final part.
Works fine for me btw
who's good with mongodb?
and nodejs
Both of them?
@user125535 it's not "who is good with mongo," it's "is mongo ever good?"
and the answer is no, use postgres
15:39
why's that?
because mongo is an inefficient, inconsistent, absurdly slow joke?
@ssube is there a way to get the head / tail of an array? i could create the groups with a1 (head), then perform the grouping on the tail without adding groups that aren't in the head
@NathanJones a[0], a[a.length - 1]
I'm not sure that makes sense, though
const [head, ...tail] = arr;
15:53
var a1 = [{ id : 1, name : "test"}, { id : 2, name : "test2"}];
var a2 = [{ id : 1, count : "1"}, {id : 2, count : "2"}];
var a3 = [{ id : 1, type : "string"}, {id : 3, type : "string"}];

const groups = {};

a1.forEach(it => {
  const group = groups[it.id] || [];
  group.push(it);
  groups[it.id] = group;
});

[a2, a3].reduce((p, c) => p.concat(c), []).forEach(it => {
  try {
    const group = groups[it.id];
    if (!group) {
      throw 'group not found for id: ' + it.id;
    }
    group.push(it);
(see full text)
Ugh. 99 problems and retaining scroll position in my SPA is one.
why doesn't this regex replcace work :$ jsfiddle.net/d5bkfkro/1
if it doesn't work, it's because it's wrong
@ndugger wow! your the best thanks man
16:00
I'm here to help
@ndugger what would this chatroom do without you jeezzzz
Because you are looking for strings starting with < but your test string does not?
4427
A: RegEx match open tags except XHTML self-contained tags

bobinceYou can't parse [X]HTML with regex. Because HTML can't be parsed by regex. Regex is not a tool that can be used to correctly parse HTML. As I have answered in HTML-and-regex questions here so many times before, the use of regex will not allow you to consume HTML. Regular expressions are a tool th...

user2620028
Have much less depressing sad interactions with the opposite sex to talk about.
@MadaraUchiha why should i use Map instead of array?
16:01
@NathanJones Because in this case, the group key is a number
@HatterisMad brutal
But in other cases, it might be a string, or even an object
user2620028
@ssube Ehh after like the 20th time he jokes about it himself, i am aloud a stab or two right?
@Luggage lawlzzz thanks
Also, a Map is iteratable with for..of (with the help of map.entries())
Which an object is not.
16:02
@Raja so @ndugger was right. :)
Only Hitler uses a sparse array when Map makes sense.
@ndugger don't tell him tho
hitler used jQuery.
@Luggage no, his armies moved quickly and smoothly. He was obviously not using jQuery.
Ah. PHP.
16:04
@Luggage Clearly he was using ColdFusion!
<cfoven>
I think the Third Reich ran on Groovy
user2620028
@luggage it definitely wasn't php because he managed to get stuff done on the front lines
@HatterisMad Definitely PHP then.
Hitler created php
16:07
Hitler's demise suggests he was using PHP
Greetings. Is anyone aware of a build tool in JS similar to GNU Make?
I'm not sure how 'similar to make' they are but gulp, grunt, probably others
@mpen You can use make..
Also true.
16:13
you can just use make, it's not very pretty though
Is there really ever a reason to do if (!!someCondition)? Won't it be converted to a boolean implicitly?
though for non-bundled code.. just transpiling, make should be quite easy to set up
gulp is good if you have a long process with a bunch of different tools to run
@Loktar I got a pic of our backyard in 360 degrees for you
@littlepootis I am using Make...there's just a few things that are tricky to do because it's not a full language
16:15
Like?
@mpen if your build is too complex for make, you might have a problem, but gulp can probably handle it
@mpen There used to be jake
But I dunno if it's active anymore.
Well, I've got junk like this in there
if you want to indent a block, it must be a separate message and indented 4 spaces (CTRL-K will do that). No ```
npm-install:
ifndef SHRINKWRAP_BIN
	$(error `npm-shrinkwrap` not found. Please run `sudo npm install -g npm-shrinkwrap`)
endif
	$(NPM_BIN) install --no-shrinkwrap --loglevel=error --no-optional
	$(NPM_BIN) prune --no-shrinkwrap --loglevel=error
	$(NPM_BIN) dedupe --no-shrinkwrap --loglevel=error
	npm-shrinkwrap --dev
	touch $(NPM_TIMESTAMP)
16:17
Disco.
sup dudes
those repeated npm scripts would be a good fit for gulp
That's not too bad, but it just gets complicated.
then you wouldn't have to call npm a million times
SERVER = $(shell php -r "echo json_decode(file_get_contents('.config.json'))->server;")
Couldn't figure out how to parse JSON in Make so I deferred to PHP
Just a lot of gross stuff like that
16:19
@MadaraUchiha @ssube here's what i have now: jsfiddle.net/fbaxaLxc
stedolan.github.io/jq is a nice commandline json parser / transformer.
node < "require('./config.json').server" :|
imgur.com/Z8TnSL3 Put this in 360 Photos in VR Desktop.
also what Ssube, said.
Yeah...in node it would be easy
16:19
jq is a great tool, though
the lighting is wonky from the clouds
jq might be nice but I want to stick to tools that I know are installed on everyone's machine :)
yea, then just node.
er.. i assume.
if you have npm, you have node
Yeah..node and PHP are fine
16:21
command line PHP is pretty rare, though (luckily)
The project I work on has a 50-line bash script which is my... build tool.
Anyway, I've tried Gulp before, but you need a dozen addons to get caching and concurrent builds to work nicely
@littlepootis any script is better than no script
@mpen that's intentional. Gulp is just the task runner.
Then maybe it isn't a task runner that I want
is there still no good tool for generating documentation for es6/es7 code?
16:22
make is the same way
@corvid //
it has very little built in, intentionally
I've used make, and gulp. You don't want to use make for anything complex...
@MadaraUchiha is map() usable on Map.entries()?
16:23
@NathanJones if only there was some way to know
For example, my build process is something like:
- install npm and composer packages
- webpack all assets
- precompile twig templates
- write mercurial stats file
- extract icomoon fonts
- upload to development server
a lot of that can run in parallel, but some of it is conditional. the conditions are tricky in Make
@Luggage haha, i looked at that, was hoping there was some trick i didn't see there
i'll stick to for..of
@NathanJones if not, you can always just map the .keys().
myMap.keys().map(key => foo(myMap[key]));
@mpen make is also much slower when you chain transformations, because you have to write files. It also lacks an efficient watch solution
@DenysSéguret But I'm not chaining transformations, Webpack takes care of that part
I'm using Make to handle all the parts Webpack can't do or isn't very good at.
16:26
and you're thinking about using both webpack and a make tool ? Then why webpack ?
Go checkout gulp.
jq is only 230 kb, you could wget it
webpack does special things make will never do.
gulp and a module that helps you shell out ought to do it
Right...which is why I'm using both right now. They both have their place
16:27
although I'd just set up a CI manifest and run that
gitlab or travis, whatever
And is your software fast built when a file changed ? I gave up make because it wasn't fast enough for this case
I just shell out with child-process.spawn or .exec
or something
@DenysSéguret I don't re-run make when a file changes...webpack dev server takes care of that. Make just makes sure everything is installed, extracted and ready to go before kicking off the file watcher
@mpen gulp and webpack can both do that
so can literally any other kind of script ever made
@Luggage .keys() returns a MapIterator, not an array so i'm getting this error: .keys(...).map is not a function jsfiddle.net/fbaxaLxc
16:30
@NathanJones yea, my mistake.
@ssube The problem I have with gulp is that it's main feature, the piping, has nothing to offer me when I use webpack. I'd be using it for its task-running capabilities. But what I really what is dependency management; I want it to be clever about which tasks need to be re-run if files are missing or are out of date. And I want them to run concurrently
it's piping will come in handy at some point, and it doesn't get in the way other times
a gulp task can simply return a promise or nothing at all. it just runs code
But everything say sounds like exactly the things people use gulp for.
Is gulp 4 out yet?
with whatever extensions needed.
@VeronicaDeane don't like to me
16:32
problem isn't usually concurrency, because you compile everything from a changed file and you chain transformations. Streaming is most useful in my opinion, unless the project is trivial (this isn't true, of course, if one of your task is a black box doing everything, like webpack)
you should at least knock and come in
today, on my way to home, there was a cyclist. He was not paying enough attention because he hit the traffic sign with his head, which caused his fall. I found it funny :|
@Loktar Error: could not parse
wtf sorry
I am so busy everyday lately so annoying
@Luggage How do you specify in Gulp that a task doesn't need to run because the source files haven't changed?
16:34
I don't even get a chance to play muh games!
the rift nor vive are even hooked up yet
been having VR with drawls
the real world hurts too much!
sort your priorities out man
haha I need to
@mpen I use gulp-changed for that. I think gulp4 will have that built in
16:35
don't you get balance issues when using VR ?
no surprisingly
the ones that fully track you get rid of that
some people starts to puke automatically or faints after 2 hours playing
some vids you see (that are the DK1) didnt have positional tracking, so that happened often
motion sickness is the name
yeah, I havent gotten it with the vive at all
but with the rift a tad
16:36
Actually I had some weird out-of-balance moments when I was standing in VR
not even walking
@mpen my rather simple gulpfile. It just builds (changed only) and restarts a development express erver: gist.github.com/luggage66/0040e25d0afc87a09205c0c063730097
I use webpack separately.. webpack --watch
@Loktar Hurry up, I wanna try and 2v1 @Cereal again and get our asses kicked.
haha
@VeronicaDeane your brain combines the input from your vestibular system and your eyes. If they don't match, you get such balance issues or motion sickness
Wait, did Cereal change his name again?
16:39
time to change locations..
be back in a few
:31291720 I think what I'd want to write would be more like

gulp.task('build', ['install-deps', 'webpack','twig','hg'], () => {
    ...
})

gulp.task('webpack', [], () => {
    if(any_source_files_have_changed) {
         spawn('webpack-dev-server')
    }
});
which I guess doesn't look too awful. But almost all of my tasks would have an if() like that at the top of the task
whereas with Make that's a core feature
!!afk welp there we have it, internet has spoken
16:41
changed works with pipes
I dont have anything to pipe
you pipe them to webpack
pipe it up
@ssube Not sure about that. My entry files are specified in webpack.config.js. Webpack resolves the rest of them by traversing the require() tree...I shouldn't be resolving them myself in Gulp...?
Hi Guys,
how to close the child window only on closing parent window
If I use window.onbeforeunload then it is closing on even page refresh
Please guide me
16:48
not sure there's anything you can do about that
refreshing the window is essentially the same as closing the page
you could have the child poll the parent to see if it's still active (or the parent notify the child every so many ms) and have the child close itself if it doesn't hear from the parent after 5s
okay thanks
aww, he starred that
@MadaraUchiha when it comes to the screeps thing, what were you thinking for paying?
2 pence

« first day (2076 days earlier)      last day (3097 days later) »