« first day (2532 days earlier)      last day (2646 days later) » 

Dom
Dom
00:00
Hi folks, I'm in a bit of a pickle trying to implement a math formula while not knowing what a successful result should look like. Trying to calc distance between two lon/lats using the first formula here , but the results I'm getting are very far from correct. Will share my code if anyone's interested..?
so you have two x/y cords and you wanna calc distance between?
Dom
Dom
yeah, I've used the stack overflow post already but that wasn't giving correct results either
@rlemon I think there is a hierarchy of bad, and just saying minorities, is over-generalizing, it is key demographics like you mentioned.
const dX = x1 - x2;
const dY = y1 - y2;
const distance = Math.sqrt( dX * dX + dY * dY);
Dom
Dom
oh sorry, on the globe lol
00:02
@Dom ^
@rlemon ...no
@Dom What's your code?
i think it's harder because it's on the surface of a sphere
and the grid points aren't equidistant
@KendallFrey listen, I had very little to go on and asked a specific question.
1 message moved to Trash can
@Dom Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
I also didn't click his link. oops
Dom
Dom
00:03
    private calculateDistance(coordinates) {
        let sin = Math.sin, cos = Math.cos;
        let earthRadius = 6371; // Kilometers
        let a = Math.acos(sin(this.sourcePoint.latitude) * sin(coordinates.latitude)) +
                (cos(this.sourcePoint.longitude) * cos(coordinates.longitude) *
                (cos(this.sourcePoint.longitude - coordinates.longitude)));

        return earthRadius * a;
    }`
he did say lon/lat
@david "so you have two x/y cords and you wanna calc distance between?" -> "yeah"
so I took a stab
@Dom your second line of the equation should have latitude, not longitude
Dom
Dom
I have to use the first formula as requested. It's a technical test for a job so not a massive deal
is anyone in freelance atm
Just want advice on building client base
00:05
probably the better place to ask
forgot stack over had a website for every verb
Rule 34b
I'm sure there are some freelancers in here, but on a specific sub-site it might already have good answers and would probably gain more traction
Dom
Dom
@KendallFrey darn it you're right... took me 30 seconds to see it after you said! reading formulas like that is not my strong suit!
@KendallFrey Thanks very much
but im asking about front-end js dev in particular, which is why i asked here
00:08
no you're asking about how to build your client base as a freelancer
the advice should be universal between languages and technologies
33
A: How can experienced contractor survive outside Elance/oDesk/Freelancer?

ScottI have never used any online freelance service to acquire work. Ever. Not even for one project. Without any direct experience as a worker, they all seemed like a less-than-ideal business venture for me to make market-level money. I have hired workers from guru.com and have ultimately never been...

seems like a good start
Dom
Dom
@KendallFrey It's still wildly off the mark though :(
I think you have misplaced ()
my girlfriend does freelance and shes always stressed out
I am sold on typescript
00:10
i like my cushy salary job
@hsimah I like both, you can be a freelancer and have a great salary.
9-5 > freelance imo. there are benefits to freelance. but a stable pay is nice.
Dom
Dom
@KendallFrey yeah missing a pair thanks
9 - 5 On Office > Free Lance > 9 - 5 Remote
not missing a pair, in fact, have some extras in the wrong place
00:12
9 - 5 Remote easily becomes 24/7 labour
granted, I work 8-5
that's not something to contemplate out of context
this whole 9-5 bullshit makes me so mad.
who actually works nine to five?
with lunch that's seven hours. '
Dom
Dom
@KendallFrey haha! I wanted to be explicit by wrapping them more than necessary. I'm now getting pretty similar results to the Haversine function in the SO post I linked above, but those values are still way off what Google says
00:15
@towc looks like shit
tons of bad practices and you might want separate components for some stuff, but hey, it's good enough to add hooks to
no styling or anything
@Dom post your updated code
make a fiddle, preferably
I can work out a nice design tomorrow, and maybe standardize the code
Dom
Dom
private calculateDistance(coordinates) {
        let sin = Math.sin, cos = Math.cos;
        let earthRadius = 6371; // Kilometers
        let a = Math.acos((sin(this.sourcePoint.latitude) * sin(coordinates.latitude)) +
                (cos(this.sourcePoint.latitude) * cos(coordinates.latitude) *
                (cos(this.sourcePoint.longitude - coordinates.longitude))));

        return earthRadius * a;
    }
but right now I really need sleep
00:18
@Dom Looks alright to me
Dom
Dom
example data: distance between "51.515419,-0.141099" and "19.4361004,-99.18870959999998" should be about "8941km" according to Google, but formula is giving about "10856"
I don't know how accurate the formula is meant to be, but it seems to be way off, and the main problem is - I don't know how accurate it's meant to be
@KendallFrey I agree it looks to be right
I'm getting 6311, oddly enough
ohh, i guess it has to be in radians
Dom
Dom
yeah soz, that's left out
 private deg2rad = (deg) : number => {
        return deg * (Math.PI / 180);
    };
after the conversion, I get 8930
Which is probably accurate enough
function calculateDistance(alat, alon, blat, blon) {
    alat *= Math.PI / 180;
    alon *= Math.PI / 180;
    blat *= Math.PI / 180;
    blon *= Math.PI / 180;
    let sin = Math.sin, cos = Math.cos;
    let earthRadius = 6371; // Kilometers
    let a = Math.acos(sin(alat) * sin(blat) + (cos(alat) * cos(blat) * cos(alon - blon)));

    return earthRadius * a;
}
Dom
Dom
@KendallFrey interesting, thanks, if you're getting the right result, I need to look at the input and see if somethings going wrong during parsing
@Tobiq required by the formula
00:34
i meant why not input as rads or have seperate degrees>rad method
Dom
Dom
oh because the data is in degrees as it comes in, the above code from Kendall is just for demo purposes
it does get converted beforehand
Hello everyone, good day
@optimalresource 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.
Can we please help me look at this question of mine
0
Q: How to get the product of numbers gotten from combinations of datasets

optimalresourceI have a combinatoric script that's working fine, actually got most of it from the IBM dev website. But I want to be able to not just show the possible combinations, but also extract the numbers on each combination and get the product of the entire numbers. The project am working on mixes numbers...

Ok
Will check the rules
I think am familiar with most of the rules. Thanks
Have checked it
@optimalresource so you want to extract the numbers and multiply them?
00:45
Exactly
does not sound too hard
Dom
Dom
@KendallFrey When you say after the conversion, do you mean the deg2rad conversion or did you do another conversion with the result? I can't spot the issue at the moment but I will find it, just double checking this
I actually have the program written to do the concatenation of the code and number
And the combination too
I don't know what you mean by combination?
@Dom the deg2rad
00:47
Like permutation, the total number of ways the data can combine, given a maximum range
In the example code i posted, 4 is the range
And the dataset is an array of 6 elements generated via the loop
well generating permutations is not a big deal, we can do that easily. but I'm confused about the end result you want
However, the array is already generated by another function in my main code, and that is where I have it in alphanumeric form, I need to extract the number and get the product, then output the product alongside the combined array
@Rick, is it clearer now?
so ill just extract the numbers, if you have the other part working
like say an array of [boy20,girl5,man6] I need to extract the number from each index and multiply the 3 of them
Yeah, exactly
Dom
Dom
@KendallFrey Thanks, finally spotted the issue - lat/lon was getting swapped around elsewhere face/palm
00:55
!!> ['boy20','girl5','man6'].map(x=>Number(x.match(/\d+/)))
@rlemon "SyntaxError: missing ) after argument list"
@rlemon [["20"],["5"],["6"]]
@rlemon [20,5,6]
!!giphy excellent
@rlemon, how do I use that, can you give a description for me on the question page
I think that's more like what I want
Look at the MDN page on string.match and that RegExp is simple enough
00:59
I'll check it out
01:14
@optimalresource are you expect 20 500 and 30
hold on, ill need to modify my answer
morn
@Rick, how do you mean? The answer you gave was correct, it gives the product of the array. But I said the main array in question contained strings and number and I have to separate them to be able to work on the product of the numbers.
Thanks for your help
Someone posted an answer just now and that is actually doing the trick, I want to apply it for most test cases, be right back
@optimalresource it won't work for digits like 20, 300 but I can fix that
ya give me sec
01:30
@optimalresource it's working ill clean it up when I get a chance.
Ok, thanks a lot
01:50
no worries also added a way for you to generate permutation.
Wow
Lemme check it out
okay, finished my react application. now to deploy it to azure and integrate with AAD.
@Rick, thanks a lot. I appreciate. The code is neat and precise
02:07
!!> ['boy20','girl5','man6'].reduce((x,y) =>Number(y.match(/\d+/))*Number(x.match(/\d+/)))
@SterlingArcher "SyntaxError: missing ) after argument list"
@SterlingArcher "TypeError: x.match is not a function"
wubalubadubdub
02:12
oh great Tobiq is back from suspension and hasn't learned a thing eh
nope
02:33
@Rick, please one last question, am relatively new to core javascript. The getProduct function, I placed it in my document.ready func and I placed the call to the function inside the for loop containing the output arrays and it ain't printing. Can I post the code here?
put in a fiddle
@Sterling, am still studying the string.match mdn, when its clear, I can be able to use ur suggestion so easily. Thanks
@Rick How? you mean jsfiddle.net?
ya jsfiddle
Ok
Will do just that right away
This is the link to the fiddle: jsfiddle.net/optimalresource/4k18hnow
@Rick, will be expecting an update on the fiddle. Let me look into the string.match some more
02:52
@optimalresource I can't spend too much time looking at your code, but there seems to be a lot of mistakes, for example, your initializing var outp = []; inside your forloop. Also, you're not declaring your variables, you forgot to put var in front of array
Ok, will look at those.
I mean you declare an empty and then populate it, you don't need to do both
Ok
I made some of those changes and also took the getProduct function out of the document.ready so it can stand alone. I look at it with the little I know, it seems to be alright, but yet not working
1 sec
03:06
I think you should just replace it with what I gave you
But that does not come with the combination
That's the problem, getting both to work together
if I had more time I would debug it for you. My suggestion is that you clean your code so that others and look at it, and make sense of it.
Alright, I'd arrange it better and add some comments now. Thanks for d suggestion
@VenkatAadithan 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.
03:46
Despite furious googling and a fair amount of fiddling, I can't figure out how to perform a task similar to setInterval(), but where an async function gets run on the interval (because the new async await stuff is awesome). Its also important that the process gets freed when things within the async function are awaited (since they take a seriously long time to run).
Any tips?
1 message moved to Trash can
@GiantCowFilms Please don't post unformatted code - hit Ctrl+K before sending, use up-arrow to edit messages, and see the faq.
@CapricaSix I was just about to fix that in an edit before you vanished my message :P
async function do_stuff() {
	var data = await miserable_slow_external_api_request();
	await save_to_impossibly_slow_database(data);
}
//which I would like to run like:
setInterval(do_stuff,50000);
//but without all the disaster.
03:59
Anybody do JavaScript on Android? I wanna port my shitty 2D arcade games to mobile, but aren't sure what the best framework to use would be...
04:40
@GiantCowFilms you can do a loop
you just need a helper to turn a timeout into a promise
very simply: await new Promise(resolve => setTimeout(resolve, 50000)) will work
if you want it to run every 50000 rather than waiting 50000 you will need to time the previous work and subtract it from the wait
dhS
dhS
05:39
Hi
How do I replace (apple) brackets in javascript
apple
same way you replace normal brackets
dhS
dhS
I am new to javascript
what is your desired input and output?
you want (apple) to turn into apple?
dhS
dhS
(apple) to apple
yes
is there other stuff around? like banana (apple) orange => banana apple orange?
dhS
dhS
05:44
no
Morning, crazoes
dhS
dhS
only one
you can try .replace(/\((.*)\)/, '$1')
or .replace(/(|)/g, '') to just get rid of all brackets everywhere
dhS
dhS
can you explain it
yes, but i don't feel like it right now
it's a regular expression
there's plenty of stuff to read online about it
05:47
@david but where does that async function go?
its an async function, not a promise.
dhS
dhS
It's ok
Thanks a ot
@GiantCowFilms

async function do_stuff_FOREVER() {
  for (;;) {
    var data = await miserable_slow_external_api_request();
    await save_to_impossibly_slow_database(data);
    await new Promise(resolve => setTimeout(resolve, 50000));
  }
}
06:04
@david That works
very clever. Thanks!
06:29
@david a needless for loop there ? ._.
06:42
"baaaaab".match(/a*/) - why does this return "", i.e. why is * not greedy here?
@MartinNyolt you're checking if the given string matches the given regex. Which doesn't
end result: you get ""
Why does it not match? It is just the question "does it contain any numbers of a". If I use + instead of * it works.
And actually it matches, otherwise it would return null. :)
Oh wait, I see now.
Hi
I didn't get this joke.. bash.org/?5300
any explanation?
The absurdity is the joke.
07:00
@MartinNyolt * = 0 or more 😉
@KarelG the point I first didn't get was that there are actually multiple matches: ()b(aaaaa)()b(), and match only returns the first.
you can use the global flag
if you add /g, then you get an array with 4 elements methinks
Oh, nice to know, thanks. But actually I just wanted the longest match. I use + now which is what I want.
07:35
morning
Ace
Ace
how do i remove the elements that are appended on another element?
i hate doing it by the element's id because then i have to use logic and 'for' loops
how do i say 'remove all appended elements from element x'?
use map instead for
and define appended elements
you mean children?
Ace
Ace
document.getElementById('buttonDisplayZone').appendChild(boxHour);
appended child elements
so children
Ace
Ace
so i use 'map' instead of 'for'?
map children from element x --> delete?
07:42
you can just set innerHTML to ""
but I don't know if it's well supported by IE
Ace
Ace
setting innerHTML to "" removes the elements?
or just hides them?
it removes everything inside the element
It permanently hides them.
Ace
Ace
ok
07:44
this says you can use it
of course you can iterate the children and use the parent to remove them
but it's up to you
the innerHTML = "" is faster for sure
Ace
Ace
will use ""
@Neoares it isn't AFAIK
using while(el.firstChild) el.removeChild(el.firstChild) is faster, but requires some writing and reading
uhm .. it depends of the # of child elements...
Ace
Ace
i bet.. it's a small app so performance isnt an issue, thanks tho!
1000 ? innerHTML then yeah. But I still use el.innerHTML = '' for quick cleanage
@KarelG why
07:59
why what ?
so innerHTML is faster for high # of children?
I don't see why it's slower with low # of children
recall that when using .innerHTML, you're adding a piece of string in a document. Then it's being reparsed. That last one takes time.
so you're reparsing the whole document after that call
The result is a large DOM tree, containing node objects
.removeChild only removes the node object from that tree.
how do I set the content-security-policy to accept mailto, tel on <a> tags?
thanks @KarelG senpai
I actually didn't like the innerHTML thing
for some reason
but as I didn't know why, I moved forward xD
the problem is that lots of people people uses it incorrectly.
08:12
oh there's a correct way to use it?
I only use that if I have a HTML string to be added to the document that usually comes from xhr response. eg top 100 rows of x data -> send request -> server generates the HTML string (template engine) and returns it to the client. I then use foo.innerHTML = xhr.responseText
it's much better in fetch where you can check if it's html or not
08:26
Guys, can someone please take a look at this
0
Q: Sitemap lastmod date in Javascript

stormecI need to the date format that is shown in <lastmod></lastmod> tags in sitemap.xml. How can I achieve that? Output like: <lastmod>2016-01-21EEST18:01:18+03:00</lastmod> Where 'EEST' is probably timezone offset. I have seen this question and the answers in php: Google Sitemap Date Format bu...

I need to know the time format for
2016-01-21EEST18:01:18+03:00
YYYY-MM-DAYUTCOFFSET..
Thanks :)
how do I set the content-security-policy to accept mailto, tel on <a> tags?
what's the best way with an npm script to run a server, wait for it to load, and then run something else?
08:42
what's the best way to get rid of jQuery
🔥
how do you know the emojii code
I mean do you use a webpage that shows you the code or something?
I need to know your secret
lol
and you load that with greasemonkey or something?
No, it's in the extension
08:45
oh it's an extension
it's only for chrome?
and what if I'm not a pleb
!!s/not//
@BenFortune and what if I'm a pleb (source)
she deleted an extra space :O
08:51
she did not
she did...
"I'm not a" if you remove "not" you get "I'm a pleb"
fuck
chat magic
the browser does that
really?
yeah, that's how whitespace gets handled
oh it's true
08:54
whitespace gets squashed, which makes sense, given how html looks like
that's why there's the <pre> tag or &nbsp;
Guys, anyone?
0
Q: Sitemap lastmod date in Javascript

stormecI need to the date format that is shown in <lastmod></lastmod> tags in sitemap.xml. How can I achieve that? Output like: <lastmod>2016-01-21EEST18:01:18+03:00</lastmod> Where 'EEST' is probably timezone offset. I have seen this question and the answers in php: Google Sitemap Date Format bu...


« first day (2532 days earlier)      last day (2646 days later) »